add new field for cumulative subscription count

This commit is contained in:
Phillip Thelen
2024-09-27 14:12:52 +02:00
committed by Kalista Payne
parent 30096247b7
commit 4bafafdc8d
5 changed files with 47 additions and 3 deletions
+28 -3
View File
@@ -154,6 +154,14 @@ describe('cron', async () => {
expect(user.purchased.plan.consecutive.count).to.equal(1);
});
it('increments plan.cumulativeCount', async () => {
user.purchased.plan.cumulativeCount = 0;
await cron({
user, tasksByType, daysMissed, analytics,
});
expect(user.purchased.plan.cumulativeCount).to.equal(1);
});
it('increments plan.consecutive.count by more than 1 if user skipped months between logins', async () => {
user.purchased.plan.dateUpdated = moment().subtract(2, 'months').toDate();
user.purchased.plan.consecutive.count = 0;
@@ -163,6 +171,15 @@ describe('cron', async () => {
expect(user.purchased.plan.consecutive.count).to.equal(2);
});
it('increments plan.cumulativeCount by more than 1 if user skipped months between logins', async () => {
user.purchased.plan.dateUpdated = moment().subtract(3, 'months').toDate();
user.purchased.plan.cumulativeCount = 0;
await cron({
user, tasksByType, daysMissed, analytics,
});
expect(user.purchased.plan.cumulativeCount).to.equal(3);
});
it('does not award unearned plan.consecutive.trinkets if subscription ended during an absence', async () => {
user.purchased.plan.dateUpdated = moment().subtract(6, 'months').toDate();
user.purchased.plan.dateTerminated = moment().subtract(3, 'months').toDate();
@@ -226,7 +243,6 @@ describe('cron', async () => {
user1.purchased.plan.dateUpdated = moment().toDate();
user1.purchased.plan.planId = 'basic';
user1.purchased.plan.consecutive.count = 0;
user1.purchased.plan.perkMonthCount = 0;
user1.purchased.plan.consecutive.trinkets = 1;
user1.purchased.plan.consecutive.gemCapExtra = 0;
});
@@ -276,7 +292,6 @@ describe('cron', async () => {
user3.purchased.plan.customerId = 'subscribedId';
user3.purchased.plan.dateUpdated = moment().toDate();
user3.purchased.plan.planId = 'basic_3mo';
user3.purchased.plan.perkMonthCount = 0;
user3.purchased.plan.consecutive.count = 0;
user3.purchased.plan.consecutive.trinkets = 1;
user3.purchased.plan.consecutive.gemCapExtra = 0;
@@ -324,7 +339,6 @@ describe('cron', async () => {
user6.purchased.plan.customerId = 'subscribedId';
user6.purchased.plan.dateUpdated = moment().toDate();
user6.purchased.plan.planId = 'google_6mo';
user6.purchased.plan.perkMonthCount = 0;
user6.purchased.plan.consecutive.count = 0;
user6.purchased.plan.consecutive.trinkets = 1;
user6.purchased.plan.consecutive.gemCapExtra = 0;
@@ -407,6 +421,7 @@ describe('cron', async () => {
.toDate();
user3g.purchased.plan.planId = null;
user3g.purchased.plan.consecutive.count = 0;
user3g.purchased.plan.cumulativeCount = 0;
user3g.purchased.plan.consecutive.trinkets = 1;
user3g.purchased.plan.consecutive.gemCapExtra = 0;
@@ -418,6 +433,7 @@ describe('cron', async () => {
user: user3g, tasksByType, daysMissed, analytics,
});
expect(user3g.purchased.plan.consecutive.count).to.equal(1);
expect(user3g.purchased.plan.cumulativeCount).to.equal(1);
expect(user3g.purchased.plan.consecutive.trinkets).to.equal(2);
expect(user3g.purchased.plan.consecutive.gemCapExtra).to.equal(2);
});
@@ -433,6 +449,7 @@ describe('cron', async () => {
expect(user3g.purchased.plan.consecutive.count).to.equal(0);
expect(user3g.purchased.plan.consecutive.trinkets).to.equal(2);
expect(user3g.purchased.plan.consecutive.gemCapExtra).to.equal(2);
expect(user3g.purchased.plan.cumulativeCount).to.equal(3);
});
});
});
@@ -476,6 +493,14 @@ describe('cron', async () => {
expect(user.purchased.plan.consecutive.count).to.equal(0);
});
it('does not increment plan.cumulativeCount', async () => {
user.purchased.plan.cumulativeCount = 0;
await cron({
user, tasksByType, daysMissed, analytics,
});
expect(user.purchased.plan.cumulativeCount).to.equal(0);
});
it('does not increment plan.consecutive.trinkets when user has reached a month that is a multiple of 3', async () => {
user.purchased.plan.consecutive.count = 5;
await cron({
@@ -103,6 +103,20 @@
>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">
Cumulative months:
</label>
<div class="col-sm-9">
<input
v-model="hero.purchased.plan.cumulativeCount"
class="form-control"
type="number"
min="0"
step="1"
>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 col-form-label">
Next Mystic Hourglass:
@@ -311,6 +311,9 @@ api.updateHero = {
hero.purchased.plan.consecutive.count = plan.consecutive.count; // eslint-disable-line max-len
}
}
if (plan.cumulativeCount) {
hero.purchased.plan.cumulativeCount = plan.cumulativeCount;
}
}
// give them gems if they got an higher level
+1
View File
@@ -70,6 +70,7 @@ async function grantEndOfTheMonthPerks (user, now) {
revealMysteryItems(user, elapsedMonths);
plan.consecutive.count += elapsedMonths;
plan.cumulativeCount += elapsedMonths;
await plan.rewardPerks(user._id, elapsedMonths);
}
}
@@ -25,6 +25,7 @@ export const schema = new mongoose.Schema({
nextPaymentProcessing: Date,
nextBillingDate: Date, // Next time google will bill this user.
hourglassPromoReceived: Date,
cumulativeCount: { $type: Number, default: 0 },
consecutive: {
count: { $type: Number, default: 0 },
// when gifted subs, offset++ for each month. offset-- each new-month (cron).