Skip to content

test(billing): use fake timers in checkout webhook unit test (slow regression) #3689

@PierreBrisorgueil

Description

@PierreBrisorgueil

Context

PR for Phase 2 audit fix (refund correlation retry — branch fix/billing-refund-correlation-retry) introduces retryWithBackoff around the PaymentIntent metadata backfill call. The existing test should not throw when paymentIntents.update fails (non-fatal fallback) at modules/billing/tests/billing.webhook.checkout.unit.tests.js:286 now incurs ~600ms of real wall-clock delays per run because :

  1. Retry wraps stripe.paymentIntents.update with backoff 200ms → 400ms → final
  2. The existing test mocks Stripe to throw, so all 3 retries fire with real setTimeout
  3. Test still passes (the assertion is .resolves.toBeUndefined()) but is now slow

Acceptance

  • Switch the test to jest.useFakeTimers() (or equivalent) + jest.runAllTimersAsync()
  • Test still passes
  • No real-timer delay incurred

Source

Discovered by spec reviewer on PR for Phase 2 audit fix (audit P1 — 2026-05-21).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions