mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Added remove when previous login incentive notifications exist
This commit is contained in:
@@ -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});
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user