How to test with multi-tenancy ?

When I want to test a create form on a multi-tenant aware panel, I get an error because the index route is missing the tenant parameter. I think this is the index route used by the "cancel" button. How do I inject the correct tenant in my test to prevent this error ? Here is my code :
test('superadmin can create admin', function () {
$this->signInAsSuperAdmin();
livewire(CreateSuperadmin::class)
->fillForm([
'name' => 'New Admin',
'email' => '[email protected]',
'password' => 'password',
])
->call('create')
->assertHasNoFormErrors();

$this->assertDatabaseHas(User::class, [
'name' => 'New Admin',
'email' => '[email protected]',
]);
});
test('superadmin can create admin', function () {
$this->signInAsSuperAdmin();
livewire(CreateSuperadmin::class)
->fillForm([
'name' => 'New Admin',
'email' => '[email protected]',
'password' => 'password',
])
->call('create')
->assertHasNoFormErrors();

$this->assertDatabaseHas(User::class, [
'name' => 'New Admin',
'email' => '[email protected]',
]);
});
Although it is the create page, I get the following error : Missing required parameter for [Route: filament.admin.resources.superadmin.index]
2 Replies
Patrick Boivin
Patrick Boivin15mo ago
Not sure but have you tried setting a tenant at the start of your test? Something like this
Filament::setTenant(Team::factory()->create());
Filament::setTenant(Team::factory()->create());
groenewege
groenewegeOP15mo ago
@pboivin thank you that works ! However, the call must be made after loging in a user.
Want results from more Discord servers?
Add your server