Validate a parameter value that is present in a list

Hey @honeycle22

Welcome to the community! :trophy:

You could use something quite hardcoded like this:

pm.test("Verifying refusal code", function () {
    let jsonData = pm.response.json();
    pm.expect(jsonData.deleates[0].refusal.code).to.eql("1306");
    pm.expect(jsonData.deleates[1].refusal.code).to.eql("502");
}); 

Your test is looping through the right part of the response but itโ€™s asserting against a single string "1506" which is fine if itโ€™s thatโ€™s either the only code for that property or you only have a single object for that array but as neither of those is the case, youโ€™re seeing it fail on the "502" value.

If you have a known set of codes, you could do it like this:

pm.test("Verifying refusal code", function () {
    var jsonData = pm.response.json();
    for (var i = 0; i < jsonData.deleates.length; i++) {
        pm.expect(jsonData.deleates[i].refusal.code).to.be.oneOf(["1306", "502"]);
    }
});
1 Like