50 lines
1.3 KiB
PHP
50 lines
1.3 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 DeleteTest extends TestCase
|
|
{
|
|
use RefreshDatabase, WithFaker;
|
|
|
|
|
|
public function test_unauthenticated_user_cannot_access(): void
|
|
{
|
|
$permission = Permission::factory()->create();
|
|
$response = $this->getJson(route('permissions.destroy',[$permission->id]));
|
|
$response->assertUnauthorized();
|
|
}
|
|
|
|
public function test_authenticated_user_can_delete_permission(): void
|
|
{
|
|
$user = User::factory()->create();
|
|
$permission = Permission::factory()->create();
|
|
|
|
$response = $this->actingAs($user)->deleteJson(route('permissions.destroy', [$permission->id]));
|
|
|
|
$response->assertOk()
|
|
->assertJson([
|
|
'message' => __('messages.successful'),
|
|
]);
|
|
|
|
$this->assertDatabaseMissing('permissions', [
|
|
'id' => $permission->id,
|
|
]);
|
|
}
|
|
|
|
public function test_guest_cannot_delete_permission(): void
|
|
{
|
|
$permission = Permission::factory()->create();
|
|
|
|
$response = $this->deleteJson(route('permissions.destroy', [$permission->id]));
|
|
|
|
$response->assertUnauthorized();
|
|
}
|
|
|
|
}
|