Skip to content

test(billing): use fake timers in checkout webhook fallback test#3698

Merged
PierreBrisorgueil merged 1 commit into
masterfrom
test/billing-checkout-fake-timers
May 22, 2026
Merged

test(billing): use fake timers in checkout webhook fallback test#3698
PierreBrisorgueil merged 1 commit into
masterfrom
test/billing-checkout-fake-timers

Conversation

@PierreBrisorgueil
Copy link
Copy Markdown
Contributor

Summary

  • Convert the should not throw when paymentIntents.update fails (non-fatal fallback) test to jest.useFakeTimers() + jest.runAllTimersAsync(), eliminating ~600ms of real retryWithBackoff backoff delay per run (≈600ms → ~5ms).
  • Restore real timers in afterEach so fake timers can't leak into sibling tests.
  • Assertions unchanged (resolves undefined + creditPack still called with the right args).

Test plan

  • npm run test:unit — checkout webhook suite green, target test now ~5ms
  • lint clean
  • no sibling-test regression

Closes #3689

The non-fatal-fallback test mocked paymentIntents.update to reject, so it
incurred ~600ms of real retryWithBackoff delay per run. Drive the backoff
with jest.useFakeTimers() + runAllTimersAsync() and restore real timers in
afterEach so sibling tests are unaffected.

Closes #3689
Copilot AI review requested due to automatic review settings May 22, 2026 18:22
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

Warning

Rate limit exceeded

@PierreBrisorgueil has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 59 minutes and 50 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 0c1f57e0-b4f8-4c3d-a6c9-b9942f59a01b

📥 Commits

Reviewing files that changed from the base of the PR and between 3df0034 and 586e078.

📒 Files selected for processing (1)
  • modules/billing/tests/billing.webhook.checkout.unit.tests.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/billing-checkout-fake-timers

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Speeds up the billing checkout webhook unit test suite by eliminating real wall-clock backoff delays introduced by retryWithBackoff, while keeping existing assertions and behavior expectations intact.

Changes:

  • Switch the “paymentIntents.update fails (non-fatal fallback)” unit test to jest.useFakeTimers() and jest.runAllTimersAsync() to advance retry backoff instantly.
  • Add jest.useRealTimers() in afterEach to prevent fake-timer leakage into sibling tests.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.71%. Comparing base (3df0034) to head (586e078).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3698   +/-   ##
=======================================
  Coverage   89.71%   89.71%           
=======================================
  Files         142      142           
  Lines        4784     4784           
  Branches     1500     1500           
=======================================
  Hits         4292     4292           
  Misses        385      385           
  Partials      107      107           
Flag Coverage Δ
integration 59.53% <ø> (ø)
unit 66.17% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3df0034...586e078. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PierreBrisorgueil PierreBrisorgueil merged commit b7ea2e3 into master May 22, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants