Laravel fluent json testing assert multiple values

Viewed 34

I am writing a test for an endpoint which returns the following json:

{
    "data": [
        {
            "id": 1,
            "name": "Group 1",
            "description": "red"
        },
        {
            "id": 2,
            "name": "Group 2",
            "description": "blue"
        }
    ]
}

I want to assert that 2 "group" objects are returned with the correct ids, and I don't care about any of the other json properties within each group (there are many more than I show above).

I can assert that there is a data array with 2 objects, one of which has id of group 2:

->assertJson(
        fn (AssertableJson $json) =>
        $json->has(
          'data',
          2,
          fn (AssertableJson $json) =>
          $json->where('id', $group2->id)
            ->etc()
        )
          ->dump()
          ->etc()
      );

How can I assert that group 1 is the other object that is returned?

0 Answers
Related