test(billing): use fake timers in checkout webhook fallback test#3698
Conversation
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
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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()andjest.runAllTimersAsync()to advance retry backoff instantly. - Add
jest.useRealTimers()inafterEachto prevent fake-timer leakage into sibling tests.
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
Summary
should not throw when paymentIntents.update fails (non-fatal fallback)test tojest.useFakeTimers()+jest.runAllTimersAsync(), eliminating ~600ms of realretryWithBackoffbackoff delay per run (≈600ms → ~5ms).afterEachso fake timers can't leak into sibling tests.creditPackstill called with the right args).Test plan
npm run test:unit— checkout webhook suite green, target test now ~5msCloses #3689