mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
* Use “now” for calculation of the subscription end date instead of plan.dateUpdated * add test to show previously incorrect logic does not affect sub end date.
This commit is contained in:
@@ -504,6 +504,18 @@ describe('payments/index', () => {
|
|||||||
expect(daysTillTermination).to.be.within(13, 15);
|
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 () => {
|
it('resets plan.extraMonths', async () => {
|
||||||
user.purchased.plan.extraMonths = 5;
|
user.purchased.plan.extraMonths = 5;
|
||||||
|
|
||||||
|
|||||||
@@ -452,7 +452,7 @@ api.cancelSubscription = async function cancelSubscription (data) {
|
|||||||
let remaining = data.nextBill ? moment(data.nextBill).diff(new Date(), 'days', true) : defaultRemainingDays;
|
let remaining = data.nextBill ? moment(data.nextBill).diff(new Date(), 'days', true) : defaultRemainingDays;
|
||||||
if (plan.extraMonths < 0) plan.extraMonths = 0;
|
if (plan.extraMonths < 0) plan.extraMonths = 0;
|
||||||
let extraDays = Math.ceil(30.5 * plan.extraMonths);
|
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';
|
let nowStrFormat = 'MM/DD/YYYY';
|
||||||
|
|
||||||
plan.dateTerminated =
|
plan.dateTerminated =
|
||||||
|
|||||||
Reference in New Issue
Block a user