setUpHasPlanner(); } public function test_planner_can_see_user_dish(): void { $planner = $this->planner; $user = User::factory()->planner($planner)->create(); $dish = Dish::factory()->planner($planner)->create(); $user->dishes()->attach($dish); $userDish = $user->userDishes->first(); $this ->actingAs($planner) ->get(route('api.users.dishes.show', [ 'user' => $user->id, 'dish' => $dish->id, ])) ->assertStatus(200) ->assertJson(fn (AssertableJson $json) => $json ->where('success', true) ->has('payload', fn ($json) => $json ->has('user_dish', fn ($json) => $json ->where('id', $userDish->id) ->has('user', fn ($json) => $json ->where('id', $user->id) ->where('name', $user->name) ) ->has('dish', fn ($json) => $json ->where('id', $dish->id) ->where('planner_id', $planner->id) ->where('name', $dish->name) ->has('users') ) ->where('recurrences', []) ) ) ->where('errors', null) ); } public function test_planner_cannot_see_user_dish_of_other_user(): void { $planner = $this->planner; $otherPlanner = Planner::factory()->create(); $user = User::factory()->planner($otherPlanner)->create(); $dish = Dish::factory()->planner($otherPlanner)->create(); $user->dishes()->attach($dish); $this ->actingAs($planner) ->get(route('api.users.dishes.show', [ 'user' => $user->id, 'dish' => $dish->id, ])) ->assertStatus(404) ->assertJson(fn (AssertableJson $json) => $json ->where('success', false) ->where('payload', null) ->where('errors', ['MODEL_NOT_FOUND']) ); } }