From 6084ea2017bcaac3a1f5f4577da05a88af6eb268 Mon Sep 17 00:00:00 2001 From: Sabe Jones Date: Wed, 1 Jun 2016 15:34:57 -0500 Subject: [PATCH] Fix mystery set award to new subscribers (#7586) * fix(mystery): flip da sign * test(subscription): check mystery box --- test/api/v3/unit/libs/payments.test.js | 15 +++++++++++++++ website/server/libs/api-v3/payments.js | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/test/api/v3/unit/libs/payments.test.js b/test/api/v3/unit/libs/payments.test.js index 30fe78b643..c5553c3e77 100644 --- a/test/api/v3/unit/libs/payments.test.js +++ b/test/api/v3/unit/libs/payments.test.js @@ -9,8 +9,17 @@ describe('payments/index', () => { let user; describe('#createSubscription', () => { + const MYSTERY_AWARD_COUNT = 2; + const MYSTERY_AWARD_UNIX_TIME = 1464725113000; + let fakeClock; + beforeEach(async () => { user = new User(); + fakeClock = sinon.useFakeTimers(MYSTERY_AWARD_UNIX_TIME); + }); + + afterEach(() => { + fakeClock.restore(); }); it('succeeds', async () => { @@ -19,6 +28,12 @@ describe('payments/index', () => { await api.createSubscription(data); expect(user.purchased.plan.planId).to.exist; }); + + it('awards mystery items', async () => { + data = { user, sub: { key: 'basic_3mo' } }; + await api.createSubscription(data); + expect(user.purchased.plan.mysteryItems.length).to.eql(MYSTERY_AWARD_COUNT); + }); }); describe('#cancelSubscription', () => { diff --git a/website/server/libs/api-v3/payments.js b/website/server/libs/api-v3/payments.js index 144b4fe568..ae825abff3 100644 --- a/website/server/libs/api-v3/payments.js +++ b/website/server/libs/api-v3/payments.js @@ -20,7 +20,7 @@ function revealMysteryItems (user) { moment().isAfter(shared.content.mystery[item.mystery].start) && moment().isBefore(shared.content.mystery[item.mystery].end) && !user.items.gear.owned[item.key] && - user.purchased.plan.mysteryItems.indexOf(item.key) !== -1 + user.purchased.plan.mysteryItems.indexOf(item.key) === -1 ) { user.purchased.plan.mysteryItems.push(item.key); }