How to write a statement to verify that in the list of entities there is an entity with the status "Recalled"

Hello everybody!

Please help with writing a script for validating the response in the body of the json message (an example of json below).

So far, such a test returns an error:

pm.test ("Appeals with the status 'Withdrawn' come in the list v2", function () {
    var jsonData = pm.response.json ();
    pm.expect (jsonData.body.appeals.appeal) .to.have.property ("id");
})

I want to check that the list contains the entity with the status “Withdrawn”

Example json:

{
   "success":true,
   "body":{
      "lastPage":true,
      "appeals":[
         {
            "appeal":{
               "id":"1-SKZND7K",
               "num":"200416-0098-219500",
               "createDate":"2020-04-15T21:23:57.000Z",
               "clientDate":"2020-04-20T13:24:52.000Z",
               "status":"В работе",
               "subjects":[
                  "Тематика для клиента - Тест",
                  "Тематика для клиента - Тест 2"
               ]
            }
         },
         {
            "appeal":{
               "id":"1-SKYEU04",
               "num":"200416-0098-218900",
               "createDate":"2020-04-15T21:15:55.000Z",
               "clientDate":"2020-04-20T13:17:07.000Z",
               "status":"В работе",
               "subjects":[
                  "Тематика для клиента - Тест",
                  "Тематика для клиента - Тест 2"
               ]
            }
         },
         {
            "appeal":{
               "id":"1-SKYBBK0",
               "num":"200415-0098-209100",
               "createDate":"2020-04-15T20:55:45.000Z",
               "clientDate":"2020-04-20T12:57:21.000Z",
               "status":"В работе",
               "subjects":[
                  "Тематика для клиента - Тест",
                  "Тематика для клиента - Тест 2"
               ]
            }
         }
      ]
   }
}

Hey @EKanischev,

I’m not 100% sure what you want to do here and the response example that you added, doesn’t include Withdrawn as a status.

If you wanted to check that the status property contains a certain state, you can use this to loop through the appeals array and check each of the appeal objects. I don’t know what the correct word for Withdrawn is so I google translated it but I think that might be wrong :smile:

pm.test ("Appeals with the status 'Withdrawn' come in the list v2", function () {
    var jsonData = pm.response.json ();
    _.each(jsonData.body.appeals, (arrItem) => {
        pm.expect(arrItem.appeal).to.have.property("status").to.equal("отозваны");
    });
}); 

If you needed something more specific, please let me know :smile: