diff --git a/test/api/unit/libs/payments/stripe/calculateSubscriptionTerminationDate.test.js b/test/api/unit/libs/payments/stripe/calculateSubscriptionTerminationDate.test.js index 96e4a07304..e044cac353 100644 --- a/test/api/unit/libs/payments/stripe/calculateSubscriptionTerminationDate.test.js +++ b/test/api/unit/libs/payments/stripe/calculateSubscriptionTerminationDate.test.js @@ -72,10 +72,18 @@ describe('#calculateSubscriptionTerminationDate', () => { it('returns current terminated date if it exists and is later than newly calculated date', () => { const expectedTerminationDate = moment().add({ months: 5 }).toDate(); - plan.terminationDate = expectedTerminationDate; + plan.dateTerminated = expectedTerminationDate; const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId); expect(terminationDate).to.equal(expectedTerminationDate); }); + + it('returns the calculated termination date if the plan does not have one', () => { + nextBill = moment().add(5, 'days'); + const expectedTerminationDate = moment().add(5, 'days'); + + const terminationDate = calculateSubscriptionTerminationDate(nextBill, plan, groupPlanId); + expect(expectedTerminationDate.diff(terminationDate, 'days')).to.eql(0); + }); }); diff --git a/website/server/libs/payments/calculateSubscriptionTerminationDate.js b/website/server/libs/payments/calculateSubscriptionTerminationDate.js index 21bc54fc95..993dfac430 100644 --- a/website/server/libs/payments/calculateSubscriptionTerminationDate.js +++ b/website/server/libs/payments/calculateSubscriptionTerminationDate.js @@ -18,6 +18,12 @@ export default function calculateSubscriptionTerminationDate ( const calculatedTerminationDate = moment().startOf('day').add({ days: remaining + extraDays }); - return calculatedTerminationDate.isBefore(purchasedPlan.terminationDate) - ? purchasedPlan.terminationDate : calculatedTerminationDate.toDate(); + // If a termination date is already set, use the one further in the future + if (purchasedPlan.dateTerminated) { + return calculatedTerminationDate.isBefore(purchasedPlan.dateTerminated) + ? purchasedPlan.dateTerminated : calculatedTerminationDate.toDate(); + } + + // Otherwise the calculated one + return calculatedTerminationDate.toDate(); }