mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-08-03 04:29:40 +00:00
Merge pull request #8242 from TheHollidayInn/login-incentives-remove-multiple-notifications
Login incentives remove multiple notifications
This commit is contained in:
commit
395dafa127
2 changed files with 23 additions and 5 deletions
|
|
@ -704,14 +704,14 @@ describe('cron', () => {
|
|||
|
||||
cron({user, tasksByType, daysMissed, analytics});
|
||||
|
||||
expect(user.notifications.length - notifsBefore2).to.equal(1);
|
||||
expect(user.notifications[1].type).to.not.equal('CRON');
|
||||
expect(user.notifications[2].type).to.equal('CRON');
|
||||
expect(user.notifications[2].data).to.eql({
|
||||
expect(user.notifications.length - notifsBefore2).to.equal(0);
|
||||
expect(user.notifications[0].type).to.not.equal('CRON');
|
||||
expect(user.notifications[1].type).to.equal('CRON');
|
||||
expect(user.notifications[1].data).to.eql({
|
||||
hp: user.stats.hp - hpBefore2 - (hpBefore2 - hpBefore1),
|
||||
mp: user.stats.mp - mpBefore2 - (mpBefore2 - mpBefore1),
|
||||
});
|
||||
expect(user.notifications[1].type).to.not.equal('CRON');
|
||||
expect(user.notifications[0].type).to.not.equal('CRON');
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -780,6 +780,16 @@ 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 = user.notifications.filter(n => n.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 notifications if they 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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue