F
Filament5mo ago
Noor

Test failing

My code -
test('user cannot view create inspection form if they do not have permission', function () {
$this->get(InspectionResource::getUrl('create'))->assertForbidden();

});
test('user cannot view create inspection form if they do not have permission', function () {
$this->get(InspectionResource::getUrl('create'))->assertForbidden();

});
Error
Tests\Feature\InspectionTest > user cannot view create inspection form if they do not have permission
Expected response status code [403] but received 200.
Failed asserting that 403 is identical to 200.
Tests\Feature\InspectionTest > user cannot view create inspection form if they do not have permission
Expected response status code [403] but received 200.
Failed asserting that 403 is identical to 200.
9 Replies
krekas
krekas5mo ago
how are you handling your permissions? there's your problem
Noor
Noor5mo ago
Permission::updateOrCreate(
['name' => 'View Inspections'],
['group' => 'Inspection', 'order' => 10]
);

Permission::updateOrCreate(
['name' => 'Create Inspection'],
['group' => 'Inspection', 'order' => 20]
);

Permission::updateOrCreate(
['name' => 'Update Inspection'],
['group' => 'Inspection', 'order' => 30]
);

Permission::updateOrCreate(
['name' => 'Delete Inspection'],
['group' => 'Inspection', 'order' => 40]
);

Permission::updateOrCreate(
['name' => 'Bulk Delete Inspections'],
['group' => 'Inspection', 'order' => 50]
);
Permission::updateOrCreate(
['name' => 'View Inspections'],
['group' => 'Inspection', 'order' => 10]
);

Permission::updateOrCreate(
['name' => 'Create Inspection'],
['group' => 'Inspection', 'order' => 20]
);

Permission::updateOrCreate(
['name' => 'Update Inspection'],
['group' => 'Inspection', 'order' => 30]
);

Permission::updateOrCreate(
['name' => 'Delete Inspection'],
['group' => 'Inspection', 'order' => 40]
);

Permission::updateOrCreate(
['name' => 'Bulk Delete Inspections'],
['group' => 'Inspection', 'order' => 50]
);
@krekas
krekas
krekas5mo ago
ok, so you create permissions this way. but how do you use them? directly in the recourse? policies? check the filament docs
Noor
Noor5mo ago
In policies @krekas
krekas
krekas5mo ago
your policies are wrong then. also do you seed permissions in the tests?
Noor
Noor5mo ago
public function create(User $user): bool
{
return $user->can('Create Inspection');
}
public function create(User $user): bool
{
return $user->can('Create Inspection');
}
@krekas I dont see anything wrong in it
krekas
krekas5mo ago
dd there if it even hits this policy and you don't need to tag every time
Noor
Noor5mo ago
dd where on test
krekas
krekas5mo ago
in policy create method
Want results from more Discord servers?
Add your server
More Posts