mercredi 10 mars 2021

How to assert array in array?

Can somebody please help me to assert array in array in postman ?

I have this peace of code:

"documents": [
        {
            "fileName": "file01_guid.pdf",
            "documentType": "document",
            "parentFiles": [
                "file01.pdf"
            ]
        },
        {
            "fileName": "file02_guid.pdf",
            "documentType": "document",
            "parentFiles": [
                "file01.pdf"
            ]
        }

I need to assert the "ParentFiles" array using this method:

var array = [];
var range = (json_response.data.documents).length

for (var i = 0; i < range; i++)

{
 var file = json_response.data.documents[i].fileName
 var type = json_response.data.documents[i].documentType;

 array.push(file)
 array.push(type)
}

So I could write this kind of test:

{
    pm.expect(array).to.include("file01.pdf", "file01.pdf");
});

Thank you in advance

Aucun commentaire:

Enregistrer un commentaire