begin refactoring

This commit is contained in:
Phillip Thelen
2024-08-08 10:36:50 +02:00
committed by Kalista Payne
parent 96623608d0
commit 930d875ae9
7 changed files with 61 additions and 154 deletions
+18 -22
View File
@@ -197,16 +197,14 @@ describe('cron', async () => {
user.purchased.plan.dateTerminated = moment(new Date()).subtract({ days: 1 });
user.purchased.plan.consecutive.gemCapExtra = 20;
user.purchased.plan.consecutive.count = 5;
user.purchased.plan.consecutive.offset = 1;
await cron({
user, tasksByType, daysMissed, analytics,
});
expect(user.purchased.plan.customerId).to.not.exist;
expect(user.purchased.plan.consecutive.gemCapExtra).to.equal(0);
expect(user.purchased.plan.consecutive.gemCapExtra).to.equal(20);
expect(user.purchased.plan.consecutive.count).to.equal(0);
expect(user.purchased.plan.consecutive.offset).to.equal(0);
});
describe('for a 1-month recurring subscription', async () => {
@@ -229,7 +227,7 @@ describe('cron', async () => {
user1.purchased.plan.planId = 'basic';
user1.purchased.plan.consecutive.count = 0;
user1.purchased.plan.perkMonthCount = 0;
user1.purchased.plan.consecutive.trinkets = 0;
user1.purchased.plan.consecutive.trinkets = 1;
user1.purchased.plan.consecutive.gemCapExtra = 0;
});
@@ -256,7 +254,7 @@ describe('cron', async () => {
user: user1, tasksByType, daysMissed, analytics,
});
expect(user1.purchased.plan.consecutive.count).to.equal(10);
expect(user1.purchased.plan.consecutive.trinkets).to.equal(10);
expect(user1.purchased.plan.consecutive.trinkets).to.equal(11);
expect(user1.purchased.plan.consecutive.gemCapExtra).to.equal(20);
});
});
@@ -281,7 +279,7 @@ describe('cron', async () => {
user3.purchased.plan.perkMonthCount = 0;
user3.purchased.plan.consecutive.count = 0;
user3.purchased.plan.consecutive.trinkets = 1;
user3.purchased.plan.consecutive.gemCapExtra = 5;
user3.purchased.plan.consecutive.gemCapExtra = 0;
});
it('increments consecutive benefits', async () => {
@@ -304,7 +302,7 @@ describe('cron', async () => {
user: user3, tasksByType, daysMissed, analytics,
});
expect(user3.purchased.plan.consecutive.count).to.equal(10);
expect(user3.purchased.plan.consecutive.trinkets).to.equal(10);
expect(user3.purchased.plan.consecutive.trinkets).to.equal(11);
expect(user3.purchased.plan.consecutive.gemCapExtra).to.equal(20);
});
});
@@ -328,8 +326,8 @@ describe('cron', async () => {
user6.purchased.plan.planId = 'google_6mo';
user6.purchased.plan.perkMonthCount = 0;
user6.purchased.plan.consecutive.count = 0;
user6.purchased.plan.consecutive.trinkets = 2;
user6.purchased.plan.consecutive.gemCapExtra = 10;
user6.purchased.plan.consecutive.trinkets = 1;
user6.purchased.plan.consecutive.gemCapExtra = 0;
});
it('increments benefits', async () => {
@@ -362,8 +360,8 @@ describe('cron', async () => {
user12.purchased.plan.dateUpdated = moment().toDate();
user12.purchased.plan.planId = 'basic_12mo';
user12.purchased.plan.consecutive.count = 0;
user12.purchased.plan.consecutive.trinkets = 4;
user12.purchased.plan.consecutive.gemCapExtra = 20;
user12.purchased.plan.consecutive.trinkets = 1;
user12.purchased.plan.consecutive.gemCapExtra = 26;
it('increments consecutive benefits the month after the second paid period has started', async () => {
clock = sinon.useFakeTimers(moment().utcOffset(0).startOf('month').add(1, 'months')
@@ -373,7 +371,7 @@ describe('cron', async () => {
user: user12, tasksByType, daysMissed, analytics,
});
expect(user12.purchased.plan.consecutive.count).to.equal(1);
expect(user12.purchased.plan.consecutive.trinkets).to.equal(13);
expect(user12.purchased.plan.consecutive.trinkets).to.equal(2);
expect(user12.purchased.plan.consecutive.gemCapExtra).to.equal(26);
});
@@ -385,8 +383,8 @@ describe('cron', async () => {
user: user12, tasksByType, daysMissed, analytics,
});
expect(user12.purchased.plan.consecutive.count).to.equal(10);
expect(user12.purchased.plan.consecutive.trinkets).to.equal(22);
expect(user12.purchased.plan.consecutive.gemCapExtra).to.equal(65);
expect(user12.purchased.plan.consecutive.trinkets).to.equal(11);
expect(user12.purchased.plan.consecutive.gemCapExtra).to.equal(26);
});
});
@@ -410,7 +408,7 @@ describe('cron', async () => {
user3g.purchased.plan.planId = null;
user3g.purchased.plan.consecutive.count = 0;
user3g.purchased.plan.consecutive.trinkets = 1;
user3g.purchased.plan.consecutive.gemCapExtra = 5;
user3g.purchased.plan.consecutive.gemCapExtra = 0;
it('increments benefits', async () => {
clock = sinon.useFakeTimers(moment().utcOffset(0).startOf('month').add(1, 'months')
@@ -419,10 +417,9 @@ describe('cron', async () => {
await cron({
user: user3g, tasksByType, daysMissed, analytics,
});
expect(user3g.purchased.plan.consecutive.count).to.equal(3);
expect(user3g.purchased.plan.consecutive.offset).to.equal(0);
expect(user3g.purchased.plan.consecutive.trinkets).to.equal(1);
expect(user3g.purchased.plan.consecutive.gemCapExtra).to.equal(5);
expect(user3g.purchased.plan.consecutive.count).to.equal(1);
expect(user3g.purchased.plan.consecutive.trinkets).to.equal(2);
expect(user3g.purchased.plan.consecutive.gemCapExtra).to.equal(2);
});
it('does not increment consecutive benefits in the month after the gift subscription has ended', async () => {
@@ -434,9 +431,8 @@ describe('cron', async () => {
});
// subscription has been erased by now
expect(user3g.purchased.plan.consecutive.count).to.equal(0);
expect(user3g.purchased.plan.consecutive.offset).to.equal(0);
expect(user3g.purchased.plan.consecutive.trinkets).to.equal(1);
expect(user3g.purchased.plan.consecutive.gemCapExtra).to.equal(0); // erased
expect(user3g.purchased.plan.consecutive.trinkets).to.equal(2);
expect(user3g.purchased.plan.consecutive.gemCapExtra).to.equal(2);
});
});
});
+21 -16
View File
@@ -13,7 +13,7 @@ import {
import * as worldState from '../../../../../website/server/libs/worldState';
import { TransactionModel } from '../../../../../website/server/models/transaction';
describe('payments/index', () => {
describe.only('payments/index', () => {
let user;
let group;
let data;
@@ -108,10 +108,6 @@ describe('payments/index', () => {
});
it('add a transaction entry to the recipient', async () => {
recipient.purchased.plan = plan;
expect(recipient.purchased.plan.extraMonths).to.eql(0);
await api.createSubscription(data);
expect(recipient.purchased.plan.extraMonths).to.eql(3);
@@ -199,13 +195,13 @@ describe('payments/index', () => {
it('gives user 1 hourglass if they have no active subscription', async () => {
await api.createSubscription(data);
expect(recipient.purchased.plan.trinket).to.eql(1);
expect(recipient.purchased.plan.consecutive.trinkets).to.eql(1);
});
it('does not giec any hourglasses if they have an active subscription', async () => {
it('does not give any hourglasses if they have an active subscription', async () => {
recipient.purchased.plan = plan;
await api.createSubscription(data);
expect(recipient.purchased.plan.trinket).to.eql(plan.trinket);
expect(recipient.purchased.plan.consecutive.trinkets).to.eql(plan.consecutive.trinkets);
});
it('sets plan.dateUpdated if it did exist but the user has cancelled', async () => {
@@ -666,6 +662,15 @@ describe('payments/index', () => {
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
});
it('adds 1 plan.consecutive.trinkets for 12 month block if they had promo', async () => {
user.purchased.plan.hourGlassPromoReceived = new Date();
data.sub.key = 'basic_12mo';
await api.createSubscription(data);
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
});
it('adds 12 plan.consecutive.trinkets for 12 month block', async () => {
data.sub.key = 'basic_12mo';
@@ -944,7 +949,7 @@ describe('payments/index', () => {
expect(user.purchased.plan.consecutive.trinkets).to.eql(6);
});
it('Adds 4 to plan.consecutive.trinkets when upgrading from basic_3mo to basic_12mo', async () => {
it('Adds 11 to plan.consecutive.trinkets when upgrading from basic_3mo to basic_12mo', async () => {
expect(user.purchased.plan.planId).to.not.exist;
await api.createSubscription(data);
@@ -958,17 +963,17 @@ describe('payments/index', () => {
clock = sinon.useFakeTimers(new Date('2022-03-03'));
await api.createSubscription(data);
expect(user.purchased.plan.planId).to.eql('basic_12mo');
expect(user.purchased.plan.consecutive.trinkets).to.eql(5);
expect(user.purchased.plan.consecutive.trinkets).to.eql(12);
});
it('Adds 2 to plan.consecutive.trinkets from basic_earned to basic_6mo after initial cycle', async () => {
it('Adds 11 to plan.consecutive.trinkets from basic_earned to basic_6mo after initial cycle', async () => {
data.sub.key = 'basic_earned';
expect(user.purchased.plan.planId).to.not.exist;
await api.createSubscription(data);
expect(user.purchased.plan.planId).to.eql('basic_earned');
expect(user.purchased.plan.consecutive.trinkets).to.eql(0);
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
data.sub.key = 'basic_6mo';
data.updatedFrom.key = 'basic_earned';
@@ -976,17 +981,17 @@ describe('payments/index', () => {
clock = sinon.useFakeTimers(new Date('2022-05-28'));
await api.createSubscription(data);
expect(user.purchased.plan.planId).to.eql('basic_6mo');
expect(user.purchased.plan.consecutive.trinkets).to.eql(2);
expect(user.purchased.plan.consecutive.trinkets).to.eql(12);
});
it('Adds 4 to plan.consecutive.trinkets when upgrading from basic_6mo to basic_12mo after initial cycle', async () => {
it('Adds 11 to plan.consecutive.trinkets when upgrading from basic_6mo to basic_12mo after initial cycle', async () => {
data.sub.key = 'basic_6mo';
expect(user.purchased.plan.planId).to.not.exist;
await api.createSubscription(data);
expect(user.purchased.plan.planId).to.eql('basic_6mo');
expect(user.purchased.plan.consecutive.trinkets).to.eql(2);
expect(user.purchased.plan.consecutive.trinkets).to.eql(1);
data.sub.key = 'basic_12mo';
data.updatedFrom.key = 'basic_6mo';
@@ -994,7 +999,7 @@ describe('payments/index', () => {
clock = sinon.useFakeTimers(new Date('2023-05-28'));
await api.createSubscription(data);
expect(user.purchased.plan.planId).to.eql('basic_12mo');
expect(user.purchased.plan.consecutive.trinkets).to.eql(6);
expect(user.purchased.plan.consecutive.trinkets).to.eql(12);
});
it('Adds 4 to plan.consecutive.trinkets when upgrading from basic_3mo to basic_12mo after initial cycle', async () => {