TenantAtlas/tests/Feature/OpsUx/TerminalNotificationFailureMessageTest.php
2026-01-18 14:44:16 +01:00

54 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\OperationRun;
use App\Services\OperationRunService;
use Filament\Facades\Filament;
it('sanitizes and truncates failure message suffix in terminal notifications', function (): void {
[$user, $tenant] = createUserWithTenant(role: 'owner');
$this->actingAs($user);
Filament::setTenant($tenant, true);
$longMessage = "This is a very long failure message that should not be allowed to flood the notification UI.\n\n".
str_repeat('x', 400);
$run = OperationRun::factory()->create([
'tenant_id' => $tenant->getKey(),
'user_id' => $user->getKey(),
'initiator_name' => $user->name,
'type' => 'inventory.sync',
'status' => 'running',
'outcome' => 'pending',
'context' => ['scope' => 'all'],
]);
/** @var OperationRunService $service */
$service = app(OperationRunService::class);
$service->updateRun(
$run,
status: 'completed',
outcome: 'failed',
summaryCounts: ['total' => 1],
failures: [[
'code' => 'example.failure',
'message' => $longMessage,
]],
);
$notification = $user->notifications()->latest('id')->first();
expect($notification)->not->toBeNull();
$body = (string) ($notification->data['body'] ?? '');
expect($body)->toContain('Failed.');
expect($body)->toContain('This is a very long failure message');
// Ensure message is not full-length / multiline.
expect($body)->not->toContain(str_repeat('x', 200));
expect($body)->not->toContain("\n\nThis is a very long failure message");
})->group('ops-ux');