mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Groups assign tasks (#7887)
* Added initial code for creating and reading group tasks * Separated group task routes. Separated shared task functions * Added taskOrder to group * Minor style fixes * Fixed lint issues * Added unit tests for task manager * Updated task helper functions * Fixed history test * Fixed group task query * Removed extra var * Updated with new file structure * Updated noset values * Removed unecessary undefineds, fixed comments, Added apiignore * Separated group task routes. Separated shared task functions * Added unit tests for task manager * Added initial groups assign route and tests * Added sync assigned task to user * Added unassign route and unlink method * Added remove and unlink group task * Updated linking and unlinking. Add test for updating task info * Added delete group task and tests * Added sync on task update and tests * Added multiple users assignment * Updated unassign for multiple users * Added test for delete task with multiple assigend users * Added update task for multiple assigned users * Fixed issue with get tasks * Abstracted syncable attributes and add tests * Fixed merge conflicts * Fixed style issues, limited group query fields, and added await * Fixed group fields needed. Removed api v2 code * Fixed style issues * Moved group field under group sub document. Updated tests. Fixed other broken tests * Renamed linkedTaskId and fixed broken alias tests * Added debug middleware to new routes * Fixed debug middleware import * Added additional user id check for original group tasks * Updated challenge task check to look for challenge id * Added checklist sync fix
This commit is contained in:
committed by
Matteo Pagliazzi
parent
173b3f3f84
commit
836cee2531
@@ -0,0 +1,80 @@
|
||||
import {
|
||||
generateUser,
|
||||
generateGroup,
|
||||
translate as t,
|
||||
} from '../../../../../helpers/api-integration/v3';
|
||||
import { v4 as generateUUID } from 'uuid';
|
||||
import { each } from 'lodash';
|
||||
|
||||
describe('GET /tasks/group/:groupId', () => {
|
||||
let user, group, task, groupWithTask;
|
||||
let tasks = [];
|
||||
let tasksToTest = {
|
||||
habit: {
|
||||
text: 'test habit',
|
||||
type: 'habit',
|
||||
up: false,
|
||||
down: true,
|
||||
},
|
||||
todo: {
|
||||
text: 'test todo',
|
||||
type: 'todo',
|
||||
},
|
||||
daily: {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
frequency: 'daily',
|
||||
everyX: 5,
|
||||
startDate: new Date(),
|
||||
},
|
||||
reward: {
|
||||
text: 'test reward',
|
||||
type: 'reward',
|
||||
},
|
||||
};
|
||||
|
||||
before(async () => {
|
||||
user = await generateUser();
|
||||
group = await generateGroup(user);
|
||||
});
|
||||
|
||||
it('returns error when group is not found', async () => {
|
||||
let dummyId = generateUUID();
|
||||
|
||||
await expect(user.get(`/tasks/group/${dummyId}`)).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('groupNotFound'),
|
||||
});
|
||||
});
|
||||
|
||||
each(tasksToTest, (taskValue, taskType) => {
|
||||
context(`${taskType}`, () => {
|
||||
before(async () => {
|
||||
task = await user.post(`/tasks/group/${group._id}`, taskValue);
|
||||
tasks.push(task);
|
||||
groupWithTask = await user.get(`/groups/${group._id}`);
|
||||
});
|
||||
|
||||
it('gets group tasks', async () => {
|
||||
let getTask = await user.get(`/tasks/group/${groupWithTask._id}`);
|
||||
expect(getTask).to.eql(tasks);
|
||||
});
|
||||
|
||||
it('gets group tasks filtered by type', async () => {
|
||||
let groupTasks = await user.get(`/tasks/group/${groupWithTask._id}?type=${task.type}s`);
|
||||
expect(groupTasks).to.eql([task]);
|
||||
});
|
||||
|
||||
it('cannot get a task owned by someone else', async () => {
|
||||
let anotherUser = await generateUser();
|
||||
|
||||
await expect(anotherUser.get(`/tasks/group/${groupWithTask._id}`)).to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
error: 'NotFound',
|
||||
message: t('groupNotFound'),
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user