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.