62 lines
1.9 KiB
PHP
62 lines
1.9 KiB
PHP
|
|
<?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 ListDishesTest extends TestCase
|
||
|
|
{
|
||
|
|
use HasPlanner;
|
||
|
|
use RefreshDatabase;
|
||
|
|
|
||
|
|
public function test_user_can_see_list_of_dishes(): void
|
||
|
|
{
|
||
|
|
$planner = $this->planner;
|
||
|
|
$dishes = Dish::factory()->planner($planner)->count(rand(2, 10))->create();
|
||
|
|
|
||
|
|
$this
|
||
|
|
->actingAs($planner)
|
||
|
|
->get(route('api.dishes.index'))
|
||
|
|
->assertStatus(200)
|
||
|
|
->assertJson(fn (AssertableJson $json) => $json
|
||
|
|
->where('success', true)
|
||
|
|
->has('payload', fn ($json) => $json
|
||
|
|
->where('dishes', $dishes
|
||
|
|
->map(fn (Dish $dish) => [
|
||
|
|
'id' => $dish->id,
|
||
|
|
'planner_id' => $planner->id,
|
||
|
|
'name' => $dish->name,
|
||
|
|
'users' => $dish->users->pluck('id')->toArray(),
|
||
|
|
])
|
||
|
|
->toArray()
|
||
|
|
)
|
||
|
|
)
|
||
|
|
->where('errors', null)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_user_cannot_see_list_of_other_users_dishes(): void
|
||
|
|
{
|
||
|
|
$planner = $this->planner;
|
||
|
|
$otherPlanner = Planner::factory()->create();
|
||
|
|
Dish::factory()->planner($otherPlanner)->count(rand(2, 10))->create();
|
||
|
|
|
||
|
|
$this
|
||
|
|
->actingAs($planner)
|
||
|
|
->get(route('api.dishes.index'))
|
||
|
|
->assertStatus(200)
|
||
|
|
->assertJson(fn (AssertableJson $json) => $json
|
||
|
|
->where('success', true)
|
||
|
|
->has('payload', fn ($json) => $json
|
||
|
|
->where('dishes', [])
|
||
|
|
)
|
||
|
|
->where('errors', null)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|