2025-10-13 14:57:11 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace Tests\Feature\User\Dish;
|
|
|
|
|
|
|
|
|
|
use App\Models\Dish;
|
|
|
|
|
use App\Models\Planner;
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use App\Models\UserDish;
|
|
|
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
|
use Illuminate\Testing\Fluent\AssertableJson;
|
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
use Tests\Traits\HasPlanner;
|
|
|
|
|
|
|
|
|
|
class ShowUserDishTest extends TestCase
|
|
|
|
|
{
|
|
|
|
|
use HasPlanner;
|
|
|
|
|
use RefreshDatabase;
|
|
|
|
|
|
2025-12-29 23:36:15 +01:00
|
|
|
protected function setUp(): void
|
|
|
|
|
{
|
|
|
|
|
parent::setUp();
|
|
|
|
|
$this->setUpHasPlanner();
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-13 14:57:11 +02:00
|
|
|
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'])
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|