TenantAtlas/apps/platform/tests/Feature/Dashboard/MyFindingsSignalTest.php
ahmido 81bb5f42c7
Some checks failed
Main Confidence / confidence (push) Failing after 55s
feat: add findings operator inbox (#258)
## Summary
- add the canonical admin-plane `My Findings` inbox at `/admin/findings/my-work`
- add the workspace overview `Assigned to me` signal and inbox-to-detail continuity
- add focused Pest coverage plus the full Spec 221 artifact bundle

## Validation
- `cd apps/platform && ./vendor/bin/sail bin pint --dirty --format agent`
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Findings/MyWorkInboxTest.php tests/Feature/Authorization/MyWorkInboxAuthorizationTest.php tests/Feature/Dashboard/MyFindingsSignalTest.php`
- `cd apps/platform && ./vendor/bin/sail artisan test --compact tests/Feature/Filament/WorkspaceOverviewNavigationTest.php`
- integrated-browser smoke completed against the browser-facing `tenantatlas` runtime, including seeded positive-path and negative-path checks plus fixture cleanup

## Filament v5 Guardrails
- Livewire v4.0+ compliant
- panel provider registration remains in `apps/platform/bootstrap/providers.php`
- global search behavior is unchanged; `FindingResource` already has a View page and the new inbox is a custom page, not a searchable resource
- no destructive actions were introduced on the inbox or overview signal
- no new assets were added; the existing deploy step for `cd apps/platform && php artisan filament:assets` remains unchanged
- coverage includes the new inbox page, authorization boundaries, the workspace overview signal, and the overview CTA regression

Co-authored-by: Ahmed Darrazi <ahmed.darrazi@live.de>
Reviewed-on: #258
2026-04-21 09:19:54 +00:00

147 lines
5.7 KiB
PHP

<?php
declare(strict_types=1);
use App\Filament\Pages\Findings\MyFindingsInbox;
use App\Models\Finding;
use App\Models\Tenant;
use App\Models\User;
use App\Services\Auth\CapabilityResolver;
use App\Support\Auth\Capabilities;
use App\Support\Workspaces\WorkspaceOverviewBuilder;
use Carbon\CarbonImmutable;
use function Pest\Laravel\mock;
afterEach(function (): void {
CarbonImmutable::setTestNow();
});
it('builds an assigned-to-me signal from visible assigned findings only', function (): void {
CarbonImmutable::setTestNow(CarbonImmutable::create(2026, 4, 21, 9, 0, 0, 'UTC'));
$tenantA = Tenant::factory()->create(['status' => 'active']);
[$user, $tenantA] = createUserWithTenant($tenantA, role: 'readonly', workspaceRole: 'readonly');
$tenantB = Tenant::factory()->create([
'status' => 'active',
'workspace_id' => (int) $tenantA->workspace_id,
'name' => 'Bravo Tenant',
]);
createUserWithTenant($tenantB, $user, role: 'readonly', workspaceRole: 'readonly');
$hiddenTenant = Tenant::factory()->create([
'status' => 'active',
'workspace_id' => (int) $tenantA->workspace_id,
'name' => 'Hidden Tenant',
]);
Finding::factory()->for($tenantA)->create([
'workspace_id' => (int) $tenantA->workspace_id,
'assignee_user_id' => (int) $user->getKey(),
'owner_user_id' => (int) $user->getKey(),
'status' => Finding::STATUS_NEW,
'due_at' => now()->subHour(),
]);
Finding::factory()->for($tenantB)->create([
'workspace_id' => (int) $tenantB->workspace_id,
'assignee_user_id' => (int) $user->getKey(),
'owner_user_id' => (int) $user->getKey(),
'status' => Finding::STATUS_TRIAGED,
'due_at' => now()->addDay(),
]);
Finding::factory()->for($tenantB)->create([
'workspace_id' => (int) $tenantB->workspace_id,
'assignee_user_id' => null,
'owner_user_id' => (int) $user->getKey(),
'status' => Finding::STATUS_NEW,
]);
Finding::factory()->for($hiddenTenant)->create([
'workspace_id' => (int) $hiddenTenant->workspace_id,
'assignee_user_id' => (int) $user->getKey(),
'owner_user_id' => (int) $user->getKey(),
'status' => Finding::STATUS_NEW,
]);
$signal = app(WorkspaceOverviewBuilder::class)
->build($tenantA->workspace()->firstOrFail(), $user)['my_findings_signal'];
expect($signal['open_assigned_count'])->toBe(2)
->and($signal['overdue_assigned_count'])->toBe(1)
->and($signal['is_calm'])->toBeFalse()
->and($signal['cta_label'])->toBe('Open my findings')
->and($signal['cta_url'])->toBe(MyFindingsInbox::getUrl(panel: 'admin'));
});
it('keeps the signal calm when no visible assigned findings remain', function (): void {
$tenant = Tenant::factory()->create(['status' => 'active']);
[$user, $tenant] = createUserWithTenant($tenant, role: 'readonly', workspaceRole: 'readonly');
Finding::factory()->for($tenant)->create([
'workspace_id' => (int) $tenant->workspace_id,
'assignee_user_id' => (int) $user->getKey(),
'owner_user_id' => (int) $user->getKey(),
'status' => Finding::STATUS_RESOLVED,
'resolved_at' => now(),
]);
$signal = app(WorkspaceOverviewBuilder::class)
->build($tenant->workspace()->firstOrFail(), $user)['my_findings_signal'];
expect($signal['open_assigned_count'])->toBe(0)
->and($signal['overdue_assigned_count'])->toBe(0)
->and($signal['is_calm'])->toBeTrue()
->and($signal['description'])->toContain('visible assigned');
});
it('suppresses blocked-tenant findings from the assigned-to-me signal', function (): void {
$visibleTenant = Tenant::factory()->create(['status' => 'active']);
[$user, $visibleTenant] = createUserWithTenant($visibleTenant, role: 'readonly', workspaceRole: 'readonly');
$blockedTenant = Tenant::factory()->create([
'status' => 'active',
'workspace_id' => (int) $visibleTenant->workspace_id,
'name' => 'Blocked Tenant',
]);
createUserWithTenant($blockedTenant, $user, role: 'readonly', workspaceRole: 'readonly');
Finding::factory()->for($visibleTenant)->create([
'workspace_id' => (int) $visibleTenant->workspace_id,
'assignee_user_id' => (int) $user->getKey(),
'owner_user_id' => (int) $user->getKey(),
'status' => Finding::STATUS_NEW,
]);
Finding::factory()->for($blockedTenant)->create([
'workspace_id' => (int) $blockedTenant->workspace_id,
'assignee_user_id' => (int) $user->getKey(),
'owner_user_id' => (int) $user->getKey(),
'status' => Finding::STATUS_NEW,
]);
mock(CapabilityResolver::class, function ($mock) use ($visibleTenant, $blockedTenant): void {
$mock->shouldReceive('primeMemberships')->once();
$mock->shouldReceive('isMember')->andReturnTrue();
$mock->shouldReceive('can')
->andReturnUsing(static function (User $user, Tenant $tenant, string $capability) use ($visibleTenant, $blockedTenant): bool {
expect([(int) $visibleTenant->getKey(), (int) $blockedTenant->getKey()])
->toContain((int) $tenant->getKey());
return match ($capability) {
Capabilities::TENANT_FINDINGS_VIEW => (int) $tenant->getKey() === (int) $visibleTenant->getKey(),
default => false,
};
});
});
$signal = app(WorkspaceOverviewBuilder::class)
->build($visibleTenant->workspace()->firstOrFail(), $user)['my_findings_signal'];
expect($signal['open_assigned_count'])->toBe(1)
->and($signal['overdue_assigned_count'])->toBe(0)
->and($signal['description'])->not->toContain($blockedTenant->name);
});