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
This commit is contained in:
Derek Kim
2018-10-23 06:47:15 -05:00
committed by Matteo Pagliazzi
parent 00717eda76
commit 4ed1082558
2 changed files with 16 additions and 2 deletions

View File

@@ -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);

View File

@@ -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