F
Filament11mo ago
Richard

Test EditUser livewire class gives 403

What I am trying to do: I am trying to setup tests for the EditUser class in my app. I use Pest. When I create the livewire instance and dump it I get the default 403 view. Please see the code below. What I did: I checked if my acting as user can update the other user with the UserPolicy. This method returns true. I checked if the canAccessPanel method of Filament in the User model gets called. It doesn't get called. I am not sure if it should be called during tests though. Also i checked the value of the record of the edit page. It's null. Please see the code below to check how I pass the id of the record to the class. My issue/the error: When I dump the livewire instance, I see the html of the default 403 page. However, I expect it to give the edit page. Code:
$this->actingAs($adminUser);

livewire(EditUser::class, ['record' => $normalUser->getRouteKey()]);
$this->actingAs($adminUser);

livewire(EditUser::class, ['record' => $normalUser->getRouteKey()]);
Solution:
I solved this by checking if viewAny in the UserPolicy was returning true for my specific case. It returned false, that's why I was getting a 403 error on the edit page. Edit: also, I use multi-tenancy so it's important to call
Filament::setTenant($x);
Filament::setTenant($x);
in the setup of my tests....
Jump to solution
1 Reply
Solution
Richard
Richard11mo ago
I solved this by checking if viewAny in the UserPolicy was returning true for my specific case. It returned false, that's why I was getting a 403 error on the edit page. Edit: also, I use multi-tenancy so it's important to call
Filament::setTenant($x);
Filament::setTenant($x);
in the setup of my tests. Marking this one as solved.
Want results from more Discord servers?
Add your server