mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
Synced isdue/next due when user joins challenge (#9779)
This commit is contained in:
@@ -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 () => {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user