planner; $dishes = Dish::factory()->planner($planner)->count(rand(2, 10))->create(); $this ->actingAs($planner) ->get(route('api.dishes.index')) ->assertStatus(200) ->assertJson(fn (AssertableJson $json) => $json ->where('success', true) ->has('payload', fn ($json) => $json ->where('dishes', $dishes ->map(fn (Dish $dish) => [ 'id' => $dish->id, 'planner_id' => $planner->id, 'name' => $dish->name, 'users' => $dish->users->pluck('id')->toArray(), ]) ->toArray() ) ) ->where('errors', null) ); } public function test_user_cannot_see_list_of_other_users_dishes(): void { $planner = $this->planner; $otherPlanner = Planner::factory()->create(); Dish::factory()->planner($otherPlanner)->count(rand(2, 10))->create(); $this ->actingAs($planner) ->get(route('api.dishes.index')) ->assertStatus(200) ->assertJson(fn (AssertableJson $json) => $json ->where('success', true) ->has('payload', fn ($json) => $json ->where('dishes', []) ) ->where('errors', null) ); } }