CSV comparison to a responseBody

Ok, this will be better structured as JSON.

The following is an example of an array with two objects. Each line of your CSV will be a separate object and you would include all of the relevant fields you want to check. Iโ€™ve only included three fields for testing purposes, but these would match your CSV headers.

[
    {
        "ID": 121,
        "address-city": "LAS",
        "workCenterCode": "DAY"
    },
    {
        "ID": 100,
        "address-city": "AU",
        "workCenterCode": "DAY"
    }
]

I would then recommend iterating over the JSON, and then searching the response based on the primary key which for this example, Iโ€™m using the ID.

This would return the object in your response for that primary key, which you can then target and assert the other fields.

// Step 1 - parse response
const response = pm.response.json();

// Step 2 - define data file. 
let testData = JSON.parse(pm.collectionVariables.get("testData"));
// You would change this to read from the data file.  
// You can access the iteration data from the special "data" variable
// let testData = data

// Step 3 - Iterate over the test data\input file
testData.forEach(element => {

    // Step 4 - Test each record in the input file
    // Using string literals to create a custom test case name
    // So its easier to know which record failed
    pm.test(`response keys match for ID ${element.ID}`, function () {

        // Step 5
        // Search the response using the ID from the testData
        let search = (response.find(obj => { return obj.id === element.ID }));

        // Step 6
        // You don't need to test the ID is correct
        // You can just check that the search is not undefined
        pm.expect(search).to.not.be.undefined;
        // console.log(search);

        // Step 7
        // You can now assert on the other fields
        // Example using bracket notation, just in case of special characters
        pm.expect(search.address.city).to.eql(element["address-city"]);
        // Example using dot notation
        pm.expect(search.workCenterCode).to.eql(element.workCenterCode);
    });
})

And the results are inโ€ฆ

image