Skip to content

Commit

Permalink
Fix hourglass logic for upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
phillipthelen committed Sep 26, 2024
1 parent d5ed7f6 commit 959d6ee
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
40 changes: 20 additions & 20 deletions test/api/unit/libs/payments/payments.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ describe('payments/index', () => {

await api.createSubscription(data);

expect(user.purchased.plan.consecutive.trinkets).to.eql(12);
expect(user.purchased.plan.consecutive.trinkets).to.eql(13);
});

context('Upgrades subscription', () => {
Expand All @@ -703,7 +703,7 @@ describe('payments/index', () => {
expect(user.purchased.plan.consecutive.gemCapExtra).to.eql(26);
});

it('Adds 11 to plan.consecutive.trinkets when upgrading from basic_6mo to basic_12mo', async () => {
it('Adds 12 to plan.consecutive.trinkets when upgrading from basic_6mo to basic_12mo', async () => {
data.sub.key = 'basic_6mo';
expect(user.purchased.plan.planId).to.not.exist;

Expand All @@ -716,10 +716,10 @@ describe('payments/index', () => {
data.updatedFrom.key = 'basic_6mo';
await api.createSubscription(data);
expect(user.purchased.plan.planId).to.eql('basic_12mo');
expect(user.purchased.plan.consecutive.trinkets).to.eql(12);
expect(user.purchased.plan.consecutive.trinkets).to.eql(13);
});

it('Adds 11 to plan.consecutive.trinkets when upgrading from basic_3mo to basic_12mo', async () => {
it('Adds 12 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);
Expand All @@ -731,7 +731,7 @@ describe('payments/index', () => {
data.updatedFrom.key = 'basic_3mo';
await api.createSubscription(data);
expect(user.purchased.plan.planId).to.eql('basic_12mo');
expect(user.purchased.plan.consecutive.trinkets).to.eql(12);
expect(user.purchased.plan.consecutive.trinkets).to.eql(13);
});
});

Expand Down Expand Up @@ -811,7 +811,7 @@ describe('payments/index', () => {
expect(user.purchased.plan.consecutive.gemCapExtra).to.eql(26);
});

it('Adds 11 to plan.consecutive.trinkets when upgrading from basic_3mo to basic_12mo', async () => {
it('Adds 12 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);
Expand All @@ -825,10 +825,10 @@ describe('payments/index', () => {
clock = sinon.useFakeTimers(new Date('2022-01-31'));
await api.createSubscription(data);
expect(user.purchased.plan.planId).to.eql('basic_12mo');
expect(user.purchased.plan.consecutive.trinkets).to.eql(12);
expect(user.purchased.plan.consecutive.trinkets).to.eql(13);
});

it('Adds 11 to plan.consecutive.trinkets when upgrading from basic_6mo to basic_12mo', async () => {
it('Adds 12 to plan.consecutive.trinkets when upgrading from basic_6mo to basic_12mo', async () => {
data.sub.key = 'basic_6mo';
expect(user.purchased.plan.planId).to.not.exist;

Expand All @@ -843,10 +843,10 @@ describe('payments/index', () => {
clock = sinon.useFakeTimers(new Date('2022-01-28'));
await api.createSubscription(data);
expect(user.purchased.plan.planId).to.eql('basic_12mo');
expect(user.purchased.plan.consecutive.trinkets).to.eql(12);
expect(user.purchased.plan.consecutive.trinkets).to.eql(13);
});

it('Adds 11 to plan.consecutive.trinkets when upgrading from basic_6mo to basic_12mo after initial cycle', async () => {
it('2 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;

Expand All @@ -861,10 +861,10 @@ describe('payments/index', () => {
clock = sinon.useFakeTimers(new Date('2022-08-28'));
await api.createSubscription(data);
expect(user.purchased.plan.planId).to.eql('basic_12mo');
expect(user.purchased.plan.consecutive.trinkets).to.eql(12);
expect(user.purchased.plan.consecutive.trinkets).to.eql(13);
});

it('Adds 11 to plan.consecutive.trinkets when upgrading from basic_3mo to basic_12mo after initial cycle', async () => {
it('Adds 12 to plan.consecutive.trinkets when upgrading from basic_3mo to basic_12mo after initial cycle', async () => {
expect(user.purchased.plan.planId).to.not.exist;

await api.createSubscription(data);
Expand All @@ -878,7 +878,7 @@ describe('payments/index', () => {
clock = sinon.useFakeTimers(new Date('2022-07-31'));
await api.createSubscription(data);
expect(user.purchased.plan.planId).to.eql('basic_12mo');
expect(user.purchased.plan.consecutive.trinkets).to.eql(12);
expect(user.purchased.plan.consecutive.trinkets).to.eql(13);
});
});
context('Upgrades within second half of subscription', () => {
Expand Down Expand Up @@ -917,7 +917,7 @@ describe('payments/index', () => {
expect(user.purchased.plan.consecutive.gemCapExtra).to.eql(26);
});

it('Adds 1 to plan.consecutive.trinkets from basic_earned to basic_6mo', async () => {
it('Adds 0 to plan.consecutive.trinkets from basic_earned to basic_6mo', async () => {
data.sub.key = 'basic_earned';
expect(user.purchased.plan.planId).to.not.exist;

Expand All @@ -932,7 +932,7 @@ describe('payments/index', () => {
clock = sinon.useFakeTimers(new Date('2022-01-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(1);
});

it('Adds 12 to plan.consecutive.trinkets when upgrading from basic_6mo to basic_12mo', async () => {
Expand All @@ -953,7 +953,7 @@ describe('payments/index', () => {
expect(user.purchased.plan.consecutive.trinkets).to.eql(13);
});

it('Adds 11 to plan.consecutive.trinkets when upgrading from basic_3mo to basic_12mo', async () => {
it('Adds 12 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);
Expand All @@ -970,7 +970,7 @@ describe('payments/index', () => {
expect(user.purchased.plan.consecutive.trinkets).to.eql(13);
});

it('Adds 1 to plan.consecutive.trinkets from basic_earned to basic_6mo after initial cycle', async () => {
it('Adds 0 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;

Expand All @@ -985,7 +985,7 @@ 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(1);
});

it('Adds 12 to plan.consecutive.trinkets when upgrading from basic_6mo to basic_12mo after initial cycle', async () => {
Expand Down Expand Up @@ -1052,12 +1052,12 @@ describe('payments/index', () => {
await api.createSubscription(data);

expect(user.purchased.plan.planId).to.eql('basic_12mo');
expect(user.purchased.plan.consecutive.trinkets).to.eql(12);
expect(user.purchased.plan.consecutive.trinkets).to.eql(13);

data.sub.key = 'basic_3mo';
data.updatedFrom = { key: 'basic_12mo' };
await api.createSubscription(data);
expect(user.purchased.plan.consecutive.trinkets).to.eql(12);
expect(user.purchased.plan.consecutive.trinkets).to.eql(13);
});
});
});
Expand Down
4 changes: 2 additions & 2 deletions website/server/libs/payments/subscriptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,13 +258,13 @@ async function createSubscription (data) {

if (block.months === 12 && autoRenews && !recipient.purchased.plan.hourglassPromoReceived) {
recipient.purchased.plan.hourglassPromoReceived = new Date();
if (months !== block.months) {
if (!isNewSubscription) {
// user is upgrading their sub. Already got one hourglass when subscribing
await plan.updateHourglasses(recipient._id, 12, '12_month_subscription');
} else {
await plan.updateHourglasses(recipient._id, 13, '12_month_subscription');
}
} else if (!data.gift || (data.gift && isNewSubscription)) {
} else if (isNewSubscription) {
await plan.updateHourglasses(recipient._id, 1, 'subscribed');
}
}
Expand Down

0 comments on commit 959d6ee

Please sign in to comment.