Added remove when previous login incentive notifications exist

This commit is contained in:
Keith Holliday
2016-11-28 21:19:53 -06:00
parent a48b8f0e34
commit f4cf906127
2 changed files with 21 additions and 1 deletions

View File

@@ -6,7 +6,7 @@ import requireAgain from 'require-again';
import { recoverCron, cron } from '../../../../../website/server/libs/cron';
import { model as User } from '../../../../../website/server/models/user';
import * as Tasks from '../../../../../website/server/models/task';
import { clone } from 'lodash';
import { clone, filter } from 'lodash';
import common from '../../../../../website/common';
import analytics from '../../../../../website/server/libs/analyticsService';
@@ -780,6 +780,18 @@ describe('cron', () => {
expect(user.notifications[0].type).to.eql('LOGIN_INCENTIVE');
});
it('replaces previous notifications', () => {
cron({user, tasksByType, daysMissed, analytics});
cron({user, tasksByType, daysMissed, analytics});
cron({user, tasksByType, daysMissed, analytics});
let filteredNotifications = filter(user.notifications, function filterNotifications (notification) {
return notification.type === 'LOGIN_INCENTIVE';
});
expect(filteredNotifications.length).to.equal(1);
});
it('increments loginIncentives by 1 even if days are skipped in between', () => {
daysMissed = 3;
cron({user, tasksByType, daysMissed, analytics});

View File

@@ -130,6 +130,14 @@ function trackCronAnalytics (analytics, user, _progress, options) {
function awardLoginIncentives (user) {
if (user.loginIncentives > 50) return;
//Remove old noitification if it exists
user.notifications
.toObject()
.find((notif, index) => {
if (notif.type === 'LOGIN_INCENTIVE') user.notifications.splice(index, 1);
});
let notificationData = {};
notificationData.message = i18n.t('checkinEarned', user.preferences.language);