app/tests/Feature/Dish/ShowDishTest.php

52 lines
1.4 KiB
PHP
Raw Permalink Normal View History

2025-10-13 14:57:11 +02:00
<?php
namespace Tests\Feature\Dish;
use App\Models\Dish;
use App\Models\Planner;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Testing\Fluent\AssertableJson;
use Tests\TestCase;
use Tests\Traits\HasPlanner;
class ShowDishTest extends TestCase
{
use HasPlanner;
use RefreshDatabase;
public function test_user_can_see_dish(): void
{
$planner = $this->planner;
$dish = Dish::factory()->planner($planner)->create();
$this
->actingAs($planner)
->get(route('api.dishes.show', $dish))
->assertStatus(200)
->assertJson(fn (AssertableJson $json) => $json
->where('success', true)
->has('payload', fn ($json) => $json
->has('dish', fn ($json) => $json
->where('id', $dish->id)
->where('planner_id', $planner->id)
->where('name', $dish->name)
->has('users')
)
)
->where('errors', null)
);
}
public function test_user_cannot_see_dish_from_other_user(): void
{
$planner = $this->planner;
$otherPlanner = Planner::factory()->create();
$dish = Dish::factory()->planner($otherPlanner)->create();
$this
->actingAs($planner)
->get(route('api.dishes.show', $dish))
->assertStatus(404);
}
}