F
Filament11mo 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
krekas11mo ago
how are you handling your permissions? there's your problem
Noor
NoorOP11mo 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
krekas11mo ago
ok, so you create permissions this way. but how do you use them? directly in the recourse? policies? check the filament docs
Noor
NoorOP11mo ago
In policies @krekas
krekas
krekas11mo ago
your policies are wrong then. also do you seed permissions in the tests?
Noor
NoorOP11mo 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
krekas11mo ago
dd there if it even hits this policy and you don't need to tag every time
Noor
NoorOP11mo ago
dd where on test
krekas
krekas11mo ago
in policy create method
Want results from more Discord servers?
Add your server