mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
fix: Update notifications lib to make it testable
closes #7770 closes #7782
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import * as sender from '../../../../../website/server/libs/email';
|
||||
import * as api from '../../../../../website/server/libs/payments';
|
||||
import analytics from '../../../../../website/server/libs/analyticsService';
|
||||
import notifications from '../../../../../website/server/libs/pushNotifications';
|
||||
import { model as User } from '../../../../../website/server/models/user';
|
||||
import moment from 'moment';
|
||||
|
||||
@@ -15,6 +16,7 @@ describe('payments/index', () => {
|
||||
sandbox.stub(user, 'sendMessage');
|
||||
sandbox.stub(analytics, 'trackPurchase');
|
||||
sandbox.stub(analytics, 'track');
|
||||
sandbox.stub(notifications, 'sendNotification');
|
||||
|
||||
data = {
|
||||
user,
|
||||
@@ -149,15 +151,15 @@ describe('payments/index', () => {
|
||||
it('sends an email about the gift', async () => {
|
||||
await api.createSubscription(data);
|
||||
|
||||
expect(sender.sendTxn).to.be.calledOnce;
|
||||
expect(sender.sendTxn).to.be.calledWith(recipient, 'gifted-subscription', [
|
||||
{name: 'GIFTER', content: 'sender'},
|
||||
{name: 'X_MONTHS_SUBSCRIPTION', content: 3},
|
||||
]);
|
||||
});
|
||||
|
||||
xit('sends a push notification about the gift', async () => {
|
||||
// TODO: the push notification library needs to be refactored to export an object with properties to better stub it
|
||||
it('sends a push notification about the gift', async () => {
|
||||
await api.createSubscription(data);
|
||||
expect(notifications.sendNotification).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('tracks subscription purchase as gift', async () => {
|
||||
@@ -518,8 +520,9 @@ describe('payments/index', () => {
|
||||
expect(user.sendMessage).to.be.calledWith(recipient, '\`Hello recipient, sender has sent you 4 gems!\`');
|
||||
});
|
||||
|
||||
xit('sends a push notification if user did not gift to self', async () => {
|
||||
// TODO: the push notification library needs to be refactored to export an object with properties to better stub it
|
||||
it('sends a push notification if user did not gift to self', async () => {
|
||||
await api.buyGems(data);
|
||||
expect(notifications.sendNotification).to.be.calledOnce;
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user