mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-04-14 11:36:45 +00:00
To-Do cron task decay fixes (#12072)
* fix(tasks): improve some cron behaviors Fixes #6488 Fixes #8590 * add test Co-authored-by: Matteo Pagliazzi <matteopagliazzi@gmail.com>
This commit is contained in:
parent
93335352ec
commit
446122d7b8
3 changed files with 19 additions and 10 deletions
|
|
@ -879,6 +879,11 @@ describe('cron', () => {
|
|||
tasksByType.todos.push(task);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
tasksByType.todos = [];
|
||||
user.tasksOrder.todos = [];
|
||||
});
|
||||
|
||||
it('should make uncompleted todos redder', () => {
|
||||
const valueBefore = tasksByType.todos[0].value;
|
||||
cron({
|
||||
|
|
@ -887,6 +892,15 @@ describe('cron', () => {
|
|||
expect(tasksByType.todos[0].value).to.be.lessThan(valueBefore);
|
||||
});
|
||||
|
||||
it('should not make completed todos redder', () => {
|
||||
tasksByType.todos[0].completed = true;
|
||||
const valueBefore = tasksByType.todos[0].value;
|
||||
cron({
|
||||
user, tasksByType, daysMissed, analytics,
|
||||
});
|
||||
expect(tasksByType.todos[0].value).to.equal(valueBefore);
|
||||
});
|
||||
|
||||
it('should add history of completed todos to user history', () => {
|
||||
tasksByType.todos[0].completed = true;
|
||||
|
||||
|
|
@ -898,17 +912,13 @@ describe('cron', () => {
|
|||
});
|
||||
|
||||
it('should remove completed todos from users taskOrder list', () => {
|
||||
tasksByType.todos = [];
|
||||
user.tasksOrder.todos = [];
|
||||
const todo = {
|
||||
text: 'test todo',
|
||||
type: 'todo',
|
||||
value: 0,
|
||||
};
|
||||
|
||||
let task = new Tasks.todo(Tasks.Task.sanitize(todo)); // eslint-disable-line new-cap
|
||||
tasksByType.todos.push(task);
|
||||
task = new Tasks.todo(Tasks.Task.sanitize(todo)); // eslint-disable-line new-cap
|
||||
const task = new Tasks.todo(Tasks.Task.sanitize(todo)); // eslint-disable-line new-cap
|
||||
tasksByType.todos.push(task);
|
||||
tasksByType.todos[0].completed = true;
|
||||
|
||||
|
|
@ -930,8 +940,6 @@ describe('cron', () => {
|
|||
});
|
||||
|
||||
it('should preserve todos order in task list', () => {
|
||||
tasksByType.todos = [];
|
||||
user.tasksOrder.todos = [];
|
||||
const todo = {
|
||||
text: 'test todo',
|
||||
type: 'todo',
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ function _calculateDelta (task, direction, cron) {
|
|||
}
|
||||
|
||||
// If To-Do, point-match the TD per checklist item completed
|
||||
if (task.type === 'todo') {
|
||||
if (task.type === 'todo' && !cron) {
|
||||
nextDelta *= 1 + reduce(task.checklist, (m, i) => m + (i.completed ? 1 : 0), 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -326,8 +326,9 @@ export function cron (options = {}) {
|
|||
// make uncompleted To-Dos redder (further incentive to complete them)
|
||||
tasksByType.todos.forEach(task => {
|
||||
if (
|
||||
task.group.assignedDate
|
||||
&& moment(task.group.assignedDate).isAfter(user.auth.timestamps.updated)
|
||||
task.completed
|
||||
|| (task.group.assignedDate
|
||||
&& moment(task.group.assignedDate).isAfter(user.auth.timestamps.updated))
|
||||
) return;
|
||||
scoreTask({
|
||||
task,
|
||||
|
|
|
|||
Loading…
Reference in a new issue