Skip to content

Commit 9b6e060

Browse files
fix(billing): add defensive check for config.billing.plans and mock config in tests
1 parent e4edf4f commit 9b6e060

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

modules/billing/services/billing.webhook.service.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const Organization = mongoose.model('Organization');
1313
* Plan rank lookup — higher index means higher-tier plan.
1414
* Used to determine upgrade vs downgrade.
1515
*/
16-
const planRanks = Object.fromEntries(config.billing.plans.map((p, i) => [p, i]));
16+
const planRanks = Object.fromEntries((config.billing?.plans || []).map((p, i) => [p, i]));
1717

1818
/**
1919
* @desc Resolve the plan name from a Stripe subscription object.

modules/billing/tests/billing.events.unit.tests.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ describe('Billing plan.changed event unit tests:', () => {
3838
},
3939
}));
4040

41+
jest.unstable_mockModule('../../../config/index.js', () => ({
42+
default: {
43+
billing: {
44+
plans: ['free', 'starter', 'pro', 'enterprise'],
45+
},
46+
},
47+
}));
48+
4149
// Import service and events from the same module context
4250
const mod = await import('../services/billing.webhook.service.js');
4351
BillingWebhookService = mod.default;

0 commit comments

Comments
 (0)