I have a Laravel 8 app I am writing a test for. Here is what my data looks like:
{
"data": [
{
"name": "Cumque ex quos.",
"createdAt": "2020-12-29T17:15:32.000000Z",
"updatedAt": "2020-12-29T17:15:32.000000Z",
"startAt": "2021-01-18 17:15:32",
"endAt": "2021-01-18 17:15:32",
"startedAt": null,
"status": "Running",
"range": {
"type": "percentage",
"max": 0,
"min": 0
},
},
{
"name": "Cumque ex quos 2.",
"createdAt": "2020-12-29T17:15:32.000000Z",
"updatedAt": "2020-12-29T17:15:32.000000Z",
"startAt": "2021-01-18 17:15:32",
"endAt": "2021-01-18 17:15:32",
"startedAt": null,
"status": "Running",
"range": {
"type": "percentage",
"max": 20,
"min": 100
},
},
],
"other_keys" [ ... ];
}
I want to test that every value of status in the response is equal to the value Running. Here's what my test looks like:
/** @test */
public function should_only_return_data_that_are_running()
{
$response = $this->getJson('/api/v2/data');
$response->assertJsonPath('data.*.status', 'Running');
}
This fails with the following:
Failed asserting that Array &0 (
0 => 'Running'
1 => 'Running'
) is identical to 'Running'.
I am obviously testing this incorrectly. What's the best way to test all of the objects returned in the data array and ensure that the status value is equal to Running?