From 4ed10825588eb2d65489d0f28ec3fa501ff71775 Mon Sep 17 00:00:00 2001 From: Derek Kim Date: Tue, 23 Oct 2018 06:47:15 -0500 Subject: [PATCH] fix for #10496: Newly subscribed accounts receive erroneous notification that they have Mystery Items (#10759) * fix Newly subscribed accounts receive erroneous notification that they have Mystery Items * Added unit test for #10496 * Restored a previous unit test --- test/api/unit/libs/payments/payments.test.js | 13 +++++++++++++ website/server/libs/payments/subscriptions.js | 5 +++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/test/api/unit/libs/payments/payments.test.js b/test/api/unit/libs/payments/payments.test.js index c63bd89823..82fb3dabad 100644 --- a/test/api/unit/libs/payments/payments.test.js +++ b/test/api/unit/libs/payments/payments.test.js @@ -446,6 +446,19 @@ describe('payments/index', () => { fakeClock.restore(); }); + it('does not add a notification for mystery items if none was awarded', async () => { + const noMysteryItemTimeframe = 1462183920000; // May 2nd 2016 + let fakeClock = sinon.useFakeTimers(noMysteryItemTimeframe); + data = { paymentMethod: 'PaymentMethod', user, sub: { key: 'basic_3mo' } }; + + await api.createSubscription(data); + + expect(user.purchased.plan.mysteryItems).to.have.a.lengthOf(0); + expect(user.notifications.find(n => n.type === 'NEW_MYSTERY_ITEMS')).to.be.undefined; + + fakeClock.restore(); + }); + it('does not award mystery item when user already owns the item', async () => { let mayMysteryItemTimeframe = 1464725113000; // May 31st 2016 let fakeClock = sinon.useFakeTimers(mayMysteryItemTimeframe); diff --git a/website/server/libs/payments/subscriptions.js b/website/server/libs/payments/subscriptions.js index 82e9a30d70..9757d1696c 100644 --- a/website/server/libs/payments/subscriptions.js +++ b/website/server/libs/payments/subscriptions.js @@ -36,8 +36,9 @@ function revealMysteryItems (user) { pushedItems.push(item.key); } }); - - user.addNotification('NEW_MYSTERY_ITEMS', { items: pushedItems }); + if (pushedItems.length > 0) { + user.addNotification('NEW_MYSTERY_ITEMS', { items: pushedItems }); + } } // @TODO: Abstract to payment helper