mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 06:07:21 +01:00
* 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
120 lines
3.2 KiB
JavaScript
120 lines
3.2 KiB
JavaScript
import {
|
|
generateUser,
|
|
generateGroup,
|
|
translate as t,
|
|
} from '../../../../../helpers/api-v3-integration.helper';
|
|
import { v4 as generateUUID } from 'uuid';
|
|
|
|
describe('POST /tasks/group/:groupid', () => {
|
|
let user, guild;
|
|
|
|
beforeEach(async () => {
|
|
user = await generateUser({balance: 1});
|
|
guild = await generateGroup(user, {type: 'guild'});
|
|
});
|
|
|
|
it('returns error when group is not found', async () => {
|
|
await expect(user.post(`/tasks/group/${generateUUID()}`, {
|
|
text: 'test habit',
|
|
type: 'habit',
|
|
up: false,
|
|
down: true,
|
|
notes: 1976,
|
|
})).to.eventually.be.rejected.and.eql({
|
|
code: 404,
|
|
error: 'NotFound',
|
|
message: t('groupNotFound'),
|
|
});
|
|
});
|
|
|
|
it('returns error when user is not a member of the group', async () => {
|
|
let userWithoutChallenge = await generateUser();
|
|
|
|
await expect(userWithoutChallenge.post(`/tasks/group/${guild._id}`, {
|
|
text: 'test habit',
|
|
type: 'habit',
|
|
up: false,
|
|
down: true,
|
|
notes: 1976,
|
|
})).to.eventually.be.rejected.and.eql({
|
|
code: 404,
|
|
error: 'NotFound',
|
|
message: t('groupNotFound'),
|
|
});
|
|
});
|
|
|
|
it('returns error when non leader tries to create a task', async () => {
|
|
let userThatIsNotLeaderOfGroup = await generateUser({
|
|
guilds: [guild._id],
|
|
});
|
|
|
|
await expect(userThatIsNotLeaderOfGroup.post(`/tasks/group/${guild._id}`, {
|
|
text: 'test habit',
|
|
type: 'habit',
|
|
up: false,
|
|
down: true,
|
|
notes: 1976,
|
|
})).to.eventually.be.rejected.and.eql({
|
|
code: 401,
|
|
error: 'NotAuthorized',
|
|
message: t('onlyGroupLeaderCanEditTasks'),
|
|
});
|
|
});
|
|
|
|
it('creates a habit', async () => {
|
|
let task = await user.post(`/tasks/group/${guild._id}`, {
|
|
text: 'test habit',
|
|
type: 'habit',
|
|
up: false,
|
|
down: true,
|
|
notes: 1976,
|
|
});
|
|
|
|
let groupTask = await user.get(`/tasks/group/${guild._id}`);
|
|
|
|
expect(groupTask[0].group.id).to.equal(guild._id);
|
|
expect(task.text).to.eql('test habit');
|
|
expect(task.notes).to.eql('1976');
|
|
expect(task.type).to.eql('habit');
|
|
expect(task.up).to.eql(false);
|
|
expect(task.down).to.eql(true);
|
|
});
|
|
|
|
it('creates a todo', async () => {
|
|
let task = await user.post(`/tasks/group/${guild._id}`, {
|
|
text: 'test todo',
|
|
type: 'todo',
|
|
notes: 1976,
|
|
});
|
|
|
|
let groupTask = await user.get(`/tasks/group/${guild._id}`);
|
|
|
|
expect(groupTask[0].group.id).to.equal(guild._id);
|
|
expect(task.text).to.eql('test todo');
|
|
expect(task.notes).to.eql('1976');
|
|
expect(task.type).to.eql('todo');
|
|
});
|
|
|
|
it('creates a daily', async () => {
|
|
let now = new Date();
|
|
let task = await user.post(`/tasks/group/${guild._id}`, {
|
|
text: 'test daily',
|
|
type: 'daily',
|
|
notes: 1976,
|
|
frequency: 'daily',
|
|
everyX: 5,
|
|
startDate: now,
|
|
});
|
|
|
|
let groupTask = await user.get(`/tasks/group/${guild._id}`);
|
|
|
|
expect(groupTask[0].group.id).to.equal(guild._id);
|
|
expect(task.text).to.eql('test daily');
|
|
expect(task.notes).to.eql('1976');
|
|
expect(task.type).to.eql('daily');
|
|
expect(task.frequency).to.eql('daily');
|
|
expect(task.everyX).to.eql(5);
|
|
expect(new Date(task.startDate)).to.eql(now);
|
|
});
|
|
});
|