Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.
Here’s an outline with best practices for making your inquiry.
pm.test(“Status code is 200”, function () {
pm.response.to.have.status(200);
});
pm.test(“Correct method is used in request”, function () {
const cond = pm.request.method === “GET”;
pm.expect(cond).to.eql(true);
});
pm.test(“Correct path is used in request”, function () {
pm.expect(pm.request.url.path[0]).to.match(/^books$/);
});
const body = pm.response.json()
pm.test(“Response is an array”, function () {
const cond = Array.isArray(body)
pm.expect(cond).to.eql(true);
});
pm.test(“Only books that are not currently checked out are returned”, function () {
const cond = body.every(book => !book.checkedOut)
pm.expect(cond).to.eql(true);
});
So you see the condition you are trying to test is
!book.checkedOut
this means that whaver you will get in your response negative of that so for current resposne which is true, cond becomes false and in next statement you are expecting it to be true,
what you should do is const cond = body.every(book => book.checkedOut) this would solve out your problem.