Another assertion test

I read alot in the forum in this week but i still struggle with assertion and nested objects. There were good tutorials but i was not able to transfer the knowlage.

I’d like to read the value in the arrays like for accounting and consultation

This is a example of the body response:
Unbenannt

The department objects has 8 arrays from 0 to 7.

I wrote a test but its “hardcode” not dynamic if something changes later.
hardcode

I’d like to find the array by name = “marketing” or other name = “…”

my idea was using this structure which i found in the forum Assertions for API Test scripts

but it didn’t worked for my because in almost all of the 8 arrays is the name key.

      for(let key in jsonData.office){
                    if(jsonData.office[key].**myproblem**('name=marketing')){
            accountingValue = jsonData.office[key].name.tasks.accounting;
      }
     }
    pm.test("value of accounting", function(){
      pm.expect(accountingValue).to.eql(false);
      });
1 Like

@kite0 - can you use filter() or find()?

let marketingDepartment = jsonData.office.department.find(dept => { return dept.name === "marketing" })
let accounting = marketingDepartment.tasks.accounting
2 Likes

Thank you it worked well that way :slight_smile:
i just i have to make it for each array with find function. think there are diffrent ways but its a good start.

in the test my result is 8 times “passed” like accounting status is false

can i add a comment or description to the “Test Results” ? Now all results look the same for me. I have already set enviorment variables to see if for marketing = accounting status is false etc. but would be nice also see in a quick overview for test results