Files
worldmonitor/tests/checkout-banner-initial-state.test.mts
Elie Habib 156cc4b86b refactor(checkout): rollout follow-up — P1 correctness + cleanup (#3276)
Squashed rebase onto current main (which now includes #3259, #3260,
#3261, #3270, #3273, #3274, #3265). PR-3276 was originally written
against PR-11's tip WITHOUT PR-14 (#3270) in its ancestry; now that
#3270 is merged, this rebase reconciles PR-3276's refactors with
the referral + nested-event-shape fixes that landed in main
independently.

Conflicts resolved (5 regions in src/services/checkout.ts):
  1. event shape read: kept main's nested event.data.message.status
     check + renamed _successFired → successFired (PR-3276's closure
     refactor)
  2. startCheckout session reset: applied PR-3276's _resetOverlaySession
     hook AND kept main's effectiveReferral / loadActiveReferral from
     #3270
  3. already-entitled banner branch: kept main's auto-dismiss fix
     (from #3261/#3265). PR-3276 was written without this fix; not
     regressing it. Used PR-3276's inlined isEntitled() check
     (computeInitialBannerState deletion per its P1 #251).
  4+5. banner timeout / active branches: kept main's stopEmailWatchers
     + currentState + currentMaskedEmail AND applied PR-3276's
     _currentBannerCleanup = null cleanup hook (per its P1 #254
     re-mount leak fix)

Also removed stale `origin: 'dashboard'` field from saveCheckoutAttempt
call (PR-3276 deleted that field from CheckoutAttempt interface per
its P1 #251 — dead write-only field).

Net refactor delivers all of PR-3276's intended fixes:
- #247 Module-scoped _successFired → per-session closure
- #249 #3163 hard-dep code markers
- #251 Delete over-engineered primitives (-65 LOC)
- #254 Banner re-mount listener leak cleanup

Tests pass (checkout-attempt-lifecycle + checkout-banner-initial-state).
Typecheck clean.
2026-04-22 16:08:43 +04:00

30 lines
1.0 KiB
TypeScript

/**
* Unit tests for the banner timing constants. DOM-level state transitions
* (pending → active → timeout) are async + event-driven and are covered
* by manual verification.
*/
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import {
EXTENDED_UNLOCK_TIMEOUT_MS,
CLASSIC_AUTO_DISMISS_MS,
} from '../src/services/checkout-banner-state.ts';
describe('banner timing constants', () => {
it('EXTENDED_UNLOCK_TIMEOUT_MS is 30s — covers webhook/propagation long tail', () => {
assert.equal(EXTENDED_UNLOCK_TIMEOUT_MS, 30_000);
});
it('CLASSIC_AUTO_DISMISS_MS is 5s — fast fade when unlock is already guaranteed', () => {
assert.equal(CLASSIC_AUTO_DISMISS_MS, 5_000);
});
it('classic auto-dismiss is strictly shorter than extended timeout', () => {
// If this ever flips, the non-extended flow would outlive the
// entitlement-wait flow, which defeats the "fast fade" intent.
assert.ok(CLASSIC_AUTO_DISMISS_MS < EXTENDED_UNLOCK_TIMEOUT_MS);
});
});