I want to get all availability keys from response body under ‘Suites’ array, and need iterate the next requests as per count of the keys.
Response body -
{
"planDescription": "",
"errorCode": "",
"isQualifyIdRequired": false,
"offerType": "BBAR",
"suites": [
{
"availabilityKey": "XXXX1234",
"flexPackageCode": null,
"rateCode": "BBAR",
"minimumStay": 1,
"availableRoomCount": 122,
"nightlyRate": 1099.96,
"suiteCode": "asda",
"totalRate": 1099.96,
"avgNightlyRate": 274.99,
"sortOrder": 0,
"flags": [],
"startDate": "0001-01-01T00:00:00",
"endDate": "0001-01-01T00:00:00"
},
{
"availabilityKey": "XXXX12345",
"flexPackageCode": null,
"rateCode": "BBAR",
"minimumStay": 1,
"availableRoomCount": 22,
"nightlyRate": 1099.96,
"suiteCode": "KBSB",
"totalRate": 1099.96,
"avgNightlyRate": 274.99,
"sortOrder": 1,
"flags": [],
"startDate": "0001-01-01T00:00:00",
"endDate": "0001-01-01T00:00:00"
}
]
}
I have tried below snippet but not getting each separate value. Can anyone please help? Thanks in advance!
pm.test("Each suite in the response body has an availability key", function () {
pm.response.json().suites.availabilityKey.forEach(function(suite) {
pm.expect(suite).to.have.property('availabilityKey');
pm.environment.set("AvailabilityKeys", availabilityKey);
});
});