write new tests

This commit is contained in:
2025-05-12 17:05:42 +03:30
parent 70f3c36f58
commit db8cda55df
13 changed files with 507 additions and 18 deletions

View File

@@ -0,0 +1,51 @@
<?php
namespace Tests\Feature\Role;
use App\Models\Permission;
use App\Models\Role;
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_role(): void
{
$role = Role::factory()->create();
$response = $this->postJson(route('roles.show',[$role->id]));
$response->assertUnauthorized();
}
public function test_a_role_can_be_returned_properly():void
{
$user = User::factory()->create();
$role = Role::factory()->create();
$permission = Permission::factory()->create([
'id' => 2,
'name' => $this->faker->name,
'name_fa' => $this->faker->name
]);
$role->syncPermissions($permission);
$role = Role::factory()->create();
$response = $this->actingAs($user)->getJson(route('roles.show', [$role->id]));
$response->assertOk()
->assertJson([
'data' => [
'id' => $role->id,
'name' => $role->name,
'name_fa' => $role->name_fa,
'permissions' => $role->permissions->pluck('name')->toArray(),
]
]);
}
}