F
Filament15mo ago
Rimon

Testing resources with Filament Shield

Does anyone know why the following test could be failing?
1 Reply
Rimon
RimonOP15mo ago
<?php

namespace Tests\Feature;

use App\Filament\Resources\MissionResource;
use App\Models\Mission;
use App\Models\MissionType;
use App\Models\User;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

test(
'it renders the widget',
function () {
Permission::create(['name' => 'view_mission']);
Permission::create(['name' => 'view_any_mission']);
$role = Role::create(['name' => 'mission_admin']);
$role->givePermissionTo('view_mission');
$role->givePermissionTo('view_any_mission');

$admin = User::factory()->create();
$admin->assignRole('mission_admin');

MissionType::factory()->create(['name' => 'Wildfire Support', 'color' => '#2776BD']);
$mission = Mission::factory()->create();

$this->actingAs($admin);

$this->get(MissionResource::getUrl('view', [
'record' => $mission,
]))->assertSuccessful();
}
);
<?php

namespace Tests\Feature;

use App\Filament\Resources\MissionResource;
use App\Models\Mission;
use App\Models\MissionType;
use App\Models\User;
use Spatie\Permission\Models\Permission;
use Spatie\Permission\Models\Role;

test(
'it renders the widget',
function () {
Permission::create(['name' => 'view_mission']);
Permission::create(['name' => 'view_any_mission']);
$role = Role::create(['name' => 'mission_admin']);
$role->givePermissionTo('view_mission');
$role->givePermissionTo('view_any_mission');

$admin = User::factory()->create();
$admin->assignRole('mission_admin');

MissionType::factory()->create(['name' => 'Wildfire Support', 'color' => '#2776BD']);
$mission = Mission::factory()->create();

$this->actingAs($admin);

$this->get(MissionResource::getUrl('view', [
'record' => $mission,
]))->assertSuccessful();
}
);
The resource is set up and I've included Filament Shield and spatie/laravel-permissions in the project. Everything works when mimicking the above actions in the browser, but the assertion always fails with a 403 Forbidden
Want results from more Discord servers?
Add your server