Not quite understanding what you mean by that? What do you mean by Dynamic?
I get a bit queasy when I hear the word dynamic in a test. You need to control your test data, and your response data should be the same every time you run the request\test.
The order shouldn’t matter if you are searching the results, but you need to be careful with the parameters for the search. I don’t know enough about your dataset so I explained the difference between the JavaScript find and filter functions just in case its possible to have duplicate categories. (It may or may not be an issue that you need to cater for in your tests).
There is an assumption here, that you know the item, category and email that you want to test (and that all three elements are in the same object like your example response). Which in theory should be fairly straight forward to search using find or filter.
If the category and item that you want to match are in the same object, then you can extend the JavaScript find function to include both elements at the same time.
For example.
const response = pm.response.json()
pm.test(`Testing cat1`, () => {
let search = response.data.dummy.find(function (obj) {
return obj.cat === 'Testing cat1' && obj.itm === 'Test A';
});
console.log(search);
pm.expect(search).to.not.be.undefined
pm.expect(search.modified.email).to.eql('test1@123.com');
});
There is no real point in testing the item and category, you just need to check that the search is not undefined.
You could probably added the expected email into the parameters for the search and then you only need to check if its undefined.
However, I can’t the result being any different to the code I posted earlier. It’s basically another way of doing the same thing. Plus this will be only testing one record in the response. You have three in your example. What about those. Do they need testing?
I guess I’m not fully understanding the logic what you want to test.
Let’s break it down into expected vs actual results.
What is your expected result.
Is is to test that the email for (category1 = x and item1 = y) matches z.