Files
backend/tests/Feature/Permission/IndexTest.php
2025-05-12 17:05:42 +03:30

51 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 Tests\TestCase;
class IndexTest extends TestCase
{
use RefreshDatabase, WithFaker;
public function test_unauthenticated_user_cannot_access_permission_index(): void
{
$response = $this->getJson(route('permissions.index'));
$response->assertStatus(401);
}
public function test_all_permissions_returned_successfully(): void
{
$user = User::factory()
->has(Permission::factory()->state([
'name' => 'permissions',
'name_fa' => 'مدیریت دسترسی',
'guard_name' => 'web',
]))
->create();
$response = $this->actingAs($user)->getJson(route('permissions.index'));
$response->assertOk();
$response->assertJsonStructure([
'data' => [
'*' => [
'id',
'name',
'name_fa',
'guard_name',
'created_at',
'updated_at',
],
]
]);
}
}