0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-20 22:42:53 -05:00

Handled null trial days on tiers

refs e26c977c66

- handles null trial days in admin and API, sets trial days as 0 for null values
This commit is contained in:
Rishabh 2022-08-09 08:40:57 +05:30 committed by Rishabh Garg
parent 98b21d18f9
commit ce80d250bf
3 changed files with 18 additions and 2 deletions

View file

@ -14,6 +14,6 @@ export default Model.extend(ValidationEngine, {
currency: attr('string'),
monthlyPrice: attr('number'),
yearlyPrice: attr('number'),
trialDays: attr('number'),
trialDays: attr('number', {defaultValue: 0}),
benefits: attr('tier-benefits')
});

View file

@ -24,7 +24,7 @@ function convertTierInput(input) {
};
if (labs.isSet('freeTrial')) {
converted.trial_days = input.trial_days;
converted.trial_days = input.trial_days || 0;
}
if (input.monthly_price && input.currency) {

View file

@ -110,4 +110,20 @@ describe('Tiers API', function () {
assert(updatedTier.visibility === visibility, `The visibility of the Tier should have been updated to ${visibility}`);
});
it('Can save with trial_days as null', async function () {
const {body: {tiers: [tier]}} = await agent.get('/tiers/?limit=1');
await agent.put(`/tiers/${tier.id}/`)
.body({
tiers: [{
trial_days: null
}]
})
.expectStatus(200);
const {body: {tiers: [updatedTier]}} = await agent.get(`/tiers/${tier.id}/`);
assert(updatedTier.trial_days === 0, `The trial_days should have been set to 0`);
});
});