I have an API endpoint that I am testing that returns an array of values in the JSON response, for example:
[
{
âidâ: â272ea3e0-9496-4153-99ba-30a4c87f30bbâ,
âdescriptionâ: âCORRESPâ,
âallowCourtesyCopyâ: true
},
{
âidâ: â423b0102-3dc8-4e91-b0b6-efcc52a478d7â,
âdescriptionâ: âCOVERâ,
âallowCourtesyCopyâ: true
},
{
âidâ: â87ccf4ce-6b79-4f4a-8cab-b50d81cc82b2â,
âdescriptionâ: âEX-1â,
âallowCourtesyCopyâ: true
}
]
I am using a CSV file containing the id & the expected response to call with the endpoint & validate the actual response, for example:
id,expected_response
1234,"[ { ââidââ: ââ272ea3e0-9496-4153-99ba-30a4c87f30bbââ, ââdescriptionââ: ââCORRESPââ, ââallowCourtesyCopyââ: true }, { ââidââ: "â423b0102-3dc8-4e91-b0b6-efcc52a478d7"â, ââdescriptionââ: ââCOVERââ, ââallowCourtesyCopyââ: true }, { ââidââ: "â87ccf4ce-6b79-4f4a-8cab-b50d81cc82b2"â, ââdescriptionââ: ââEX-1"â, ââallowCourtesyCopyââ: true } ]â
For the endpoint I have this as my test:
let jsonData = pm.response.json();
pm.test(âResponse has expected valuesâ, () => {
// get expected response from data file
expected_response = pm.iterationData.get(âexpected_responseâ);
// convert to json
expected_response = JSON.parse(expected_response);
// compare expected response to actual
pm.expect(jsonData).to.include(expected_response);
});
However when I run the test I get the following error:
Response has expected values | AssertionError: expected [ Array(32) ] to include [ { id: â272ea3e0-9496-4153-99ba-30a4c87f30bbâ, description: âCORRESPâ, allowCourtesyCopy: true }, { id: â423b0102-3dc8-4e91-b0b6-efcc52a478d7â, description: âCOVERâ, allowCourtesyCopy: true }, { id: â87ccf4ce-6b79-4f4a-8cab-b50d81cc82b2â, description: âEX-1â, allowCourtesyCopy: true } ]
I canât figure out why Postman is saying the actual response doesnât match the expected response from the file. I have another data test that use a CSV that works, the only difference is that the expected response in that file is a dictionary like this:
{
âkeyâ: âvalueâ,
âkeyâ: âvalueâ,
âkeyâ: âvalueâ
}
Any help would be most appreciated. Thanks in advance.