hi colleagues,
i have a POST request which searchs for a particular object in the response body.Response body is an array like below
{
"structureNodeList": [
{
"tenantId": "*",
"retailStoreId": "101",
"structureUniqueName": "*",
"systemName": "*",
"structureName": "*",
"country": "*",
"countryShort": "*"
}
]
}
My request looks whether the retailSoreId=100 exists,in case retailSoreId=100 can be found,the next request will use it.My issue is ,if the retailSoreId=100 can not be found ,e.g like in the above response body instead of 100 the 101 is found,my request does not fail,it gives me the HTTPS status code 200.
I tried the following code
//check if structureUniqueName and retailStoreId for C4R Store has been found.If yes it will be deleted
var jsonData = JSON.parse(responseBody);
if (!jsonData.structureNodeList.find((a)=>a.retailStoreId===(store))) {
console.log(`Store ${store} could not be deleted because it does not exsist in SM.`)
throw "ERROR" ;
}else{
pm.collectionVariables.set("completeStore", jsonData.structureNodeList.find((a)=>a.retailStoreId===(store)).structureUniqueName);
pm.collectionVariables.set("retailStoreId", jsonData.structureNodeList.find((a)=>a.retailStoreId===(store)).retailStoreId);
console.log(`StructureUniqueName ${pm.collectionVariables.get('completeStore')} has been found in SM .`)
console.log(`Store ${pm.collectionVariables.get('retailStoreId')} is going to be deleted.`)
}
It will make the call to stop and an error is thrown in console,but in the collection runner the call is not marked as failed
I think i need a test condition based on response body using pm.expect()
but not sure how to do it if the body is an array and not a string.Any suggestion is appreciated