Hi,
I’m a real newbie and have already spent far too long reading many answers on where to try to get something that works, but I’m struggling. I want to compare two responses for a version 1 versus a version 2 endpoint (the data returned should be almost identical).
I’ve managed to crack the order of arrays with a sort before comparing, but I know that there is one attribute in the response that will differ between the two versions. This attribute is in an object within an array in two different objects in the response.
For example (snipped):
{
"policyNumber": 1,
"policyholder": {
"contactDetails": {
"address1": "line 1",
"address2": "",
"address3": "",
"city": "",
"county": "",
"postcode": "",
"emailAddress": "",
"telephoneNumber": ""
},
"bankDetails": [
{
"accountName": "xxx",
"sortCode": "999999",
"accountNumber": "12345678",
"mandateReference": "xxx",
"billingDay": 1,
"firstCollectionDate": null,
"bankName": "",
"effectiveFrom": "2023-06-24T00:00:00Z",
"createdOn": "2023-06-24T23:58:41Z"
},
{
"accountName": "xxx",
"sortCode": "999998",
"accountNumber": "12345679",
"mandateReference": "xxx",
"billingDay": 1,
"firstCollectionDate": "2025-07-10T00:00:00Z",
"bankName": "",
"effectiveFrom": "2023-06-24T00:00:00Z",
"createdOn": "2023-06-24T23:58:41Z"
}
],
In the first response I am expecting bankName to be empty; in the second I am expecting it to be populated. As I am testing 1000s of responses I want to be able to ignore the bankName from the comparison.
Here’s how I am comparing:
pm.collectionVariables.set("response2", JSON.stringify(pm.response.json()));
const firstResponse = pm.collectionVariables.get("response1");
const secondResponse = pm.collectionVariables.get("response2");
// might need to remove all instances of bankName from both responses as I'm now passing the bankName in the stored procedure
const _ = require('lodash');
const r1 = _.sortBy(firstResponse);
const r2 = _.sortBy(secondResponse);
pm.test("V1 response should be equal to V2 response", function () {
pm.expect(r1).to.deep.equal(r2);
});
My test runs 1, followed by 2.
Please be gentle with me