Hi, I just want to make sure that this is correctly testing that An Object and an Object within an array is present.
Example api:
{
"items": [
{
"oID": "0000001211",
"oInvoiceNo": "1234567",
"OrderBlocks": [
{
"olLine": 1,
"olProductCode": "001"
}
]
}
]
}
Example test:
pm.test("Order Details are Present", () => {
pm.response.to.have.jsonBody("oID");
pm.response.to.have.jsonBody("oInvoiceNo");
pm.response.to.have.jsonBody("OrderBlocks[0].olLine");
pm.response.to.have.jsonBody("OrderBlocks[0].olProductCode");
});
Itâs returning as a Pass, but Iâve been experimenting with syntax all day with loads of different tests(I canât remember .js and pm.* so I just refactor constantly until it works), and Iâm sure I had one earlier that brought back a False Pass, just wanted to make sure that this is a correct way for checking that the correct properties, and properties within arrays are present in a response.
I also donât completely understand why this seems to work, shouldnât âoIDâ also require me to have an array like (âitems[0].oIDâ) ? Yet when I try this, it fails to find oID.
Was trying this initially and it failed, so the above is my new âfixâ:
pm.test("Order Details are Present", () => {
pm.response.to.have.jsonBody("items.OrderBlocks.olLine");
});
Any help/advice on testing this kind of stuff correctly is really appreciated, thanks!