55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Tests\Feature\User;
|
||
|
|
|
||
|
|
use App\Models\Planner;
|
||
|
|
use App\Models\User;
|
||
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||
|
|
use Illuminate\Testing\Fluent\AssertableJson;
|
||
|
|
use Tests\TestCase;
|
||
|
|
use Tests\Traits\HasPlanner;
|
||
|
|
|
||
|
|
class ShowUserTest extends TestCase
|
||
|
|
{
|
||
|
|
use HasPlanner;
|
||
|
|
use RefreshDatabase;
|
||
|
|
|
||
|
|
public function test_planner_can_see_user(): void
|
||
|
|
{
|
||
|
|
$planner = $this->planner;
|
||
|
|
$user = User::factory()->planner($planner)->create();
|
||
|
|
|
||
|
|
$this
|
||
|
|
->actingAs($planner)
|
||
|
|
->get(route('api.users.show', ['user' => $user]))
|
||
|
|
->assertStatus(200)
|
||
|
|
->assertJson(fn (AssertableJson $json) => $json
|
||
|
|
->where('success', true)
|
||
|
|
->has('payload', fn ($json) => $json
|
||
|
|
->has('user', fn ($json) => $json
|
||
|
|
->where('id', $user->id)
|
||
|
|
->where('name', $user->name)
|
||
|
|
)
|
||
|
|
)
|
||
|
|
->where('errors', null)
|
||
|
|
);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function test_planner_cannot_see_user_from_other_planner(): void
|
||
|
|
{
|
||
|
|
$planner = $this->planner;
|
||
|
|
$otherPlanner = Planner::factory()->create();
|
||
|
|
$user = User::factory()->planner($otherPlanner)->create();
|
||
|
|
|
||
|
|
$this
|
||
|
|
->actingAs($planner)
|
||
|
|
->get(route('api.users.show', ['user' => $user]))
|
||
|
|
->assertStatus(404)
|
||
|
|
->assertJson(fn (AssertableJson $json) => $json
|
||
|
|
->where('success', false)
|
||
|
|
->where('payload', null)
|
||
|
|
->where('errors', ['MODEL_NOT_FOUND'])
|
||
|
|
);
|
||
|
|
}
|
||
|
|
}
|