Test that each nested and unnamed object has prior=248 or new=248
I am trying to write a test that checks each of the objects in the JSON response body for a specific string (in this case ‘248’) in either the ‘changes.prior’ or ‘changes.new’ field.
Here is an example JSON response body:
[
{
"eventType": "account-updated",
"changes": [
{
"property": "preferredStoreId",
"prior": "248",
"new": "20"
}
]
},
{
"eventType": "account-updated",
"changes": [
{
"property": "preferredStoreId",
"prior": "265",
"new": "248"
}
]
}
]
I reviewed this post and attempted these test scripts, neither of which works:
pm.test("Each event contains search param", () => {
require('lodash').each(jsonData, (item) => {
pm.expect(item.changes.prior || item.changes.new).to.contain('248')
})
})
pm.test('Each event contains search param', () => {
require('lodash').each(jsonData, (item) => {
pm.expect(item.changes.prior.contain("248") || item.changes.new.contain("248")).to.be.true
})
})
I believe the outer [brackets] are confusing me. Can anyone help me with a test like this?