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(); });