mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
Set isDue and NextDue during sleep (#8769)
This commit is contained in:
committed by
Sabe Jones
parent
46ed1813c6
commit
0e069e78d5
@@ -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', () => {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user