Files
famous-ly4-ev/app-modules/identity/tests/Feature/RoleResourceTest.php
T

37 lines
1.1 KiB
PHP
Raw Normal View History

<?php
use App\Models\User;
use Modules\Identity\Database\Seeders\RolePermissionSeeder;
use Modules\Identity\Filament\Resources\Roles\RoleResource;
use Spatie\Permission\Models\Role;
beforeEach(function () {
$this->seed(RolePermissionSeeder::class);
$this->superAdmin = User::factory()->create();
$this->superAdmin->assignRole('super_admin');
});
test('a super_admin can list and edit roles', function () {
$this->actingAs($this->superAdmin)->get('/admin/roles')->assertSuccessful();
$role = Role::where('name', 'support')->firstOrFail();
$this->actingAs($this->superAdmin)->get("/admin/roles/{$role->id}/edit")->assertSuccessful();
});
test('an admin without manage_roles is forbidden from the role resource', function () {
$admin = User::factory()->create();
$admin->assignRole('admin');
$this->actingAs($admin)->get('/admin/roles')->assertForbidden();
});
test('roles cannot be created or deleted from the resource', function () {
expect(RoleResource::canCreate())->toBeFalse();
$role = Role::where('name', 'support')->firstOrFail();
expect(RoleResource::canDelete($role))->toBeFalse();
});