planner; $users = User::factory()->planner($planner)->count(10)->create(); $dishes = Dish::factory()->planner($planner)->count(10)->create(); $users->each(function ($user) use ($dishes) { $user->dishes()->attach($dishes->random(5)); }); $this ->actingAs($planner) ->get(route('api.user-dishes.index')) ->assertStatus(200) ->assertJson(fn (AssertableJson $json) => $json ->where('success', true) ->has('payload.user_dishes', 10 * 5) ->where('errors', null) ); } public function test_planner_cannot_see_user_dishes_from_other_planner(): void { $planner = $this->planner; $otherPlanner = Planner::factory()->create(); $users = User::factory()->planner($planner)->count(10)->create(); $dishes = Dish::factory()->planner($planner)->count(10)->create(); $users->each(function ($user) use ($dishes) { $user->dishes()->attach($dishes->random(rand(1, 5))); }); $this ->actingAs($otherPlanner) ->get(route('api.user-dishes.index')) ->assertStatus(200) ->assertJson(fn (AssertableJson $json) => $json ->where('success', true) ->has('payload.user_dishes', 0) ->where('errors', null) ); } }