Best approach to asserting values in arrays within arrays within arrays

I am setting up a test suite for GraphQL endpoints and am getting a “false pass” or a test that should have failed when I “tested my test” but is passing, so there is obviously something wrong.
I have seen a few examples showing assertions that go into arrays within arrays, but we have data that (as you can see with a sample I made more generic, with structure intact) that we need to assert specific values with where there are more “levels” and/or key: value pairs within the array. I’ve written ridiculously complicated assertions for arrays/hashes/both for Ruby REST APIs, with RSpec, but most of the documentation I’ve found for Postman and/or testing GraphQL with Postman does not go that “deep.”

{
“data”: {
“thing1”: {
“getUser”: {
“FirstName”: “Test”,
“LastName”: “Again”,
“Department”: {
“DeptName”: “Dept.2”
},
“MyDate”: {
“MyDateIs”: 1596870000
},
Nickname
}
}
}
}

The test:

const jsonData = pm.response.json();

pm.test("The user first name is correct", () => {
_.each(jsonData.thing1, (item) => {
    pm.expect(item.thing1.getUser.FirstName).to.equal("Test")
})
})

pm.test("the user last name is correct", () => {
_.each(jsonData.thing1, (item) => {
    pm.expect(item.thing1.getUser.LastName).to.equal("Again")
})
})

})

If I run the above tests, they all pass, but unfortunately, running the last one (with the last name wrong to verify my assertion structure) also “passed” or was green and counted as a pass in Postman, but it was obviously wrong. I originally had to.eql and had the same result.

pm.test("the user last name is correct", () => {
    _.each(jsonData.thing1, (item) => {
        pm.expect(item.thing1.getUser.LastName).to.equal("Agaainin")
    })

In the next iteration of this test, the goal is to pass and assert values based on a specific environment, so it would be great if anyone had some favorite resources on how to address the above question with variables, but I need to make sure everything is structured correctly to give us accurate results first.

Edit: I was able to get correctly passing/failing assertions using the approach shown at the bottom of this page: Assertions for API Test scripts

This passes:
pm.test(“The user last name is correct”, () => {
let lastName = jsonData.data.thing1.getUser.lastName;
pm.expect(lastName).to.equal(“Again”);
})

This test version

pm.test(“The user last name is correct”, () => {
let lastName = jsonData.data.thing1.getUser.lastName;
pm.expect(lastName).to.equal(“Jones”);
})

fails with an error AssertionError: expected ‘Again’ to equal ‘Jones’

Is there a way to convert this approach to working with variables/parameters across environments? Or is there an alternative that would be better for that use case?

Your question may already have an answer on the community forum. Please search for related topics, and then read through the guidelines before creating a new topic.