使用POSTMAN,我获得了JSON有效负载返回。我需要验证第一次返回PoiId时值是1234而第二个PoiId实例值是5678.验证返回PoiId值的顺序是正确的。我正在考虑这样做:
我在其他地方看到,可以将PoiId设置为数组:
var response = JSON.parse(responseBody),
PoiId = [];
这个想法是验证位置[0]的值是1234.对不起,但我很想在Postman中验证。想建议。
同样,结果的顺序是验证的目标。
{
"poi": [{
"PoiId": "1234",
"offeringName": "Test1",
"totalOfferingAmount": -15,
"offeringTypeQualifier": "Test",
"productTypeQualifier": "Product",
"quantity": -1,
"messages": [],
"autoAdd": false,
"autoAction": "removed",
"addedByProcessor": true,
"qualificationLevel": "FQ",
"qualificationDetails": []
}, {
"PoiId": "5678",
"offeringName": "Test2",
"totalOfferingAmount": -15,
"offeringTypeQualifier": "Test",
"productTypeQualifier": "Product",
"quantity": -1,
"messages": [],
"autoAdd": false,
"autoAction": "removed",
"addedByProcessor": true,
"qualificationLevel": "FQ",
"qualificationDetails": []
}],
"isPOIOfferValidForCheckout": true,
"_status": []
}
答案 0 :(得分:0)
由于 poi 是一个对象数组,您应该这样验证:
var response = JSON.parse(responseBody);
var poi = response.poi;
tests['First PoiId is 1234'] = poi[0].PoiId === 1234;
tests['Second PoiId is 5678'] = poi[1].PoiId === 5678;