42 lines
1.5 KiB
PHP
42 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\Department;
|
|
|
|
beforeEach(function (): void {
|
|
seedRoles();
|
|
});
|
|
|
|
it('allows viewers to read departments but not modify them', function (): void {
|
|
$viewer = createUserWithRole('viewer');
|
|
$department = Department::factory()->create();
|
|
|
|
expect($viewer->can('viewAny', Department::class))->toBeTrue()
|
|
->and($viewer->can('view', $department))->toBeTrue()
|
|
->and($viewer->can('create', Department::class))->toBeFalse()
|
|
->and($viewer->can('update', $department))->toBeFalse()
|
|
->and($viewer->can('delete', $department))->toBeFalse();
|
|
});
|
|
|
|
it('grants administrators full department access', function (): void {
|
|
$admin = createUserWithRole('administrator');
|
|
$department = Department::factory()->create();
|
|
|
|
expect($admin->can('viewAny', Department::class))->toBeTrue()
|
|
->and($admin->can('view', $department))->toBeTrue()
|
|
->and($admin->can('create', Department::class))->toBeTrue()
|
|
->and($admin->can('update', $department))->toBeTrue()
|
|
->and($admin->can('delete', $department))->toBeTrue();
|
|
});
|
|
|
|
it('grants super admin full department access', function (): void {
|
|
$superAdmin = createAdminUser();
|
|
$department = Department::factory()->create();
|
|
|
|
expect($superAdmin->can('viewAny', Department::class))->toBeTrue()
|
|
->and($superAdmin->can('create', Department::class))->toBeTrue()
|
|
->and($superAdmin->can('update', $department))->toBeTrue()
|
|
->and($superAdmin->can('delete', $department))->toBeTrue();
|
|
});
|