From 446122d7b868d2ecd65f8dc27505e06d3582c3b8 Mon Sep 17 00:00:00 2001 From: Sabe Jones Date: Tue, 5 May 2020 11:52:44 -0500 Subject: [PATCH] To-Do cron task decay fixes (#12072) * fix(tasks): improve some cron behaviors Fixes #6488 Fixes #8590 * add test Co-authored-by: Matteo Pagliazzi --- test/api/unit/libs/cron.test.js | 22 +++++++++++++++------- website/common/script/ops/scoreTask.js | 2 +- website/server/libs/cron.js | 5 +++-- 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/test/api/unit/libs/cron.test.js b/test/api/unit/libs/cron.test.js index eb97c47c42..1544a8c373 100644 --- a/test/api/unit/libs/cron.test.js +++ b/test/api/unit/libs/cron.test.js @@ -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', diff --git a/website/common/script/ops/scoreTask.js b/website/common/script/ops/scoreTask.js index d13d566112..101e2bcf39 100644 --- a/website/common/script/ops/scoreTask.js +++ b/website/common/script/ops/scoreTask.js @@ -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); } } diff --git a/website/server/libs/cron.js b/website/server/libs/cron.js index cec80becaa..482f504132 100644 --- a/website/server/libs/cron.js +++ b/website/server/libs/cron.js @@ -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,