diff --git a/test/api/unit/libs/payments/payments.test.js b/test/api/unit/libs/payments/payments.test.js index 10759094f0..f4a0c3e509 100644 --- a/test/api/unit/libs/payments/payments.test.js +++ b/test/api/unit/libs/payments/payments.test.js @@ -65,7 +65,6 @@ describe('payments/index', () => { mysteryItems: [], consecutive: { trinkets: 0, - offset: 0, gemCapExtra: 0, }, }; @@ -179,13 +178,13 @@ describe('payments/index', () => { expect(recipient.purchased.plan.consecutive.gemCapExtra).to.eql(10); }); - it('sets gemCapExtra to max if they receive a 3 month sub', async () => { + it('sets gemCapExtra to 0 if they receive a 3 month sub', async () => { data.gift.subscription.key = 'basic_3mo'; data.gift.subscription.months = 3; await api.createSubscription(data); - expect(recipient.purchased.plan.gemCapExtra).to.eql(0); + expect(recipient.purchased.plan.consecutive.gemCapExtra).to.eql(0); }); it('sets gemCapExtra to max if they receive a 12 month sub', async () => { @@ -1183,6 +1182,16 @@ describe('payments/index', () => { expect(user.purchased.plan.consecutive.gemCapExtra).to.eql(12); }); + it('initializes gemCapExtra', async () => { + await api.cancelSubscription(data); + expect(user.purchased.plan.consecutive.gemCapExtra).to.eql(0); + }); + + it('initializes hourglasses', async () => { + await api.cancelSubscription(data); + expect(user.purchased.plan.consecutive.trinkets).to.eql(0); + }); + it('does not reset owned hourglasses', async () => { user.purchased.plan.consecutive.trinkets = 12; diff --git a/website/server/libs/payments/subscriptions.js b/website/server/libs/payments/subscriptions.js index a6c5c3302b..afbf2b9226 100644 --- a/website/server/libs/payments/subscriptions.js +++ b/website/server/libs/payments/subscriptions.js @@ -200,18 +200,11 @@ async function prepareSubscriptionValues (data) { owner: data.user._id, }); - // allow non-override if a plan was previously used - if (!plan.gemsBought) { - plan.gemsBought = 0; - } - - if (!plan.dateCreated) { - plan.dateCreated = today; - } - - if (!plan.mysteryItems) { - plan.mysteryItems = []; - } + _.defaults(plan, { + gemsBought: 0, + dateCreated: today, + mysteryItems: [], + }); if (data.subscriptionId) { plan.subscriptionId = data.subscriptionId; @@ -261,7 +254,6 @@ async function createSubscription (data) { if (months > 0) { if (block.months === 12) { recipient.purchased.plan.consecutive.gemCapExtra = 26; - recipient.markModified('purchased.plan.consecutive'); } if (block.months === 12 && autoRenews && !recipient.purchased.plan.hourglassPromoReceived) {