Files
backend/tests/Feature/Permission/ListTest.php

52 lines
1.2 KiB
PHP

<?php
namespace Tests\Feature\Permission;
use App\Models\Permission;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Testing\Fluent\AssertableJson;
use Tests\TestCase;
class ListTest extends TestCase
{
use RefreshDatabase, WithFaker;
public function test_unauthenticated_user_cannot_access(): void
{
$response = $this->getJson(route('permissions.list'));
$response->assertUnauthorized();
}
public function test_guest_user_cannot_access_list(): void
{
$response = $this->getJson(route('permissions.list'));
$response->assertUnauthorized();
}
public function test_permissions_list_returns_correct_structure(): void
{
$user = User::factory()
->create();
Permission::factory()->count(3)->create();
$response = $this->actingAs($user)->getJson(route('permissions.list'));
$response->assertOk()
->assertJsonStructure([
'data' => [
'*' => [
'id',
'name',
'name_fa',
]
]
]);
}
}