F
Filament3mo ago
Andi

pest 403 for List page

Hello I try to write a pest test to test the table.
beforeEach(fn() => asAdmin());

it('can render page', function () {
livewire(ListPermissions::class)
->assertSuccessful();
});
beforeEach(fn() => asAdmin());

it('can render page', function () {
livewire(ListPermissions::class)
->assertSuccessful();
});
asAdmin
function asAdmin(): TestCase
{
$user = User::factory()->create();

test()->seed(PermissionSeeder::class);

$permission = Permission::query()
->firstOrCreate(['name' => '*']);
$user->permissions()->attach($permission);

return test()->actingAs($user);
}
function asAdmin(): TestCase
{
$user = User::factory()->create();

test()->seed(PermissionSeeder::class);

$permission = Permission::query()
->firstOrCreate(['name' => '*']);
$user->permissions()->attach($permission);

return test()->actingAs($user);
}
assertSuccessful fails because of 403. And yes, I do have canAccessPanel in User model, it just returns true. On production I am able to login and access the resource.
4 Replies
LeandroFerreira
LeandroFerreira3mo ago
Did you double-check $this->user->permissions inside the test?
Andi
AndiOP3mo ago
Yes, permissions are set. But somehow livewire() is not triggering my middleware. Because I also test with get() if I am able to see / not see index page of the resource.
LeandroFerreira
LeandroFerreira3mo ago
Maybe you could temporarily bypass the permissions to check if that’s causing the issue
Andi
AndiOP3mo ago
Yes, works. Just commented out policy
Want results from more Discord servers?
Add your server