habitica/test/api/unit/libs/taskManager.js

190 lines
4.8 KiB
JavaScript
Raw Normal View History

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
2016-09-03 08:54:55 +00:00
import {
createTasks,
getTasks,
syncableAttrs,
moveTask,
2018-06-18 12:40:25 +00:00
} from '../../../../website/server/libs/taskManager';
import i18n from '../../../../website/common/script/i18n';
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
2016-09-03 08:54:55 +00:00
import {
generateUser,
generateGroup,
generateChallenge,
2018-06-18 12:40:25 +00:00
} from '../../../helpers/api-unit.helper.js';
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
2016-09-03 08:54:55 +00:00
describe('taskManager', () => {
let user, group, challenge;
let testHabit = {
text: 'test habit',
type: 'habit',
up: false,
down: true,
notes: 1976,
};
let req = {};
let res = {};
beforeEach(() => {
req = {};
res = {};
user = generateUser();
group = generateGroup({
name: 'test group',
type: 'guild',
privacy: 'public',
leader: user._id,
});
challenge = generateChallenge({
name: 'test challenge',
shortName: 'testc',
group: group._id,
leader: user._id,
});
});
it('creates user tasks', async () => {
req.body = testHabit;
res.t = i18n.t;
let newTasks = await createTasks(req, res, {user});
let newTask = newTasks[0];
expect(newTask.text).to.equal(testHabit.text);
expect(newTask.type).to.equal(testHabit.type);
expect(newTask.up).to.equal(testHabit.up);
expect(newTask.down).to.equal(testHabit.down);
expect(newTask.createdAt).to.exist;
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
2016-09-03 08:54:55 +00:00
});
it('gets user tasks', async () => {
req.body = testHabit;
res.t = i18n.t;
await createTasks(req, res, {user});
req.body = {};
req.query = {
type: 'habits',
};
let tasks = await getTasks(req, res, {user});
let task = tasks[0];
expect(task.text).to.equal(testHabit.text);
expect(task.type).to.equal(testHabit.type);
expect(task.up).to.equal(testHabit.up);
expect(task.down).to.equal(testHabit.down);
expect(task.createdAt).to.exist;
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
2016-09-03 08:54:55 +00:00
});
it('creates group tasks', async () => {
req.body = testHabit;
res.t = i18n.t;
let newTasks = await createTasks(req, res, {user, group});
let newTask = newTasks[0];
expect(newTask.text).to.equal(testHabit.text);
expect(newTask.type).to.equal(testHabit.type);
expect(newTask.up).to.equal(testHabit.up);
expect(newTask.down).to.equal(testHabit.down);
expect(newTask.createdAt).to.exist;
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
2016-09-03 08:54:55 +00:00
expect(newTask.group.id).to.equal(group._id);
});
it('gets group tasks', async () => {
req.body = testHabit;
res.t = i18n.t;
await createTasks(req, res, {user, group});
req.body = {};
req.query = {
type: 'habits',
};
let tasks = await getTasks(req, res, {user, group});
let task = tasks[0];
expect(task.text).to.equal(testHabit.text);
expect(task.type).to.equal(testHabit.type);
expect(task.up).to.equal(testHabit.up);
expect(task.down).to.equal(testHabit.down);
expect(task.createdAt).to.exist;
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
2016-09-03 08:54:55 +00:00
expect(task.group.id).to.equal(group._id);
});
it('creates challenge tasks', async () => {
req.body = testHabit;
res.t = i18n.t;
let newTasks = await createTasks(req, res, {user, challenge});
let newTask = newTasks[0];
expect(newTask.text).to.equal(testHabit.text);
expect(newTask.type).to.equal(testHabit.type);
expect(newTask.up).to.equal(testHabit.up);
expect(newTask.down).to.equal(testHabit.down);
expect(newTask.createdAt).to.exist;
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
2016-09-03 08:54:55 +00:00
expect(newTask.challenge.id).to.equal(challenge._id);
});
it('gets challenge tasks', async () => {
req.body = testHabit;
res.t = i18n.t;
await createTasks(req, res, {user, challenge});
req.body = {};
req.query = {
type: 'habits',
};
let tasks = await getTasks(req, res, {user, challenge});
let task = tasks[0];
expect(task.text).to.equal(testHabit.text);
expect(task.type).to.equal(testHabit.type);
expect(task.up).to.equal(testHabit.up);
expect(task.down).to.equal(testHabit.down);
expect(task.createdAt).to.exist;
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
2016-09-03 08:54:55 +00:00
expect(task.challenge.id).to.equal(challenge._id);
});
it('returns syncable attibutes', async () => {
req.body = testHabit;
res.t = i18n.t;
let tasks = await createTasks(req, res, {user, challenge});
let syncableTask = syncableAttrs(tasks[0]);
expect(syncableTask._id).to.not.exist;
expect(syncableTask.userId).to.not.exist;
expect(syncableTask.challenge).to.not.exist;
expect(syncableTask.history).to.not.exist;
expect(syncableTask.tags).to.not.exist;
expect(syncableTask.completed).to.not.exist;
expect(syncableTask.streak).to.not.exist;
expect(syncableTask.notes).to.not.exist;
expect(syncableTask.updatedAt).to.not.exist;
});
it('moves tasks to a specified position', async () => {
let order = ['task-id-1', 'task-id-2'];
moveTask(order, 'task-id-2', 0);
expect(order).to.eql(['task-id-2', 'task-id-1']);
});
it('moves tasks to a specified position out of length', async () => {
let order = ['task-id-1'];
moveTask(order, 'task-id-2', 2);
expect(order).to.eql(['task-id-1', 'task-id-2']);
});
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
2016-09-03 08:54:55 +00:00
});