diff --git a/test/api/v3/unit/libs/cron.test.js b/test/api/v3/unit/libs/cron.test.js index 0cf1845c69..6382b85a3d 100644 --- a/test/api/v3/unit/libs/cron.test.js +++ b/test/api/v3/unit/libs/cron.test.js @@ -313,6 +313,24 @@ describe('cron', () => { expect(tasksByType.dailys[0].completed).to.be.false; expect(user.stats.hp).to.equal(healthBefore); }); + + it('sets isDue for daily', () => { + let daily = { + text: 'test daily', + type: 'daily', + frequency: 'daily', + everyX: 5, + startDate: new Date(), + }; + + let task = new Tasks.daily(Tasks.Task.sanitize(daily)); // eslint-disable-line new-cap + tasksByType.dailys.push(task); + tasksByType.dailys[0].completed = true; + + cron({user, tasksByType, daysMissed, analytics}); + + expect(tasksByType.dailys[0].isDue).to.be.exist; + }); }); describe('todos', () => { diff --git a/website/server/libs/cron.js b/website/server/libs/cron.js index 2cc319e824..a7a64fae3d 100644 --- a/website/server/libs/cron.js +++ b/website/server/libs/cron.js @@ -16,6 +16,16 @@ const i18n = common.i18n; const loginIncentives = common.content.loginIncentives; // const maxPMs = 200; +function setIsDueNextDue (task, user, now) { + let optionsForShouldDo = cloneDeep(user.preferences.toObject()); + task.isDue = common.shouldDo(now, task, optionsForShouldDo); + optionsForShouldDo.nextDue = true; + let nextDue = common.shouldDo(now, task, optionsForShouldDo); + if (nextDue && nextDue.length > 0) { + task.nextDue = nextDue; + } +} + export async function recoverCron (status, locals) { let {user} = locals; @@ -108,6 +118,7 @@ function performSleepTasks (user, tasksByType, now) { } daily.completed = false; + setIsDueNextDue(daily, user, now); }); } @@ -316,14 +327,7 @@ export function cron (options = {}) { }); task.completed = false; - let optionsForShouldDo = cloneDeep(user.preferences.toObject()); - task.isDue = common.shouldDo(now, task, optionsForShouldDo); - optionsForShouldDo.nextDue = true; - let nextDue = common.shouldDo(now, task, optionsForShouldDo); - - if (nextDue && nextDue.length > 0) { - task.nextDue = nextDue; - } + setIsDueNextDue(task, user, now); if (completed || scheduleMisses > 0) { if (task.checklist) {