TenantAtlas/tests/Feature/OpsUx/NoQueuedDbNotificationsTest.php
2026-01-18 15:46:49 +01:00

37 lines
1023 B
PHP

<?php
declare(strict_types=1);
use App\Notifications\OperationRunQueued;
use App\Services\OperationRunService;
use Filament\Facades\Filament;
it('emits at most one queued database notification per newly created run', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$this->actingAs($user);
$tenant->makeCurrent();
Filament::setTenant($tenant, true);
/** @var OperationRunService $service */
$service = app(OperationRunService::class);
$run = $service->ensureRun(
tenant: $tenant,
type: 'policy.sync',
inputs: ['scope' => 'all'],
initiator: $user,
);
$service->dispatchOrFail($run, function (): void {
// no-op (dispatch succeeded)
});
expect($user->notifications()->count())->toBe(1);
$this->assertDatabaseHas('notifications', [
'notifiable_id' => $user->getKey(),
'notifiable_type' => $user->getMorphClass(),
'type' => OperationRunQueued::class,
]);
})->group('ops-ux');