diff --git a/test/api/v3/unit/libs/cron.test.js b/test/api/v3/unit/libs/cron.test.js index 0e30cddeb9..a319ba63b2 100644 --- a/test/api/v3/unit/libs/cron.test.js +++ b/test/api/v3/unit/libs/cron.test.js @@ -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; diff --git a/website/server/libs/cron.js b/website/server/libs/cron.js index 3e348e9baf..3b7f62d9f2 100644 --- a/website/server/libs/cron.js +++ b/website/server/libs/cron.js @@ -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()) {