mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Payments gem reset (#8712)
* Added gem reset if user does not have date last updated set * Fixed login of adding updated date
This commit is contained in:
committed by
Sabe Jones
parent
8c8f0ea201
commit
39a112b605
@@ -79,6 +79,13 @@ describe('cron', () => {
|
|||||||
expect(user.purchased.plan.gemsBought).to.equal(0);
|
expect(user.purchased.plan.gemsBought).to.equal(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('resets plan.gemsBought on a new month if user does not have purchased.plan.dateUpdated', () => {
|
||||||
|
user.purchased.plan.gemsBought = 10;
|
||||||
|
user.purchased.plan.dateUpdated = undefined;
|
||||||
|
cron({user, tasksByType, daysMissed, analytics});
|
||||||
|
expect(user.purchased.plan.gemsBought).to.equal(0);
|
||||||
|
});
|
||||||
|
|
||||||
it('does not reset plan.gemsBought within the month', () => {
|
it('does not reset plan.gemsBought within the month', () => {
|
||||||
let clock = sinon.useFakeTimers(moment().startOf('month').add(2, 'days').unix());
|
let clock = sinon.useFakeTimers(moment().startOf('month').add(2, 'days').unix());
|
||||||
user.purchased.plan.dateUpdated = moment().startOf('month').toDate();
|
user.purchased.plan.dateUpdated = moment().startOf('month').toDate();
|
||||||
|
|||||||
@@ -206,8 +206,11 @@ export function cron (options = {}) {
|
|||||||
let perfect = true;
|
let perfect = true;
|
||||||
|
|
||||||
// Reset Gold-to-Gems cap if it's the start of the month
|
// 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').isSame(moment().startOf('month'))) {
|
let dateUpdatedFalse = !moment(user.purchased.plan.dateUpdated).startOf('month').isSame(moment().startOf('month')) || !user.purchased.plan.dateUpdated;
|
||||||
|
|
||||||
|
if (user.purchased && user.purchased.plan && dateUpdatedFalse) {
|
||||||
user.purchased.plan.gemsBought = 0;
|
user.purchased.plan.gemsBought = 0;
|
||||||
|
if (!user.purchased.plan.dateUpdated) user.purchased.plan.dateUpdated = moment();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.isSubscribed()) {
|
if (user.isSubscribed()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user