Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
Signed-off-by: Lloric Mayuga Garcia <[email protected]>
  • Loading branch information
lloricode committed Aug 25, 2024
1 parent f0b8bed commit 93a65af
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 35 deletions.
34 changes: 0 additions & 34 deletions tests/Actions/EditRoleActionTest.php

This file was deleted.

11 changes: 10 additions & 1 deletion tests/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ function loginAsSuperAdmin()
return $user;
}

// get user admin role
function getSuperAdminRole(): RoleContract & Model
{
/** @var RoleContract&Model $role */
Expand All @@ -29,6 +28,16 @@ function getSuperAdminRole(): RoleContract & Model
return $role;
}

function getAdminRole(): RoleContract & Model
{
/** @var RoleContract&Model $role */
$role = app(RoleContract::class)->findByName(
name: PermissionConfig::admin(),
);

return $role;
}

function createRole(string $name, ?string $guard = null): RoleContract & Model
{
/** @var RoleContract&Model $role */
Expand Down
55 changes: 55 additions & 0 deletions tests/Resources/RoleResource/Pages/EditRoleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Lloricode\FilamentSpatieLaravelPermissionPlugin\Tests\Resources\RoleResource\Pages;

use Lloricode\FilamentSpatieLaravelPermissionPlugin\Config\PermissionConfig;
use Lloricode\FilamentSpatieLaravelPermissionPlugin\Resources\RoleResource\Pages\EditRole;

use function Pest\Laravel\assertDatabaseCount;
use function Pest\Laravel\assertDatabaseHas;
use function Pest\Livewire\livewire;

beforeEach(function () {

loginAsSuperAdmin();
});

it('can update role name', function () {

assertDatabaseCount('roles', 2);

$name = fake()->word();

$role = createRole($name);

livewire(EditRole::class, ['record' => $role->getRouteKey()])
->fillForm([
'name' => $name . ' new',
'guard_name' => PermissionConfig::defaultGuardName(),
])
->call('save')
->assertSuccessful();

assertDatabaseCount('roles', 3);
assertDatabaseHas('roles', [
'name' => $name . ' new',
]);
});
it('can not update admin', function () {

assertDatabaseCount('roles', 2);

$name = fake()->word();

livewire(EditRole::class, ['record' => getAdminRole()->getRouteKey()])
->fillForm([
'name' => $name,
'guard_name' => PermissionConfig::defaultGuardName(),
])
->call('save')
->assertStatus(400);

assertDatabaseCount('roles', 2);
});

0 comments on commit 93a65af

Please sign in to comment.