61 lines
1.9 KiB
PHP
61 lines
1.9 KiB
PHP
|
|
<?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 ListUserDishesTest extends TestCase
|
||
|
|
{
|
||
|
|
use HasPlanner;
|
||
|
|
use RefreshDatabase;
|
||
|
|
|
||
|
|
public function test_planner_can_see_user_dish(): void
|
||
|
|
{
|
||
|
|
$planner = $this->planner;
|
||
|
|
$users = User::factory()->planner($planner)->count(10)->create();
|
||
|
|
$dishes = Dish::factory()->planner($planner)->count(10)->create();
|
||
|
|
$users->each(function ($user) use ($dishes) {
|
||
|
|
$user->dishes()->attach($dishes->random(5));
|
||
|
|
});
|
||
|
|
|
||
|
|
$this
|
||
|
|
->actingAs($planner)
|
||
|
|
->get(route('api.user-dishes.index'))
|
||
|
|
->assertStatus(200)
|
||
|
|
->assertJson(fn (AssertableJson $json) => $json
|
||
|
|
->where('success', true)
|
||
|
|
->has('payload.user_dishes', 10 * 5)
|
||
|
|
->where('errors', null)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_planner_cannot_see_user_dishes_from_other_planner(): void
|
||
|
|
{
|
||
|
|
$planner = $this->planner;
|
||
|
|
$otherPlanner = Planner::factory()->create();
|
||
|
|
$users = User::factory()->planner($planner)->count(10)->create();
|
||
|
|
$dishes = Dish::factory()->planner($planner)->count(10)->create();
|
||
|
|
$users->each(function ($user) use ($dishes) {
|
||
|
|
$user->dishes()->attach($dishes->random(rand(1, 5)));
|
||
|
|
});
|
||
|
|
|
||
|
|
$this
|
||
|
|
->actingAs($otherPlanner)
|
||
|
|
->get(route('api.user-dishes.index'))
|
||
|
|
->assertStatus(200)
|
||
|
|
->assertJson(fn (AssertableJson $json) => $json
|
||
|
|
->where('success', true)
|
||
|
|
->has('payload.user_dishes', 0)
|
||
|
|
->where('errors', null)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|