actingAs($user); Filament::setTenant($tenant, true); $finding = Finding::factory()->for($tenant)->create([ 'status' => Finding::STATUS_NEW, ]); Livewire::test(ListFindings::class) ->callTableAction('triage', $finding) ->assertHasNoTableActionErrors(); $finding->refresh(); expect($finding->status)->toBe(Finding::STATUS_TRIAGED) ->and($finding->triaged_at)->not->toBeNull(); Livewire::test(ListFindings::class) ->callTableAction('start_progress', $finding) ->assertHasNoTableActionErrors(); $finding->refresh(); expect($finding->status)->toBe(Finding::STATUS_IN_PROGRESS) ->and($finding->in_progress_at)->not->toBeNull(); Livewire::test(ListFindings::class) ->callTableAction('resolve', $finding, [ 'resolved_reason' => 'patched', ]) ->assertHasNoTableActionErrors(); $finding->refresh(); expect($finding->status)->toBe(Finding::STATUS_RESOLVED) ->and($finding->resolved_reason)->toBe('patched') ->and($finding->resolved_at)->not->toBeNull(); Livewire::test(ListFindings::class) ->filterTable('open', false) ->callTableAction('reopen', $finding) ->assertHasNoTableActionErrors(); $finding->refresh(); expect($finding->status)->toBe(Finding::STATUS_REOPENED) ->and($finding->reopened_at)->not->toBeNull() ->and($finding->due_at)->not->toBeNull(); }); it('supports close and request exception via row actions', function (): void { [$user, $tenant] = createUserWithTenant(role: 'owner'); $this->actingAs($user); Filament::setTenant($tenant, true); $closeFinding = Finding::factory()->for($tenant)->create([ 'status' => Finding::STATUS_NEW, ]); $exceptionFinding = Finding::factory()->for($tenant)->create([ 'status' => Finding::STATUS_NEW, ]); Livewire::test(ListFindings::class) ->callTableAction('close', $closeFinding, [ 'closed_reason' => 'duplicate ticket', ]) ->assertHasNoTableActionErrors(); Livewire::test(ListFindings::class) ->callTableAction('request_exception', $exceptionFinding, [ 'owner_user_id' => (int) $user->getKey(), 'request_reason' => 'accepted by security', 'review_due_at' => now()->addDays(14)->toDateTimeString(), 'expires_at' => now()->addDays(30)->toDateTimeString(), ]) ->assertHasNoTableActionErrors(); expect($closeFinding->refresh()->status)->toBe(Finding::STATUS_CLOSED) ->and($closeFinding->closed_reason)->toBe('duplicate ticket'); $exception = FindingException::query() ->where('finding_id', (int) $exceptionFinding->getKey()) ->first(); expect($exception)->toBeInstanceOf(FindingException::class) ->and($exception?->status)->toBe(FindingException::STATUS_PENDING) ->and($exception?->request_reason)->toBe('accepted by security'); }); it('assigns owners and assignees via row action and rejects non-member ids', function (): void { [$manager, $tenant] = createUserWithTenant(role: 'manager'); $this->actingAs($manager); Filament::setTenant($tenant, true); $assignee = User::factory()->create(); createUserWithTenant(tenant: $tenant, user: $assignee, role: 'operator'); $outsider = User::factory()->create(); $finding = Finding::factory()->for($tenant)->create([ 'status' => Finding::STATUS_NEW, ]); Livewire::test(ListFindings::class) ->callTableAction('assign', $finding, [ 'assignee_user_id' => (int) $assignee->getKey(), 'owner_user_id' => (int) $manager->getKey(), ]) ->assertHasNoTableActionErrors(); $finding->refresh(); expect((int) $finding->assignee_user_id)->toBe((int) $assignee->getKey()) ->and((int) $finding->owner_user_id)->toBe((int) $manager->getKey()); Livewire::test(ListFindings::class) ->callTableAction('assign', $finding, [ 'assignee_user_id' => (int) $outsider->getKey(), 'owner_user_id' => (int) $manager->getKey(), ]); $finding->refresh(); expect((int) $finding->assignee_user_id)->toBe((int) $assignee->getKey()); }); it('keeps the admin workflow surface scoped to the canonical tenant', function (): void { $tenantA = Tenant::factory()->create(); [$user, $tenantA] = createUserWithTenant(tenant: $tenantA, role: 'owner'); $tenantB = Tenant::factory()->create([ 'workspace_id' => (int) $tenantA->workspace_id, ]); createUserWithTenant(tenant: $tenantB, user: $user, role: 'owner'); $visibleFinding = Finding::factory()->for($tenantA)->create([ 'status' => Finding::STATUS_NEW, ]); $hiddenFinding = Finding::factory()->for($tenantB)->create([ 'status' => Finding::STATUS_NEW, ]); $this->actingAs($user); Filament::setCurrentPanel('admin'); Filament::setTenant(null, true); Filament::bootCurrentPanel(); session()->put(WorkspaceContext::SESSION_KEY, (int) $tenantA->workspace_id); session()->put(WorkspaceContext::LAST_TENANT_IDS_SESSION_KEY, [ (string) $tenantA->workspace_id => (int) $tenantA->getKey(), ]); Livewire::actingAs($user)->test(ListFindings::class) ->assertCanSeeTableRecords([$visibleFinding]) ->assertCanNotSeeTableRecords([$hiddenFinding]); });