Hello friends!
I’ve already broken my head and need assistance.
I have response:
[
{
"name": "documentName1",
"documentId": 101
},
{
"name": "documentName2",
"documentId": 102
},
{
"name": "documentName3",
"documentId": 103
}
]
documentId = 103 is added to environment variable {{documentId3}}.
So, I need to ensure that some of documentIds has the value from variable.
I’ve tried:
const schema = pm.response.json();
pm.test('Document is in response', function () {
pm.expect(schema.find(obj => obj.documentId === (pm.environment.get("{{documentId3}}")))).to.exist;
});
pm.expect(schema.find(obj => obj.documentId === pm.environment.get("{{documentId3}}"))).to.exist;
pm.expect(schema.find(obj => obj.documentId === {{documentId3}})).to.exist;
pm.expect(schema.find(obj => obj.documentId === documentId3)).to.exist;
and other variations of writing the variable but I get “AssertionError: expected undefined to exist”.
How to write such function correctly?
Thank you in advance.