mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
fix(subscriptions): don't reset Gems midmonth
This commit is contained in:
@@ -71,6 +71,17 @@ describe('cron', () => {
|
||||
expect(user.purchased.plan.gemsBought).to.equal(0);
|
||||
});
|
||||
|
||||
it('does not reset plans.gemsBought within the month', () => {
|
||||
let clock = sinon.useFakeTimers(Number(moment().startOf('month').add(2, 'days').toDate()));
|
||||
user.purchased.plan.dateUpdated = moment().startOf('month').toDate();
|
||||
|
||||
user.purchased.plan.gemsBought = 10;
|
||||
cron({user, tasksByType, daysMissed, analytics});
|
||||
expect(user.purchased.plan.gemsBought).to.equal(10);
|
||||
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
it('resets plan.dateUpdated on a new month', () => {
|
||||
let currentMonth = moment().startOf('month');
|
||||
cron({user, tasksByType, daysMissed, analytics});
|
||||
@@ -173,6 +184,17 @@ describe('cron', () => {
|
||||
expect(user.purchased.plan.gemsBought).to.equal(0);
|
||||
});
|
||||
|
||||
it('does not reset plans.gemsBought within the month', () => {
|
||||
let clock = sinon.useFakeTimers(Number(moment().startOf('month').add(2, 'days').toDate()));
|
||||
user.purchased.plan.dateUpdated = moment().startOf('month').toDate();
|
||||
|
||||
user.purchased.plan.gemsBought = 10;
|
||||
cron({user, tasksByType, daysMissed, analytics});
|
||||
expect(user.purchased.plan.gemsBought).to.equal(10);
|
||||
|
||||
clock.restore();
|
||||
});
|
||||
|
||||
it('does not reset plan.dateUpdated on a new month', () => {
|
||||
cron({user, tasksByType, daysMissed, analytics});
|
||||
expect(user.purchased.plan.dateUpdated).to.be.empty;
|
||||
|
||||
@@ -125,7 +125,7 @@ export function cron (options = {}) {
|
||||
let perfect = true;
|
||||
|
||||
// Reset Gold-to-Gems cap if it's the start of the month
|
||||
if (user.purchased && user.purchased.plan && moment(user.purchased.plan.dateUpdated).startOf('month') !== moment().startOf('month')) {
|
||||
if (user.purchased && user.purchased.plan && !moment(user.purchased.plan.dateUpdated).startOf('month').isSame(moment().startOf('month'))) {
|
||||
user.purchased.plan.gemsBought = 0;
|
||||
}
|
||||
if (user.isSubscribed()) {
|
||||
|
||||
Reference in New Issue
Block a user