mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
Fix case where a number was sometimes a string
This commit is contained in:
committed by
Phillip Thelen
parent
86e33b2364
commit
a3bc20f855
@@ -347,6 +347,7 @@ describe('cron', async () => {
|
|||||||
});
|
});
|
||||||
expect(user.purchased.plan.perkMonthCount).to.equal(1);
|
expect(user.purchased.plan.perkMonthCount).to.equal(1);
|
||||||
user.purchased.plan.perkMonthCount = undefined;
|
user.purchased.plan.perkMonthCount = undefined;
|
||||||
|
user.purchased.plan.consecutive.count = 8;
|
||||||
clock.restore();
|
clock.restore();
|
||||||
clock = sinon.useFakeTimers(moment().utcOffset(0).startOf('month').add(2, 'months')
|
clock = sinon.useFakeTimers(moment().utcOffset(0).startOf('month').add(2, 'months')
|
||||||
.add(2, 'days')
|
.add(2, 'days')
|
||||||
@@ -436,6 +437,8 @@ describe('cron', async () => {
|
|||||||
|
|
||||||
it('keeps existing plan.perkMonthCount intact when incrementing consecutive benefits', async () => {
|
it('keeps existing plan.perkMonthCount intact when incrementing consecutive benefits', async () => {
|
||||||
user3.purchased.plan.perkMonthCount = 2
|
user3.purchased.plan.perkMonthCount = 2
|
||||||
|
user3.purchased.plan.consecutive.trinkets = 1
|
||||||
|
user3.purchased.plan.consecutive.gemCapExtra = 5
|
||||||
clock = sinon.useFakeTimers(moment().utcOffset(0).startOf('month').add(4, 'months')
|
clock = sinon.useFakeTimers(moment().utcOffset(0).startOf('month').add(4, 'months')
|
||||||
.add(2, 'days')
|
.add(2, 'days')
|
||||||
.toDate());
|
.toDate());
|
||||||
@@ -443,6 +446,8 @@ describe('cron', async () => {
|
|||||||
user: user3, tasksByType, daysMissed, analytics,
|
user: user3, tasksByType, daysMissed, analytics,
|
||||||
});
|
});
|
||||||
expect(user3.purchased.plan.perkMonthCount).to.equal(2);
|
expect(user3.purchased.plan.perkMonthCount).to.equal(2);
|
||||||
|
expect(user3.purchased.plan.consecutive.trinkets).to.equal(2);
|
||||||
|
expect(user3.purchased.plan.consecutive.gemCapExtra).to.equal(10);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not increment consecutive benefits in the second month of the second period that they already have benefits for', async () => {
|
it('does not increment consecutive benefits in the second month of the second period that they already have benefits for', async () => {
|
||||||
@@ -516,6 +521,7 @@ describe('cron', async () => {
|
|||||||
user6.purchased.plan.customerId = 'subscribedId';
|
user6.purchased.plan.customerId = 'subscribedId';
|
||||||
user6.purchased.plan.dateUpdated = moment().toDate();
|
user6.purchased.plan.dateUpdated = moment().toDate();
|
||||||
user6.purchased.plan.planId = 'google_6mo';
|
user6.purchased.plan.planId = 'google_6mo';
|
||||||
|
user6.purchased.plan.perkMonthCount = 0;
|
||||||
user6.purchased.plan.consecutive.count = 0;
|
user6.purchased.plan.consecutive.count = 0;
|
||||||
user6.purchased.plan.consecutive.offset = 6;
|
user6.purchased.plan.consecutive.offset = 6;
|
||||||
user6.purchased.plan.consecutive.trinkets = 2;
|
user6.purchased.plan.consecutive.trinkets = 2;
|
||||||
@@ -561,6 +567,19 @@ describe('cron', async () => {
|
|||||||
expect(user6.purchased.plan.consecutive.gemCapExtra).to.equal(20);
|
expect(user6.purchased.plan.consecutive.gemCapExtra).to.equal(20);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('keeps existing plan.perkMonthCount intact when incrementing consecutive benefits', async () => {
|
||||||
|
user6.purchased.plan.perkMonthCount = 2
|
||||||
|
clock = sinon.useFakeTimers(moment().utcOffset(0).startOf('month').add(7, 'months')
|
||||||
|
.add(2, 'days')
|
||||||
|
.toDate());
|
||||||
|
await cron({
|
||||||
|
user: user6, tasksByType, daysMissed, analytics,
|
||||||
|
});
|
||||||
|
expect(user6.purchased.plan.perkMonthCount).to.equal(2);
|
||||||
|
expect(user6.purchased.plan.consecutive.trinkets).to.equal(4);
|
||||||
|
expect(user6.purchased.plan.consecutive.gemCapExtra).to.equal(20);
|
||||||
|
});
|
||||||
|
|
||||||
it('increments consecutive benefits the month after the third paid period has started', async () => {
|
it('increments consecutive benefits the month after the third paid period has started', async () => {
|
||||||
clock = sinon.useFakeTimers(moment().utcOffset(0).startOf('month').add(13, 'months')
|
clock = sinon.useFakeTimers(moment().utcOffset(0).startOf('month').add(13, 'months')
|
||||||
.add(2, 'days')
|
.add(2, 'days')
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ schema.plugin(baseModel, {
|
|||||||
|
|
||||||
schema.methods.incrementPerkCounterAndReward = async function incrementPerkCounterAndReward
|
schema.methods.incrementPerkCounterAndReward = async function incrementPerkCounterAndReward
|
||||||
(userID, adding) {
|
(userID, adding) {
|
||||||
|
if (typeof adding === 'string' || adding instanceof String) {
|
||||||
|
adding = parseInt(adding)
|
||||||
|
}
|
||||||
// if perkMonthCount wasn't used before, initialize it.
|
// if perkMonthCount wasn't used before, initialize it.
|
||||||
if (this.perkMonthCount == undefined && adding == 1) {
|
if (this.perkMonthCount == undefined && adding == 1) {
|
||||||
this.perkMonthCount = (this.consecutive.count-1) % SUBSCRIPTION_BASIC_BLOCK_LENGTH;
|
this.perkMonthCount = (this.consecutive.count-1) % SUBSCRIPTION_BASIC_BLOCK_LENGTH;
|
||||||
|
|||||||
Reference in New Issue
Block a user