diff --git a/test/api/v3/unit/libs/payments.test.js b/test/api/v3/unit/libs/payments.test.js index e655c42080..ccec83b42a 100644 --- a/test/api/v3/unit/libs/payments.test.js +++ b/test/api/v3/unit/libs/payments.test.js @@ -504,6 +504,18 @@ describe('payments/index', () => { expect(daysTillTermination).to.be.within(13, 15); }); + it('terminates at next billing date even if dateUpdated is prior to now', async () => { + data.nextBill = moment().add({ days: 15 }); + data.user.purchased.plan.dateUpdated = moment().subtract({ days: 10 }); + + await api.cancelSubscription(data); + + let now = new Date(); + let daysTillTermination = moment(user.purchased.plan.dateTerminated).diff(now, 'days'); + + expect(daysTillTermination).to.be.within(13, 15); + }); + it('resets plan.extraMonths', async () => { user.purchased.plan.extraMonths = 5; diff --git a/website/server/libs/payments.js b/website/server/libs/payments.js index 31c886a27c..3c15a560c3 100644 --- a/website/server/libs/payments.js +++ b/website/server/libs/payments.js @@ -452,7 +452,7 @@ api.cancelSubscription = async function cancelSubscription (data) { let remaining = data.nextBill ? moment(data.nextBill).diff(new Date(), 'days', true) : defaultRemainingDays; if (plan.extraMonths < 0) plan.extraMonths = 0; let extraDays = Math.ceil(30.5 * plan.extraMonths); - let nowStr = `${now.format('MM')}/${moment(plan.dateUpdated).format('DD')}/${now.format('YYYY')}`; + let nowStr = `${now.format('MM')}/${now.format('DD')}/${now.format('YYYY')}`; let nowStrFormat = 'MM/DD/YYYY'; plan.dateTerminated =