In my program, there is an input parameter known as IsFruit that can have a value of either 0 or 1. If IsFruit is set to 0, the response should return fruits with a FruitsYN value of N. Similarly, if it is set to 1, FruitsYN should be Y. In cases where IsFruit has no value specified, the response can contain FruitsYN as either Y or N. I have noticed that while some test cases are passing successfully, others are failing. When I print IsFruit in cases where it is empty, it appears as ∅
var requestData = JSON.parse(request.data);
var responseData = JSON.parse(responseBody);
var IsFruit=requestData.IsFruit;// IsFruit can be either 0,1 or empty
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
pm.test("Check if Fruits found with this search criteria", function() {
pm.expect(responseData.Message).to.not.eql("No Fruits found with this search criteria");
var list = (responseData.Fruits).length;
//console.log(list);
var a = [];
for (var i = 0; i < list; i++) {
var counter = responseData.Fruits[i];
FruitsYN = counter.FruitsYN
//console.log(FruitsYN);
a.push(FruitsYN)
pm.test("Check whether Fruit values in the Fruits returned is accurate based on fruit filter in the request", function() {
if (IsFruit == 0) {
pm.expect(FruitsYN).to.eql("N")
}
if (IsFruit == 1) {
pm.expect(FruitsYN).to.eql("Y")
}
if (IsFruit =="") {
pm.expect(FruitsYN).to.be.oneOf(["Y", "N"]);
}
});
}
});
});