WIP(tests): finish cleaning up v3 integrations

This commit is contained in:
SabreCat
2022-08-22 21:47:55 -05:00
parent 02c50b6126
commit 82abdaa0c4
9 changed files with 72 additions and 342 deletions

View File

@@ -8,10 +8,6 @@ describe('POST /tasks/:id/score/:direction', () => {
let user; let guild; let member; let member2; let let user; let guild; let member; let member2; let
task; task;
function findAssignedTask (memberTask) {
return memberTask.group.id === guild._id;
}
beforeEach(async () => { beforeEach(async () => {
const { group, members, groupLeader } = await createAndPopulateGroup({ const { group, members, groupLeader } = await createAndPopulateGroup({
groupDetails: { groupDetails: {
@@ -30,209 +26,50 @@ describe('POST /tasks/:id/score/:direction', () => {
task = await user.post(`/tasks/group/${guild._id}`, { task = await user.post(`/tasks/group/${guild._id}`, {
text: 'test todo', text: 'test todo',
type: 'todo', type: 'todo',
requiresApproval: true,
}); });
await user.post(`/tasks/${task._id}/assign/${member._id}`); await user.post(`/tasks/${task._id}/assign`, [member._id]);
}); });
it('prevents user from scoring a task that needs to be approved', async () => { it('completes single-assigned task', async () => {
await user.update({ await member.post(`/tasks/${task._id}/score/up`);
'preferences.language': 'cs',
});
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
const direction = 'up';
const response = await member.post(`/tasks/${syncedTask._id}/score/${direction}`);
expect(response.data.requiresApproval).to.equal(true);
expect(response.message).to.equal(t('taskApprovalHasBeenRequested'));
const updatedTask = await member.get(`/tasks/${syncedTask._id}`);
await user.sync();
expect(user.notifications.length).to.equal(3);
expect(user.notifications[2].type).to.equal('GROUP_TASK_APPROVAL');
expect(user.notifications[2].data.message).to.equal(t('userHasRequestedTaskApproval', {
user: member.auth.local.username,
taskName: updatedTask.text,
taskId: updatedTask._id,
direction,
}, 'cs')); // This test only works if we have the notification translated
expect(user.notifications[2].data.groupId).to.equal(guild._id);
expect(updatedTask.group.approval.requested).to.equal(true);
expect(updatedTask.group.approval.requestedDate).to.be.a('string'); // date gets converted to a string as json doesn't have a Date type
});
it('sends notifications to all managers', async () => {
await user.post(`/groups/${guild._id}/add-manager`, {
managerId: member2._id,
});
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
const direction = 'up';
await member.post(`/tasks/${syncedTask._id}/score/${direction}`);
const updatedTask = await member.get(`/tasks/${syncedTask._id}`);
await user.sync();
await member2.sync();
expect(user.notifications.length).to.equal(3);
expect(user.notifications[2].type).to.equal('GROUP_TASK_APPROVAL');
expect(user.notifications[2].data.message).to.equal(t('userHasRequestedTaskApproval', {
user: member.auth.local.username,
taskName: updatedTask.text,
taskId: updatedTask._id,
direction,
}));
expect(user.notifications[2].data.groupId).to.equal(guild._id);
expect(member2.notifications.length).to.equal(2);
expect(member2.notifications[1].type).to.equal('GROUP_TASK_APPROVAL');
expect(member2.notifications[1].data.message).to.equal(t('userHasRequestedTaskApproval', {
user: member.auth.local.username,
taskName: updatedTask.text,
taskId: updatedTask._id,
direction,
}));
expect(member2.notifications[1].data.groupId).to.equal(guild._id);
});
it('errors when approval has already been requested', async () => {
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await member.post(`/tasks/${syncedTask._id}/score/up`);
const response = await member.post(`/tasks/${syncedTask._id}/score/up`);
expect(response.data.requiresApproval).to.equal(true);
expect(response.message).to.equal(t('taskRequiresApproval'));
});
it('allows a user to score an approved task', async () => {
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await member.post(`/tasks/${syncedTask._id}/score/up`);
await user.post(`/tasks/${task._id}/approve/${member._id}`);
await member.post(`/tasks/${syncedTask._id}/score/up`);
const updatedTask = await member.get(`/tasks/${syncedTask._id}`);
expect(updatedTask.completed).to.equal(true);
expect(updatedTask.dateCompleted).to.be.a('string'); // date gets converted to a string as json doesn't have a Date type
});
it('completes master task when single-completion task is completed', async () => {
const sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
text: 'shared completion todo',
type: 'todo',
requiresApproval: false,
sharedCompletion: 'singleCompletion',
});
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member._id}`);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(
memberTasks,
memberTask => memberTask.group.taskId === sharedCompletionTask._id,
);
await member.post(`/tasks/${syncedTask._id}/score/up`);
const groupTasks = await user.get(`/tasks/group/${guild._id}?type=completedTodos`); const groupTasks = await user.get(`/tasks/group/${guild._id}?type=completedTodos`);
const masterTask = find(groupTasks, groupTask => groupTask._id === sharedCompletionTask._id); const sourceTask = find(groupTasks, groupTask => groupTask._id === task._id);
expect(masterTask.completed).to.equal(true); expect(sourceTask.completed).to.equal(true);
}); });
it('deletes other assigned user tasks when single-completion task is completed', async () => { it('errors when task has already been completed', async () => {
const sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, { await member.post(`/tasks/${task._id}/score/up`);
text: 'shared completion todo',
type: 'todo', await expect(member.post(`/tasks/${task._id}/score/up`)).to.be.rejected.and.to.eventually.eql({
requiresApproval: false, code: 401,
sharedCompletion: 'singleCompletion', error: 'NotAuthorized',
message: t('sessionOutdated'),
});
}); });
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member._id}`); it('does not complete multi-assigned task when not all assignees have completed', async () => {
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member2._id}`); await user.post(`/tasks/${task._id}/assign`, [member2._id]);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find( await member.post(`/tasks/${task._id}/score/up`);
memberTasks,
memberTask => memberTask.group.taskId === sharedCompletionTask._id,
);
await member.post(`/tasks/${syncedTask._id}/score/up`);
const member2Tasks = await member2.get('/tasks/user');
const syncedTask2 = find(
member2Tasks,
memberTask => memberTask.group.taskId === sharedCompletionTask._id,
);
expect(syncedTask2).to.equal(undefined);
});
it('does not complete master task when not all user tasks are completed if all assigned must complete', async () => {
const sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
text: 'shared completion todo',
type: 'todo',
requiresApproval: false,
sharedCompletion: 'allAssignedCompletion',
});
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member._id}`);
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member2._id}`);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(
memberTasks,
memberTask => memberTask.group.taskId === sharedCompletionTask._id,
);
await member.post(`/tasks/${syncedTask._id}/score/up`);
const groupTasks = await user.get(`/tasks/group/${guild._id}`); const groupTasks = await user.get(`/tasks/group/${guild._id}`);
const masterTask = find(groupTasks, groupTask => groupTask._id === sharedCompletionTask._id); const sourceTask = find(groupTasks, groupTask => groupTask._id === task._id);
expect(masterTask.completed).to.equal(false); expect(sourceTask.completed).to.equal(false);
}); });
it('completes master task when all user tasks are completed if all assigned must complete', async () => { it('completes multi-assigned task when all assignees have completed', async () => {
const sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, { await user.post(`/tasks/${task._id}/assign`, [member2._id]);
text: 'shared completion todo',
type: 'todo',
requiresApproval: false,
sharedCompletion: 'allAssignedCompletion',
});
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member._id}`); await member.post(`/tasks/${task._id}/score/up`);
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member2._id}`); await member2.post(`/tasks/${task._id}/score/up`);
const memberTasks = await member.get('/tasks/user');
const member2Tasks = await member2.get('/tasks/user');
const syncedTask = find(
memberTasks,
memberTask => memberTask.group.taskId === sharedCompletionTask._id,
);
const syncedTask2 = find(
member2Tasks,
memberTask => memberTask.group.taskId === sharedCompletionTask._id,
);
await member.post(`/tasks/${syncedTask._id}/score/up`);
await member2.post(`/tasks/${syncedTask2._id}/score/up`);
const groupTasks = await user.get(`/tasks/group/${guild._id}?type=completedTodos`); const groupTasks = await user.get(`/tasks/group/${guild._id}?type=completedTodos`);
const masterTask = find(groupTasks, groupTask => groupTask._id === sharedCompletionTask._id); const sourceTask = find(groupTasks, groupTask => groupTask._id === task._id);
expect(masterTask.completed).to.equal(true); expect(sourceTask.completed).to.equal(true);
}); });
}); });

View File

@@ -39,7 +39,7 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
}); });
it('returns error when task is not found', async () => { it('returns error when task is not found', async () => {
await expect(user.post(`/tasks/${generateUUID()}/assign/${member._id}`)) await expect(user.post(`/tasks/${generateUUID()}/assign`, [member._id]))
.to.eventually.be.rejected.and.eql({ .to.eventually.be.rejected.and.eql({
code: 404, code: 404,
error: 'NotFound', error: 'NotFound',
@@ -56,7 +56,7 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
notes: 1976, notes: 1976,
}); });
await expect(user.post(`/tasks/${nonGroupTask._id}/assign/${member._id}`)) await expect(user.post(`/tasks/${nonGroupTask._id}/assign`, [member._id]))
.to.eventually.be.rejected.and.eql({ .to.eventually.be.rejected.and.eql({
code: 401, code: 401,
error: 'NotAuthorized', error: 'NotAuthorized',
@@ -67,7 +67,7 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
it('returns error when user is not a member of the group', async () => { it('returns error when user is not a member of the group', async () => {
const nonUser = await generateUser(); const nonUser = await generateUser();
await expect(nonUser.post(`/tasks/${task._id}/assign/${member._id}`)) await expect(nonUser.post(`/tasks/${task._id}/assign`, [member._id]))
.to.eventually.be.rejected.and.eql({ .to.eventually.be.rejected.and.eql({
code: 404, code: 404,
error: 'NotFound', error: 'NotFound',
@@ -76,7 +76,7 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
}); });
it('returns error when non leader tries to create a task', async () => { it('returns error when non leader tries to create a task', async () => {
await expect(member2.post(`/tasks/${task._id}/assign/${member._id}`)) await expect(member2.post(`/tasks/${task._id}/assign`, [member._id]))
.to.eventually.be.rejected.and.eql({ .to.eventually.be.rejected.and.eql({
code: 401, code: 401,
error: 'NotAuthorized', error: 'NotAuthorized',
@@ -84,49 +84,23 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
}); });
}); });
it('allows user to assign themselves (claim)', async () => {
await member.post(`/tasks/${task._id}/assign/${member._id}`);
const groupTask = await user.get(`/tasks/group/${guild._id}`);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
expect(groupTask[0].group.assignedUsers).to.contain(member._id);
expect(syncedTask).to.exist;
});
it('sends notifications to group leader and managers when a task is claimed', async () => {
await user.post(`/groups/${guild._id}/add-manager`, {
managerId: member2._id,
});
await member.post(`/tasks/${task._id}/assign/${member._id}`);
await user.sync();
await member2.sync();
const groupTask = await user.get(`/tasks/group/${guild._id}`);
expect(user.notifications.length).to.equal(3); // includes Guild Joined achievement
expect(user.notifications[2].type).to.equal('GROUP_TASK_CLAIMED');
expect(user.notifications[2].data.taskId).to.equal(groupTask[0]._id);
expect(user.notifications[2].data.groupId).to.equal(guild._id);
expect(member2.notifications.length).to.equal(2);
expect(member2.notifications[1].type).to.equal('GROUP_TASK_CLAIMED');
expect(member2.notifications[1].data.taskId).to.equal(groupTask[0]._id);
expect(member2.notifications[1].data.groupId).to.equal(guild._id);
});
it('assigns a task to a user', async () => { it('assigns a task to a user', async () => {
await user.post(`/tasks/${task._id}/assign/${member._id}`); await user.post(`/tasks/${task._id}/assign`, [member._id]);
const groupTask = await user.get(`/tasks/group/${guild._id}`); const groupTask = await user.get(`/tasks/group/${guild._id}`);
await member.put('/user', {
'preferences.tasks.mirrorGroupTasks': [guild._id],
});
const memberTasks = await member.get('/tasks/user'); const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask); const syncedTask = find(memberTasks, findAssignedTask);
expect(groupTask[0].group.assignedUsers).to.contain(member._id); expect(groupTask[0].group.assignedUsers).to.contain(member._id);
expect(groupTask[0].group.assignedUsersDetail[member._id]).to.exist;
expect(syncedTask).to.exist; expect(syncedTask).to.exist;
}); });
it('sends a notification to assigned user', async () => { it('sends a notification to assigned user', async () => {
await user.post(`/tasks/${task._id}/assign/${member._id}`); await user.post(`/tasks/${task._id}/assign`, [member._id]);
await member.sync(); await member.sync();
const groupTask = await user.get(`/tasks/group/${guild._id}`); const groupTask = await user.get(`/tasks/group/${guild._id}`);
@@ -137,20 +111,27 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
}); });
it('assigns a task to multiple users', async () => { it('assigns a task to multiple users', async () => {
await user.post(`/tasks/${task._id}/assign/${member._id}`); await user.post(`/tasks/${task._id}/assign`, [member._id, member2._id]);
await user.post(`/tasks/${task._id}/assign/${member2._id}`);
const groupTask = await user.get(`/tasks/group/${guild._id}`); const groupTask = await user.get(`/tasks/group/${guild._id}`);
await member.put('/user', {
'preferences.tasks.mirrorGroupTasks': [guild._id],
});
const memberTasks = await member.get('/tasks/user'); const memberTasks = await member.get('/tasks/user');
const member1SyncedTask = find(memberTasks, findAssignedTask); const member1SyncedTask = find(memberTasks, findAssignedTask);
await member2.put('/user', {
'preferences.tasks.mirrorGroupTasks': [guild._id],
});
const member2Tasks = await member2.get('/tasks/user'); const member2Tasks = await member2.get('/tasks/user');
const member2SyncedTask = find(member2Tasks, findAssignedTask); const member2SyncedTask = find(member2Tasks, findAssignedTask);
expect(groupTask[0].group.assignedUsers).to.contain(member._id); expect(groupTask[0].group.assignedUsers).to.contain(member._id);
expect(groupTask[0].group.assignedUsers).to.contain(member2._id); expect(groupTask[0].group.assignedUsersDetail[member._id]).to.exist;
expect(member1SyncedTask).to.exist; expect(member1SyncedTask).to.exist;
expect(groupTask[0].group.assignedUsers).to.contain(member2._id);
expect(groupTask[0].group.assignedUsersDetail[member2._id]).to.exist;
expect(member2SyncedTask).to.exist; expect(member2SyncedTask).to.exist;
}); });
@@ -159,13 +140,17 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
managerId: member2._id, managerId: member2._id,
}); });
await member2.post(`/tasks/${task._id}/assign/${member._id}`); await member2.post(`/tasks/${task._id}/assign`, [member._id]);
const groupTask = await member2.get(`/tasks/group/${guild._id}`); const groupTask = await member2.get(`/tasks/group/${guild._id}`);
await member.put('/user', {
'preferences.tasks.mirrorGroupTasks': [guild._id],
});
const memberTasks = await member.get('/tasks/user'); const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask); const syncedTask = find(memberTasks, findAssignedTask);
expect(groupTask[0].group.assignedUsers).to.contain(member._id); expect(groupTask[0].group.assignedUsers).to.contain(member._id);
expect(groupTask[0].group.assignedUsersDetail[member._id]).to.exist;
expect(syncedTask).to.exist; expect(syncedTask).to.exist;
}); });
}); });

View File

@@ -37,7 +37,7 @@ describe('POST /tasks/:taskId/unassign/:memberId', () => {
notes: 1976, notes: 1976,
}); });
await user.post(`/tasks/${task._id}/assign/${member._id}`); await user.post(`/tasks/${task._id}/assign`, [member._id]);
}); });
it('returns error when task is not found', async () => { it('returns error when task is not found', async () => {
@@ -96,7 +96,7 @@ describe('POST /tasks/:taskId/unassign/:memberId', () => {
}); });
it('unassigns a user and only that user from a task', async () => { it('unassigns a user and only that user from a task', async () => {
await user.post(`/tasks/${task._id}/assign/${member2._id}`); await user.post(`/tasks/${task._id}/assign`, [member2._id]);
await user.post(`/tasks/${task._id}/unassign/${member._id}`); await user.post(`/tasks/${task._id}/unassign/${member._id}`);
@@ -105,6 +105,9 @@ describe('POST /tasks/:taskId/unassign/:memberId', () => {
const memberTasks = await member.get('/tasks/user'); const memberTasks = await member.get('/tasks/user');
const member1SyncedTask = find(memberTasks, findAssignedTask); const member1SyncedTask = find(memberTasks, findAssignedTask);
await member2.put('/user', {
'preferences.tasks.mirrorGroupTasks': [guild._id],
});
const member2Tasks = await member2.get('/tasks/user'); const member2Tasks = await member2.get('/tasks/user');
const member2SyncedTask = find(member2Tasks, findAssignedTask); const member2SyncedTask = find(member2Tasks, findAssignedTask);
@@ -130,20 +133,7 @@ describe('POST /tasks/:taskId/unassign/:memberId', () => {
expect(syncedTask).to.not.exist; expect(syncedTask).to.not.exist;
}); });
it('allows a user to unassign themselves', async () => { it('returns error when non leader tries to unassign a task', async () => {
await member.post(`/tasks/${task._id}/unassign/${member._id}`);
const groupTask = await user.get(`/tasks/group/${guild._id}`);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
expect(groupTask[0].group.assignedUsers).to.not.contain(member._id);
expect(syncedTask).to.not.exist;
});
// @TODO: Which do we want? The user to unassign themselves or not. This test was in
// here, but then we had a request to allow to unaissgn.
xit('returns error when non leader tries to unassign their a task', async () => {
await expect(member.post(`/tasks/${task._id}/unassign/${member._id}`)) await expect(member.post(`/tasks/${task._id}/unassign/${member._id}`))
.to.eventually.be.rejected.and.eql({ .to.eventually.be.rejected.and.eql({
code: 401, code: 401,

View File

@@ -1,4 +1,3 @@
import { find } from 'lodash';
import { import {
createAndPopulateGroup, translate as t, createAndPopulateGroup, translate as t,
} from '../../../../../helpers/api-integration/v3'; } from '../../../../../helpers/api-integration/v3';
@@ -11,10 +10,6 @@ describe('PUT /tasks/:id', () => {
let habit; let habit;
let todo; let todo;
function findAssignedTask (memberTask) {
return memberTask.group.id === guild._id;
}
beforeEach(async () => { beforeEach(async () => {
const { group, members, groupLeader } = await createAndPopulateGroup({ const { group, members, groupLeader } = await createAndPopulateGroup({
groupDetails: { groupDetails: {
@@ -44,8 +39,7 @@ describe('PUT /tasks/:id', () => {
notes: 1976, notes: 1976,
}); });
await user.post(`/tasks/${habit._id}/assign/${member._id}`); await user.post(`/tasks/${habit._id}/assign`, [member._id, member2._id]);
await user.post(`/tasks/${habit._id}/assign/${member2._id}`);
}); });
it('updates a group task', async () => { it('updates a group task', async () => {
@@ -56,28 +50,6 @@ describe('PUT /tasks/:id', () => {
expect(savedHabit.notes).to.eql('some new notes'); expect(savedHabit.notes).to.eql('some new notes');
}); });
it('updates a group task - approval is required', async () => {
// allow to manage
await user.post(`/groups/${guild._id}/add-manager`, {
managerId: member._id,
});
// change the habit
habit = await member.put(`/tasks/${habit._id}`, {
text: 'new text!',
requiresApproval: true,
});
const memberTasks = await member2.get('/tasks/user');
const syncedTask = find(memberTasks, memberTask => memberTask.group.taskId === habit._id);
// score up to trigger approval
const response = await member2.post(`/tasks/${syncedTask._id}/score/up`);
expect(response.data.requiresApproval).to.equal(true);
expect(response.message).to.equal(t('taskApprovalHasBeenRequested'));
});
it('member updates a group task value - not allowed', async () => { it('member updates a group task value - not allowed', async () => {
// change the todo // change the todo
await expect(member.put(`/tasks/${habit._id}`, { await expect(member.put(`/tasks/${habit._id}`, {
@@ -120,7 +92,7 @@ describe('PUT /tasks/:id', () => {
], ],
}); });
await user.post(`/tasks/${habit._id}/assign/${member._id}`); await user.post(`/tasks/${habit._id}/assign`, [member._id]);
// change the checklist text // change the checklist text
habit = await user.put(`/tasks/${habit._id}`, { habit = await user.put(`/tasks/${habit._id}`, {
@@ -137,63 +109,4 @@ describe('PUT /tasks/:id', () => {
expect(habit.checklist.length).to.eql(2); expect(habit.checklist.length).to.eql(2);
}); });
it('updates the linked tasks', async () => {
await user.put(`/tasks/${habit._id}`, {
text: 'some new text',
up: false,
down: false,
notes: 'some new notes',
});
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
expect(syncedTask.text).to.eql('some new text');
expect(syncedTask.up).to.eql(false);
expect(syncedTask.down).to.eql(false);
});
it('updates the linked tasks for all assigned users', async () => {
await user.put(`/tasks/${habit._id}`, {
text: 'some new text',
up: false,
down: false,
notes: 'some new notes',
});
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
const member2Tasks = await member2.get('/tasks/user');
const member2SyncedTask = find(member2Tasks, findAssignedTask);
expect(syncedTask.text).to.eql('some new text');
expect(syncedTask.up).to.eql(false);
expect(syncedTask.down).to.eql(false);
expect(member2SyncedTask.text).to.eql('some new text');
expect(member2SyncedTask.up).to.eql(false);
expect(member2SyncedTask.down).to.eql(false);
});
it('updates the linked tasks', async () => {
await user.post(`/groups/${guild._id}/add-manager`, {
managerId: member2._id,
});
await member2.put(`/tasks/${habit._id}`, {
text: 'some new text',
up: false,
down: false,
notes: 'some new notes',
});
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
expect(syncedTask.text).to.eql('some new text');
expect(syncedTask.up).to.eql(false);
expect(syncedTask.down).to.eql(false);
});
}); });

View File

@@ -145,15 +145,12 @@ describe('POST /user/class/cast/:spellId', () => {
text: 'todo group', text: 'todo group',
type: 'todo', type: 'todo',
}); });
await groupLeader.post(`/tasks/${groupTask._id}/assign/${groupLeader._id}`); await groupLeader.post(`/tasks/${groupTask._id}/assign`, [groupLeader._id]);
const memberTasks = await groupLeader.get('/tasks/user');
const syncedGroupTask = find(memberTasks, memberTask => memberTask.group.id === group._id);
await groupLeader.update({ 'stats.class': 'rogue', 'stats.lvl': 11 }); await groupLeader.update({ 'stats.class': 'rogue', 'stats.lvl': 11 });
await sleep(0.5); await sleep(0.5);
await groupLeader.sync(); await groupLeader.sync();
await expect(groupLeader.post(`/user/class/cast/pickPocket?targetId=${syncedGroupTask._id}`)) await expect(groupLeader.post(`/user/class/cast/pickPocket?targetId=${groupTask._id}`))
.to.eventually.be.rejected.and.eql({ .to.eventually.be.rejected.and.eql({
code: 400, code: 400,
error: 'BadRequest', error: 'BadRequest',
@@ -279,7 +276,10 @@ describe('POST /user/class/cast/:spellId', () => {
type: 'todo', type: 'todo',
}); });
await user.update({ 'stats.class': 'healer', 'stats.mp': 200, 'stats.lvl': 15 }); await user.update({ 'stats.class': 'healer', 'stats.mp': 200, 'stats.lvl': 15 });
await user.post(`/tasks/${groupTask._id}/assign/${user._id}`); await user.post(`/tasks/${groupTask._id}/assign`, [user._id]);
await user.put('/user', {
'preferences.tasks.mirrorGroupTasks': [guild._id],
});
await user.post('/user/class/cast/brightness'); await user.post('/user/class/cast/brightness');
await user.sync(); await user.sync();

View File

@@ -100,11 +100,14 @@ describe('POST /user/reset', () => {
text: 'todo group', text: 'todo group',
type: 'todo', type: 'todo',
}); });
await user.post(`/tasks/${groupTask._id}/assign/${user._id}`); await user.post(`/tasks/${groupTask._id}/assign`, [user._id]);
await user.post('/user/reset'); await user.post('/user/reset');
await user.sync(); await user.sync();
await user.put('/user', {
'preferences.tasks.mirrorGroupTasks': [guild._id],
});
const memberTasks = await user.get('/tasks/user'); const memberTasks = await user.get('/tasks/user');
const syncedGroupTask = find(memberTasks, memberTask => memberTask.group.id === guild._id); const syncedGroupTask = find(memberTasks, memberTask => memberTask.group.id === guild._id);

View File

@@ -130,7 +130,7 @@ describe('POST /user/class/cast/:spellId', () => {
text: 'todo group', text: 'todo group',
type: 'todo', type: 'todo',
}); });
await groupLeader.post(`/tasks/${groupTask._id}/assign/${groupLeader._id}`); await groupLeader.post(`/tasks/${groupTask._id}/assign`, [groupLeader._id]);
const memberTasks = await groupLeader.get('/tasks/user'); const memberTasks = await groupLeader.get('/tasks/user');
const syncedGroupTask = find(memberTasks, memberTask => memberTask.group.id === group._id); const syncedGroupTask = find(memberTasks, memberTask => memberTask.group.id === group._id);
@@ -247,7 +247,7 @@ describe('POST /user/class/cast/:spellId', () => {
type: 'todo', type: 'todo',
}); });
await user.update({ 'stats.class': 'healer', 'stats.mp': 200, 'stats.lvl': 15 }); await user.update({ 'stats.class': 'healer', 'stats.mp': 200, 'stats.lvl': 15 });
await user.post(`/tasks/${groupTask._id}/assign/${user._id}`); await user.post(`/tasks/${groupTask._id}/assign`, [user._id]);
await user.post('/user/class/cast/brightness'); await user.post('/user/class/cast/brightness');
await user.sync(); await user.sync();

View File

@@ -100,11 +100,14 @@ describe('POST /user/reset', () => {
text: 'todo group', text: 'todo group',
type: 'todo', type: 'todo',
}); });
await user.post(`/tasks/${groupTask._id}/assign/${user._id}`); await user.post(`/tasks/${groupTask._id}/assign`, [user._id]);
await user.post('/user/reset'); await user.post('/user/reset');
await user.sync(); await user.sync();
await user.put('/user', {
'preferences.tasks.mirrorGroupTasks': [guild._id],
});
const memberTasks = await user.get('/tasks/user'); const memberTasks = await user.get('/tasks/user');
const syncedGroupTask = find(memberTasks, memberTask => memberTask.group.id === guild._id); const syncedGroupTask = find(memberTasks, memberTask => memberTask.group.id === guild._id);

View File

@@ -22,7 +22,6 @@ async function castTaskSpell (res, req, targetId, user, spell, quantity = 1) {
const task = await Tasks.Task.findOne({ const task = await Tasks.Task.findOne({
_id: targetId, _id: targetId,
userId: user._id,
}).exec(); }).exec();
if (!task) throw new NotFound(res.t('messageTaskNotFound')); if (!task) throw new NotFound(res.t('messageTaskNotFound'));
if (task.challenge.id) throw new BadRequest(res.t('challengeTasksNoCast')); if (task.challenge.id) throw new BadRequest(res.t('challengeTasksNoCast'));