Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions modules/billing/tests/billing.webhook.checkout.unit.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ describe('Billing webhook checkout unit tests:', () => {
});

afterEach(() => {
jest.useRealTimers();
jest.restoreAllMocks();
});

Expand Down Expand Up @@ -284,17 +285,21 @@ describe('Billing webhook checkout unit tests:', () => {
});

test('should not throw when paymentIntents.update fails (non-fatal fallback)', async () => {
jest.useFakeTimers();
const paymentIntentId = 'pi_test_failing';
mockStripeInstance.paymentIntents.update.mockRejectedValue(new Error('Stripe API error'));

await expect(
BillingWebhookService.handleCheckoutPaymentCompleted({
id: stripeSessionId,
payment_status: 'paid',
payment_intent: paymentIntentId,
metadata: { organizationId: orgId, packId: 'pack_500k', kind: 'extras' },
}),
).resolves.toBeUndefined();
const promise = BillingWebhookService.handleCheckoutPaymentCompleted({
id: stripeSessionId,
payment_status: 'paid',
payment_intent: paymentIntentId,
metadata: { organizationId: orgId, packId: 'pack_500k', kind: 'extras' },
});
// handleCheckoutPaymentCompleted catches the retry exhaustion internally (non-fatal),
// so the promise resolves; advance the backoff timers while it is pending.
const assertion = expect(promise).resolves.toBeUndefined();
await jest.runAllTimersAsync();
await assertion;

// creditPack should still have run despite the PI update failure
expect(mockExtraService.creditPack).toHaveBeenCalledWith(orgId, 'pack_500k', stripeSessionId);
Expand Down
Loading