Skip to content

Commit 46efee0

Browse files
test(billing): cover StripeInvalidRequestError class-name branch in retry short-circuit
The shouldRetry predicate guards both Stripe error type spellings (StripeInvalidRequestError class name + invalid_request_error raw type, which vary by stripe-node version). Add a parallel short-circuit test for the class-name value and align the existing test's predicate with the production one. Closes a coverage gap flagged by the pre-push gate.
1 parent b3f08d5 commit 46efee0

1 file changed

Lines changed: 16 additions & 1 deletion

File tree

modules/billing/tests/billing.retry.unit.tests.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,22 @@ describe('retryWithBackoff', () => {
4848
retryWithBackoff(fn, {
4949
attempts: 3,
5050
baseMs: 200,
51-
shouldRetry: (e) => e?.type !== 'invalid_request_error',
51+
shouldRetry: (e) => e?.type !== 'StripeInvalidRequestError' && e?.type !== 'invalid_request_error',
52+
}),
53+
).rejects.toThrow('bad params');
54+
expect(fn).toHaveBeenCalledTimes(1);
55+
});
56+
57+
test('short-circuits on the StripeInvalidRequestError class-name type too', async () => {
58+
// stripe-node exposes the error class name on .type in some SDK versions and the
59+
// raw API type string in others; the call-site predicate guards both, so cover both.
60+
const err = Object.assign(new Error('bad params'), { type: 'StripeInvalidRequestError' });
61+
const fn = jest.fn().mockRejectedValue(err);
62+
await expect(
63+
retryWithBackoff(fn, {
64+
attempts: 3,
65+
baseMs: 200,
66+
shouldRetry: (e) => e?.type !== 'StripeInvalidRequestError' && e?.type !== 'invalid_request_error',
5267
}),
5368
).rejects.toThrow('bad params');
5469
expect(fn).toHaveBeenCalledTimes(1);

0 commit comments

Comments
 (0)