Added defaults for monthly and yearly price
refs https://github.com/TryGhost/Team/issues/2362 Rather than throwing when we encounter a Tier price of 0, we can instead default to the standard yearly and monthly price.
This commit is contained in:
parent
205664f75f
commit
80b766047e
@ -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.'
|
||||
|
@ -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 = {};
|
||||
|
Loading…
Reference in New Issue
Block a user