diff --git a/test/api/v3/integration/challenges/POST-challenges_challengeId_join.test.js b/test/api/v3/integration/challenges/POST-challenges_challengeId_join.test.js index 29c312807d..1f7ef43d6b 100644 --- a/test/api/v3/integration/challenges/POST-challenges_challengeId_join.test.js +++ b/test/api/v3/integration/challenges/POST-challenges_challengeId_join.test.js @@ -101,19 +101,21 @@ describe('POST /challenges/:challengeId/join', () => { }); it('syncs challenge tasks to joining user', async () => { - let taskText = 'A challenge task text'; - + const taskText = 'A challenge task text'; await groupLeader.post(`/tasks/challenge/${challenge._id}`, [ - {type: 'habit', text: taskText}, + {type: 'daily', text: taskText}, ]); await authorizedUser.post(`/challenges/${challenge._id}/join`); - let tasks = await authorizedUser.get('/tasks/user'); - let tasksTexts = tasks.map((task) => { - return task.text; + + const tasks = await authorizedUser.get('/tasks/user'); + const syncedTask = tasks.find((task) => { + return task.text === taskText; }); - expect(tasksTexts).to.include(taskText); + expect(syncedTask.text).to.eql(taskText); + expect(syncedTask.isDue).to.exist; + expect(syncedTask.nextDue).to.exist; }); it('adds challenge tag to user tags', async () => { diff --git a/website/server/libs/taskManager.js b/website/server/libs/taskManager.js index b956419f73..fa3e5fa1fb 100644 --- a/website/server/libs/taskManager.js +++ b/website/server/libs/taskManager.js @@ -45,6 +45,7 @@ export function setNextDue (task, user, dueDateOption) { let optionsForShouldDo = user.preferences.toObject(); optionsForShouldDo.now = now; task.isDue = shared.shouldDo(dateTaskIsDue, task, optionsForShouldDo); + optionsForShouldDo.nextDue = true; let nextDue = shared.shouldDo(dateTaskIsDue, task, optionsForShouldDo); if (nextDue && nextDue.length > 0) { diff --git a/website/server/models/challenge.js b/website/server/models/challenge.js index 793eab37f9..8e44a6a470 100644 --- a/website/server/models/challenge.js +++ b/website/server/models/challenge.js @@ -14,7 +14,7 @@ import shared from '../../common'; import { sendTxn as txnEmail } from '../libs/email'; import { sendNotification as sendPushNotification } from '../libs/pushNotifications'; import cwait from 'cwait'; -import { syncableAttrs } from '../libs/taskManager'; +import { syncableAttrs, setNextDue } from '../libs/taskManager'; const Schema = mongoose.Schema; @@ -145,6 +145,7 @@ schema.methods.syncToUser = async function syncChallengeToUser (user) { matchingTask.challenge = {taskId: chalTask._id, id: challenge._id, shortName: challenge.shortName}; matchingTask.userId = user._id; user.tasksOrder[`${chalTask.type}s`].push(matchingTask._id); + setNextDue(matchingTask, user); } else { _.merge(matchingTask, syncableAttrs(chalTask)); // Make sure the task is in user.tasksOrder