diff --git a/ghost/tiers/lib/Tier.js b/ghost/tiers/lib/Tier.js index 6b0345c0a6..133e95e513 100644 --- a/ghost/tiers/lib/Tier.js +++ b/ghost/tiers/lib/Tier.js @@ -419,6 +419,9 @@ function validateMonthlyPrice(value, type) { } return null; } + if (!value) { + return 500; + } if (!Number.isSafeInteger(value)) { throw new ValidationError({ message: 'Tier prices must be an integer.' @@ -446,6 +449,9 @@ function validateYearlyPrice(value, type) { } return null; } + if (!value) { + return 5000; + } if (!Number.isSafeInteger(value)) { throw new ValidationError({ message: 'Tier prices must be an integer.' diff --git a/ghost/tiers/test/Tier.test.js b/ghost/tiers/test/Tier.test.js index 6037de7602..6528ddf42c 100644 --- a/ghost/tiers/test/Tier.test.js +++ b/ghost/tiers/test/Tier.test.js @@ -52,11 +52,9 @@ const invalidInputs = [ {currency: 25}, {currency: 'USD', type: 'free'}, {monthlyPrice: 2000, type: 'free', trialDays: null, currency: null, yearlyPrice: null}, - {monthlyPrice: null}, {monthlyPrice: -20}, {monthlyPrice: 10000000000}, {yearlyPrice: 2000, type: 'free', trialDays: null, monthlyPrice: null, currency: null}, - {yearlyPrice: null}, {yearlyPrice: -20}, {yearlyPrice: 10000000000}, {createdAt: 'Today'}, @@ -87,6 +85,17 @@ describe('Tier', function () { } }); + it('Uses default monthly and yearly price if they are set to 0', async function () { + const tier = await Tier.create({ + ...validInput, + monthlyPrice: 0, + yearlyPrice: 0 + }); + + assert.equal(tier.getPrice('month'), 500); + assert.equal(tier.getPrice('year'), 5000); + }); + it('Does not error for valid inputs', async function () { for (const validInputItem of validInputs) { let input = {};