TenantAtlas/tests/Feature/OpsUx/ActiveRunsTest.php
ahmido abda751296 feat(058): tenant dashboard + active-runs gating (#68)
Adds a tenant-scoped dashboard page (KPIs, Needs Attention, Recent Drift Findings, Recent Operations) with polling only while active runs exist.

Guardrails: DB-only render (no outbound HTTP) + tenant isolation.

Tests: ActiveRunsTest, TenantDashboardDbOnlyTest, TenantDashboardTenantScopeTest.
Co-authored-by: Ahmed Darrazi <ahmeddarrazi@adsmac.local>
Reviewed-on: #68
2026-01-21 14:00:42 +00:00

65 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\OperationRun;
use App\Models\Tenant;
use App\Support\OpsUx\ActiveRuns;
it('returns false when tenant has no active runs', function (): void {
$tenant = Tenant::factory()->create();
OperationRun::factory()->create([
'tenant_id' => $tenant->getKey(),
'type' => 'inventory.sync',
'status' => 'completed',
'outcome' => 'succeeded',
'initiator_name' => 'System',
]);
expect(ActiveRuns::existForTenant($tenant))->toBeFalse();
});
it('returns true when tenant has queued runs', function (): void {
$tenant = Tenant::factory()->create();
OperationRun::factory()->create([
'tenant_id' => $tenant->getKey(),
'type' => 'inventory.sync',
'status' => 'queued',
'outcome' => 'pending',
'initiator_name' => 'System',
]);
expect(ActiveRuns::existForTenant($tenant))->toBeTrue();
});
it('returns true when tenant has running runs', function (): void {
$tenant = Tenant::factory()->create();
OperationRun::factory()->create([
'tenant_id' => $tenant->getKey(),
'type' => 'inventory.sync',
'status' => 'running',
'outcome' => 'pending',
'initiator_name' => 'System',
]);
expect(ActiveRuns::existForTenant($tenant))->toBeTrue();
});
it('is tenant scoped (other tenant active runs do not count)', function (): void {
$tenantA = Tenant::factory()->create();
$tenantB = Tenant::factory()->create();
OperationRun::factory()->create([
'tenant_id' => $tenantB->getKey(),
'type' => 'inventory.sync',
'status' => 'running',
'outcome' => 'pending',
'initiator_name' => 'System',
]);
expect(ActiveRuns::existForTenant($tenantA))->toBeFalse();
});