Ensured group tasks are removed from places that challegnes tasks are (#8359)

* Ensured group tasks are removed from places that challegnes tasks are

* Added tests for user reset and class cast
This commit is contained in:
Keith Holliday
2017-01-07 05:01:12 -06:00
committed by Matteo Pagliazzi
parent 28e8ec2d2c
commit 857aa5827b
7 changed files with 72 additions and 9 deletions

View File

@@ -9,7 +9,10 @@ module.exports = function reset (user, tasks = []) {
let tasksToRemove = [];
tasks.forEach(task => {
if (!task.challenge || !task.challenge.id || task.challenge.broken) {
let isNotChallengeTask = !task.challenge || !task.challenge.id || task.challenge.broken;
let isNotGroupTask = !task.group || !task.group.id || task.group.broken;
if (isNotChallengeTask && isNotGroupTask) {
tasksToRemove.push(task._id);
let i = user.tasksOrder[`${task.type}s`].indexOf(task._id);
if (i !== -1) user.tasksOrder[`${task.type}s`].splice(i, 1);