Skip to content

Commit 3989596

Browse files
test(billing): cover main checkout controller 502 path + invalid priceId
1 parent 3067183 commit 3989596

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

modules/billing/tests/billing.extras.controller.unit.tests.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ describe('Billing extras controller unit tests:', () => {
3131
jest.resetModules();
3232

3333
mockBillingService = {
34+
createCheckout: jest.fn(),
3435
createExtrasCheckout: jest.fn(),
3536
getLocalSubscription: jest.fn(),
3637
getSubscription: jest.fn(),
@@ -147,6 +148,28 @@ describe('Billing extras controller unit tests:', () => {
147148
});
148149
});
149150

151+
// ── checkout (main subscription) ───────────────────────────────────────────
152+
153+
describe('checkout', () => {
154+
test('should return 502 and log the error when Stripe call fails with generic error', async () => {
155+
req.body = { priceId: 'price_growth_m', successUrl: 'http://ok', cancelUrl: 'http://cancel' };
156+
mockBillingService.createCheckout.mockRejectedValue(new Error('Network error'));
157+
158+
await BillingController.checkout(req, res);
159+
160+
expect(res.status).toHaveBeenCalledWith(502);
161+
});
162+
163+
test('should return 422 when priceId is invalid (no logger.error on 422 path)', async () => {
164+
req.body = { priceId: 'price_unknown', successUrl: 'http://ok', cancelUrl: 'http://cancel' };
165+
mockBillingService.createCheckout.mockRejectedValue(new Error('Invalid priceId: price not found'));
166+
167+
await BillingController.checkout(req, res);
168+
169+
expect(res.status).toHaveBeenCalledWith(422);
170+
});
171+
});
172+
150173
// ── extrasBalance ──────────────────────────────────────────────────────────
151174

152175
describe('extrasBalance', () => {

0 commit comments

Comments
 (0)