TenantAtlas/apps/platform/tests/Feature/Filament/UnhandledRejectionLoggerAssetTest.php
Ahmed Darrazi 72ddc18743 feat: implement spec 192 header discipline
- land the spec 192 resource, guard, browser smoke, and documentation changes
- add unhandled rejection request correlation for 419 diagnostics
- disable panel-wide database notification polling and cover it with focused tests
2026-04-11 23:09:42 +02:00

40 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
it('injects the unhandled rejection logger into Filament pages', function (): void {
$this->get('/admin/login')
->assertSuccessful()
->assertSee('js/tenantpilot/unhandled-rejection-logger.js', escape: false);
});
it('ships a window unhandledrejection logger with structured payload output', function (): void {
$js = file_get_contents(public_path('js/tenantpilot/unhandled-rejection-logger.js'));
expect($js)->toBeString();
expect($js)
->toContain('__tenantpilotUnhandledRejectionLoggerApplied')
->toContain("window.addEventListener('unhandledrejection'")
->toContain('window.fetch = async (...args) =>')
->toContain('XMLHttpRequest.prototype.open = function (method, url, ...rest)')
->toContain('const transport = resolveTransportMetadata(normalizedReason)')
->toContain('requestUrl: transport?.requestUrl ?? null')
->toContain('requestMethod: transport?.method ?? null')
->toContain('transportType: transport?.transportType ?? null')
->toContain('requestUrl: payload.requestUrl')
->toContain('isExpectedBackgroundTransportFailure')
->toContain("document.visibilityState !== 'visible'")
->toContain('document.hasFocus')
->toContain('event.preventDefault()')
->toContain('status === 419')
->toContain('Page Expired')
->toContain('status === 404')
->toContain('Not Found')
->toContain('const dedupeKey = toStableJson({')
->toContain('reason: payload.reason')
->toContain('TenantPilot unhandled promise rejection')
->toContain('JSON.stringify')
->not->toContain('recentKeys.has(payloadJson)')
->not->toContain('recentKeys.set(payloadJson, nowMs)');
});