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:
Sabe Jones 2020-05-05 11:52:44 -05:00 committed by GitHub
parent 93335352ec
commit 446122d7b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 10 deletions

View file

@ -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',

View file

@ -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);
}
}

View file

@ -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,