Hey,
Im trying to create a test where i verify that the data within an array is correct using an If statement. Below is the json im testing against and i want to be able to create a test so check that if there is a specific ID returned, then the following data in that array is correct if thats even possible?
[
{
"id": "04e7e4ac",
"title": "Simple rules & mistakes to avoid",
"slug": "simple-rules-and-mistakes-to-avoid/dp/04e7e4ac",
"productType": "e-learning-module",
"isConfigurable": false,
"shortDescription": null,
"defaultVariant": {
"sku": "78e12e11",
"price": "£4.99",
"originalPrice": "£4.99"
},
"images": [
{
"type": "main",
"baseUrl": "https://images.arcade.futurecdn.net/@prod",
"path": "/sylius/assets/images/8f/3c/9f99ea632a02773d237574b5962e.jpg"
}
],
"categories": []
},
So i want to check that if the ID equals “04e7e4ac” then the rest of the json has the correct values, i.e “title”: “Simple rules & mistakes to avoid”,
I have tried the below but its returning a pass regardless of the data im inputting
pm.test("Data for ID is correct", () => {
let jsonData = pm.response.json()
if (jsonData.id === "04e7e4ac") {
pm.expect(jsonData.id).to.equal("04e7e4ac")
pm.expect(jsonData.title).to.eql("Simple rules & mistakes to avoid")
pm.expect(jsonData.slug).to.eql("simple-rules-and-mistakes-to-avoid/dp/04e7e4ac")
}
})