permissions refactoring
This commit is contained in:
@@ -13,13 +13,19 @@ class UserTest extends TestCase
|
||||
use RefreshDatabase;
|
||||
|
||||
/**
|
||||
* Ensure the default user factory creates non-admin users.
|
||||
* Ensure the default user factory does not grant global admin access.
|
||||
*/
|
||||
public function test_user_factory_defaults_to_non_admin(): void
|
||||
public function test_user_factory_defaults_to_no_global_admin_access(): void
|
||||
{
|
||||
$user = User::factory()->create();
|
||||
|
||||
$this->assertFalse($user->is_admin);
|
||||
$this->assertDatabaseMissing('permission_assignments', [
|
||||
'assignee_id' => $user->id,
|
||||
'assignee_type' => $user->getMorphClass(),
|
||||
'permission' => 'global:admin',
|
||||
'scope_id' => null,
|
||||
'scope_type' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -29,7 +35,13 @@ class UserTest extends TestCase
|
||||
{
|
||||
$user = User::factory()->admin()->create();
|
||||
|
||||
$this->assertTrue($user->is_admin);
|
||||
$this->assertDatabaseHas('permission_assignments', [
|
||||
'assignee_id' => $user->id,
|
||||
'assignee_type' => $user->getMorphClass(),
|
||||
'permission' => 'global:admin',
|
||||
'scope_id' => null,
|
||||
'scope_type' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -39,14 +51,23 @@ class UserTest extends TestCase
|
||||
{
|
||||
$this->seed(UserSeeder::class);
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'email' => 'admin@kanbangit.test',
|
||||
'is_admin' => true,
|
||||
$admin = User::query()->where('email', 'admin@kanbangit.test')->firstOrFail();
|
||||
$member = User::query()->where('email', 'test@example.com')->firstOrFail();
|
||||
|
||||
$this->assertDatabaseHas('permission_assignments', [
|
||||
'assignee_id' => $admin->id,
|
||||
'assignee_type' => $admin->getMorphClass(),
|
||||
'permission' => 'global:admin',
|
||||
'scope_id' => null,
|
||||
'scope_type' => null,
|
||||
]);
|
||||
|
||||
$this->assertDatabaseHas('users', [
|
||||
'email' => 'test@example.com',
|
||||
'is_admin' => false,
|
||||
$this->assertDatabaseHas('permission_assignments', [
|
||||
'assignee_id' => $member->id,
|
||||
'assignee_type' => $member->getMorphClass(),
|
||||
'permission' => 'project:create',
|
||||
'scope_id' => null,
|
||||
'scope_type' => null,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user