-
-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathbilling.stripe-errors.unit.tests.js
More file actions
52 lines (45 loc) · 1.94 KB
/
billing.stripe-errors.unit.tests.js
File metadata and controls
52 lines (45 loc) · 1.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Module dependencies.
*/
import { describe, test, expect } from '@jest/globals';
import { isNonTransientStripeError } from '../lib/billing.stripe-errors.js';
/**
* Unit tests for isNonTransientStripeError — deterministic Stripe errors that
* should short-circuit retries (invalid request / authentication / permission),
* across both SDK-wrapped (.type = class name) and raw (.type = wire string) shapes.
*/
describe('isNonTransientStripeError', () => {
test.each([
'StripeInvalidRequestError',
'StripeIdempotencyError',
'StripeAuthenticationError',
'StripePermissionError',
])('returns true for SDK error class %s (err.type = class name)', (type) => {
expect(isNonTransientStripeError({ type })).toBe(true);
});
test('returns true via the rawType branch when the class is not listed', () => {
expect(isNonTransientStripeError({ type: 'StripeFutureUnknownError', rawType: 'invalid_request_error' })).toBe(
true,
);
});
test('returns true for an unwrapped API error object (type = invalid_request_error)', () => {
expect(isNonTransientStripeError({ type: 'invalid_request_error' })).toBe(true);
});
test.each(['StripeAPIError', 'StripeConnectionError', 'StripeRateLimitError'])(
'returns false for transient SDK error class %s',
(type) => {
expect(isNonTransientStripeError({ type })).toBe(false);
},
);
test('returns false for StripeCardError (402 — some decline codes are transient)', () => {
expect(isNonTransientStripeError({ type: 'StripeCardError' })).toBe(false);
});
test('returns false for a generic non-Stripe error', () => {
expect(isNonTransientStripeError(new Error('boom'))).toBe(false);
});
test('returns false for null / undefined / non-object', () => {
expect(isNonTransientStripeError(null)).toBe(false);
expect(isNonTransientStripeError(undefined)).toBe(false);
expect(isNonTransientStripeError('invalid_request_error')).toBe(false);
});
});