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

54 lines
1.5 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 SHowTest extends TestCase
{
use RefreshDatabase, WithFaker;
public function test_guest_cannot_view_permission(): void
{
$permission = Permission::factory()->create();
$response = $this->getJson(route('permissions.show', $permission));
$response->assertUnauthorized();
}
public function test_permission_show_returns_correct_structure_and_data(): void
{
$user = User::factory()
->has(Permission::factory()->state([
'name' => 'manage-permissions',
'name_fa' => 'مدیریت دسترسی‌ها',
'guard_name' => 'web',
]))
->create();
$permission = Permission::factory()->create([
'name' => 'edit-posts',
'name_fa' => 'ویرایش پست‌ها',
'guard_name' => 'web',
]);
$response = $this->actingAs($user)->getJson(route('permissions.show', $permission));
$response->assertOk()
->assertJson([
'data' => [
'id' => $permission->id,
'name' => 'edit-posts',
'name_fa' => 'ویرایش پست‌ها',
'guard_name' => 'web',
]
]);
}
}