Hi,
I have the following JSON response
[
{
"nid": "387",
"changed": "1612429358"
},
{
"nid": "388",
"changed": "1612439271"
},
{
"nid": "389",
"changed": "1612958700"
},
{
"nid": "399",
"changed": "1613139731"
},
{
"nid": "392",
"changed": "1613140500"
},
{
"nid": "393",
"changed": "1613145772"
}
]
And I’m running the following test to verify that a specified ‘nid’ is returned in the response.
/* Verify apprenticeship in the status of "Published" is correctly returned */
var resp = JSON.parse(responseBody);
var _ = require('lodash')
var apprenticeshipexists = _.find(resp, function(o) {
return o.nid == pm.collectionVariables.get("publishedNID"); });
pm.test("Published apprenticeship is returned", function () {
pm.expect((apprenticeshipexists) != null).to.be.true});
//If test has passed add apprenticeship ID as a variable for use in further tests
if (pm.expect((apprenticeshipexists) != null).to.be.true = true){
pm.collectionVariables.set("PublishedIDTemp", pm.collectionVariables.get("publishedNID"));
} else
{console.log("Test failed apprenticeship ID not present");
}
The test is ‘passing’ and ‘failing’ correctly, however my if statement is always adding the variable '“PublishedIDTemp” even when pm.expect((apprenticeshipexists) != null).to.be.true returns as false. Can you help?
Thanks