I have a nested 'if, else if, else' test script for #Postman tests but i get some condition executed when it is not meant to be and others not executed properly.
When I comment some section out of the condition in the test, it works as desired.
var jsonData = JSON.parse(responseBody);
if (responseCode.code === 200){
tests["Http status is 200"] = responseCode.code === 200;
try{
tests["ID: "] = jsonData.id === jsonData.id;
tests["Name is: "] = jsonData.name === jsonData.name;
tests["Description is: "]= jsonData.description === jsonData.description;
}
catch(e){}
}
else if (responseCode.code !== 200){
//using invalid token
tests["Http status is 401"] = responseCode.code === 401;
try{
tests["Response Message is: " + jsonData.error] = jsonData.error;
}
catch(e){}
}
else(responseCode.code !== 200){
//record not found
tests["Http status is 404"] = responseCode.code === 404;
try{
tests["Status Code is " + responseStatus.status] = responseStatus.status;
tests["Response Message is: " + jsonData.message] = jsonData.message;
tests["Time is " + jsonData.timestamp] = jsonDat.timestamp;
}catch(e){}
}