create([ 'status' => 'active', ]); $second = Tenant::factory()->create([ 'status' => 'active', ]); $user = User::factory()->create(); $this->actingAs($user); $user->tenants()->syncWithoutDetaching([ $first->getKey() => ['role' => 'owner'], $second->getKey() => ['role' => 'owner'], ]); Filament::setTenant($first, true); Livewire::test(ChooseTenant::class) ->call('selectTenant', $second->getKey()) ->assertRedirect(TenantDashboard::getUrl(tenant: $second)); $preference = UserTenantPreference::query() ->where('user_id', $user->getKey()) ->where('tenant_id', $second->getKey()) ->first(); expect($preference)->not->toBeNull(); expect($preference?->last_used_at)->not->toBeNull(); });