## Summary - implement Spec 143 tenant lifecycle, operability, and tenant-context semantics across chooser, tenant management, onboarding, and canonical operation viewers - add centralized tenant lifecycle and operability support types, audit action coverage, and lifecycle-aware badge and action handling - add feature and unit coverage for tenant chooser eligibility, global search scoping, canonical operation access, onboarding authorization, and lifecycle presentation ## Testing - vendor/bin/sail artisan test --compact - vendor/bin/sail bin pint --dirty --format agent Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de> Reviewed-on: #172
61 lines
2.0 KiB
PHP
61 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use Filament\PanelRegistry;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
it('only returns active membership tenants for normal users', function (): void {
|
|
$user = User::factory()->create();
|
|
|
|
$allowed = Tenant::factory()->active()->create(['name' => 'Allowed']);
|
|
$onboarding = Tenant::factory()->onboarding()->create([
|
|
'workspace_id' => (int) $allowed->workspace_id,
|
|
'name' => 'Onboarding',
|
|
]);
|
|
$archived = Tenant::factory()->archived()->create([
|
|
'workspace_id' => (int) $allowed->workspace_id,
|
|
'name' => 'Archived',
|
|
]);
|
|
|
|
$user->tenants()->syncWithoutDetaching([
|
|
$allowed->getKey() => ['role' => 'readonly'],
|
|
$onboarding->getKey() => ['role' => 'readonly'],
|
|
$archived->getKey() => ['role' => 'readonly'],
|
|
]);
|
|
|
|
/** @var \Filament\Panel $panel */
|
|
$panel = app(PanelRegistry::class)->get('admin');
|
|
|
|
$tenants = $user->getTenants($panel);
|
|
|
|
expect($tenants)->toHaveCount(1);
|
|
expect($tenants->first()?->getKey())->toBe($allowed->getKey());
|
|
expect($tenants->contains(fn (Tenant $tenant): bool => $tenant->name === 'Onboarding'))->toBeFalse();
|
|
expect($tenants->contains(fn (Tenant $tenant): bool => $tenant->name === 'Archived'))->toBeFalse();
|
|
});
|
|
|
|
it('returns no tenants for users without active tenant memberships', function (): void {
|
|
$user = User::factory()->create();
|
|
|
|
$draft = Tenant::factory()->draft()->create(['name' => 'Draft']);
|
|
$archived = Tenant::factory()->archived()->create([
|
|
'workspace_id' => (int) $draft->workspace_id,
|
|
'name' => 'Archived',
|
|
]);
|
|
|
|
$user->tenants()->syncWithoutDetaching([
|
|
$draft->getKey() => ['role' => 'readonly'],
|
|
$archived->getKey() => ['role' => 'readonly'],
|
|
]);
|
|
|
|
/** @var \Filament\Panel $panel */
|
|
$panel = app(PanelRegistry::class)->get('admin');
|
|
|
|
expect($user->getTenants($panel))->toHaveCount(0);
|
|
});
|