Получение параметров полей из JSON в POSTMAN Cannot read property 'offer' of undefined
Всем привет! Недавно начала изучать автотесты в Postman, имеется следующая задача: нужно найти значение параметра offerType и узнать равно ли оно 7 или нет.
Пишу следующий тест:
pm.test("Checking offer blocks", function () {
var jsonData= pm.response.json();
var list = jsonData.length;
console.log(jsonData.productOffers.length);
jsonData.productOffers.forEach(shortProduct => {
pm.expect(jsonData.productOffers.shortProduct.offer.offerType).to.eql(7)
})});
Получаю следующий ответ: TypeError: Cannot read property 'offer' of undefined
Ниже прикладываю JSON
{
"productOffers": [
{
"shortProduct": {
"id": "000000000000000121_KG",
"name": "Слива черная/красная, 1 кг",
"eanMain": null,
"department": null,
"offer": {
"offerType": 7,
"dateEnd": "2020-10-28T00:00:00+03:00",
"percent": null,
"description": null,
"badgeText": "x10"
},
"badges": null,
"isAdult": false,
"priceParams": {
"tariffingPrice": 149.99,
"regularPrice": 0.0,
"endDate": "9999-12-31T00:00:00+03:00",
"orderPrice": 149.99,
"sellType": "weight",
"tariffingVolume": 1,
"tariffingUom": "г",
"orderMinVolume": 0.5,
"orderStep": 0.5,
"orderUom": "г"
}
},
"actionId": "800000103",
"promoId": "14_6BD2F3205BCFB84B170076007FBCEFA3",
"status": "E0003"
},
{
"shortProduct": {
"id": "000000000000000123_KG",
"name": "Черешня, 1 кг",
"eanMain": "2000000000237",
"department": null,
"offer": {
"offerType": 6,
"dateEnd": "2020-10-26T00:00:00+03:00",
"percent": 98.0,
"description": null,
"badgeText": "-98%"
},
"badges": null,
"isAdult": false,
"priceParams": {
"tariffingPrice": 19.00,
"regularPrice": 1699.99,
"endDate": "2020-10-26T00:00:00+03:00",
"orderPrice": 19.00,
"sellType": "weight",
"tariffingVolume": 1,
"tariffingUom": "кг",
"orderMinVolume": 0.5,
"orderStep": 0.5,
"orderUom": "кг"
}
},
"actionId": "900000103",
"promoId": "14_62D2F3205BCFB84B170076007FBCEFA3",
"status": "E0003"
},
{
"shortProduct": {
"id": "000000000000000126_KG",
"name": "Виноград Биколор фасованный, 1 кг",
"eanMain": null,
"department": null,
"offer": {
"offerType": 6,
"dateEnd": "2020-10-30T00:00:00+03:00",
"percent": 98.0,
"description": null,
"badgeText": "-98%"
},
"badges": null,
"isAdult": false,
"priceParams": {
"tariffingPrice": 2.50,
"regularPrice": 199.99,
"endDate": "2020-10-30T00:00:00+03:00",
"orderPrice": 0.02,
"sellType": "weight-by-piece",
"tariffingVolume": 1,
"tariffingUom": "кг",
"orderMinVolume": 1.0,
"orderStep": 1.0,
"orderUom": "уп."
}
},
"actionId": "900000113",
"promoId": "14_66D2F3205BCFB84B170076007FBCEFA3",
"status": "E0003"
}
]
}