Validation

Scripts

PruTAN lets you to add dynamic behaviour to ISO requests. This allows you to write test suites and build requests that can contain dynamic parameters. You can add JavaScript code that executes at two events in the flow:

  • Validation are executed after a response is received from the server
  • You can add multiple validation to a request
  • You can add validation to both requests saved and not saved in a collection

PruTAN will then execute the scripts after the response is received.

Post-request validation

As you introduce new code, validation ensure that your API is working as intended. The higher your test coverage, the more flexible and bug-resistant your code will be.

Writing post-request validation

PruTAN ships a powerful API called xv which can handle post-request scripts as well as validation. Here we'll use xv to run validation on the response recieved from APIs.

Examples

Let us look at some examples of how you can use PruTAN to write validation.

Test response status code and Field id = 3 value

Let us write a test to check whether the response to our request has a status code of 200. Which means that there are no errors in the response body. We'll use the below URL with the GET method.

In this case we'll need to write two expect statements one for checking the status and another for checking the response body. However we can wrap expect statements with the test method from the xv API to group related statements.

  • We will use same request UPI > Transaction for validation scripts.

There are two ways to test the status code:

ConditionCode
Check if response code is 200xv.expect(xv.response.status)toBe(200)
In-built matcher functionxv.expect(xv.response.status).toBeLevel2xx()
// Check ISO request & response property
xv.test("Check response Field id=3 value", ()=> {   
    xv.expect(xv.iso.response.get(3)).toBe("310000");
});

// Check status code is 2xx
xv.test("Status code is 2xx", ()=> {
    xv.expect(xv.response.statusCode).toBeLevel2xx();
});

  • To know more about validation scripts please checkout our sample scripts provided by PruTAN in right side of the Validation Tab.

The validation will have passed once you click on the "Send" button.