setUpHasPlanner(); } public function test_list_user_dishes(): void { $planner = $this->planner; $users = User::factory()->planner($planner)->count(rand(3, 10))->create(); $dishes = Dish::factory()->planner($planner)->count(rand(3, 10))->create(); $dishes->each(function (Dish $dish) use ($users) { $dish->users()->sync($users->random(rand(1, 3))->pluck('id')); }); $targetUser = $users->random(); $targetUser->refresh(); $this ->actingAs($planner) ->get(route('api.users.dishes.index', [ 'user' => $targetUser->id, ])) ->assertStatus(200) ->assertJson(fn (AssertableJson $json) => $json ->where('success', true) ->has('payload', fn ($json) => $json ->has('user', fn ($json) => $json ->where('id', $targetUser->id) ->where('name', $targetUser->name) ->has('user_dishes', $targetUser->dishes->count()) ->where('user_dishes', $targetUser->userDishes ->map(fn (UserDish $userDish) => [ 'id' => $userDish->id, 'dish' => [ 'id' => $userDish->dish->id, 'name' => $userDish->dish->name, ], 'recurrences' => [], ]) ->toArray() ) ) ) ->where('errors', null) ); } }