Set isDue and NextDue during sleep (#8769)

This commit is contained in:
Keith Holliday
2017-05-30 14:57:38 -06:00
committed by Sabe Jones
parent 46ed1813c6
commit 0e069e78d5
2 changed files with 30 additions and 8 deletions

View File

@@ -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', () => {

View File

@@ -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) {