planner; $dishes = Dish::factory()->planner($planner)->count(rand(80, 100))->create(); $users = User::factory()->planner($planner)->count(rand(2, 10))->create(); $users->each(fn (User $user) => UserDish::factory() ->user($user) ->dish($dishes->random()) ->create()); $this ->actingAs($planner) ->get(route('api.users.index')) ->assertStatus(200) ->assertJson(fn (AssertableJson $json) => $json ->where('success', true) ->has('payload', fn ($json) => $json ->where('users', $users ->sortBy('id') ->map(fn (User $user) => [ 'id' => $user->id, 'name' => $user->name, 'user_dishes' => $user->userDishes->map(fn (UserDish $userDish) => [ 'id' => $userDish->id, 'dish' => [ 'id' => $userDish->dish->id, 'name' => $userDish->dish->name, ], 'recurrences' => [], ])->toArray(), ]) ->toArray() ) ) ->where('errors', null) ); } public function test_user_cannot_see_list_of_users_of_other_planner(): void { $planner = $this->planner; $otherPlanner = Planner::factory()->create(); User::factory()->planner($otherPlanner)->count(rand(2, 10))->create(); $this ->actingAs($planner) ->get(route('api.users.index')) ->assertStatus(200) ->assertJson(fn (AssertableJson $json) => $json ->where('success', true) ->where('payload.users', []) ->where('errors', null) ); } }