This test pm.expect(jsonData.payload.invitationStatus == "A");
works regardless of the value that invitationStatus
actually contains.
i.e. payload.invitationStatus = E
will pass in the test.
How do I get this to pass only if the value is A?
Here are a couple of examples of the payload:
{
"payload": {
"buyer": "",
"error": "E",
"invitationStatus": "E",
"supplier": "",
"terms": ""
}
}
{
"payload": {
"buyer": "omitted omitted",
"error": "S",
"invitationStatus": "A",
"supplier": "ABC Supplier",
"terms": ""
}
}
Here's the test itself:
// Setters
let jsonData = JSON.parse(responseBody);
// Testers
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Invitation status is A", function () {
if(jsonData.payload) {
pm.expect(jsonData.payload.invitationStatus == "A");
} else {
throw new Error("Unexpected structure");
}
});
I'm not sure why the ==
didn't work but this worked pm.expect(jsonData.payload.invitationStatus).to.eql("A");
Here's a good resource for other postman tests examples https://www.getpostman.com/docs/v6/postman/scripts/test_examples