F
Filament13mo ago
jals65

Testing using acting as with superadmin.

Hi, i'm using PEST to test some parts of my panel, and I want to make a test to assert that some html is visible. The problem is when i'm trying to use a new user, with super_admin role, but when the page render, it trows 403 forbidden. Here the test:
it('Has contextual menu', function () {
$project = \Maat\Projects\Models\Project::factory()->create();

$user = User::factory()->create();
$user->assignRole('super_admin');

$response = $this->actingAs($user)->get(\Maat\Projects\Resources\ProjectResource::getUrl('view', [
'record' => $project->name
]));

$response->assertSee('<span class="fi-sidebar-item-label flex-1 truncate text-primary-600 dark:text-primary-400 font-semibold">Info</span>');
});
it('Has contextual menu', function () {
$project = \Maat\Projects\Models\Project::factory()->create();

$user = User::factory()->create();
$user->assignRole('super_admin');

$response = $this->actingAs($user)->get(\Maat\Projects\Resources\ProjectResource::getUrl('view', [
'record' => $project->name
]));

$response->assertSee('<span class="fi-sidebar-item-label flex-1 truncate text-primary-600 dark:text-primary-400 font-semibold">Info</span>');
});
4 Replies
jals65
jals65OP13mo ago
I see in bbdd that the user is created correctly, all perms are created correctly, the super_admin has all permisions assigned, and the user has the super_admin role assigned.
LeandroFerreira
LeandroFerreira13mo ago
change the APP_ENV value to local in the phpunit.xml file and try again
jals65
jals65OP13mo ago
thanks, that is the problem. that was causing the 403
Want results from more Discord servers?
Add your server