write new tests
This commit is contained in:
51
tests/Feature/Role/ShowTest.php
Normal file
51
tests/Feature/Role/ShowTest.php
Normal 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(),
|
||||
]
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user