mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +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
110 lines
2.4 KiB
JavaScript
110 lines
2.4 KiB
JavaScript
import '../../website/server/libs/i18n';
|
|
import mongoose from 'mongoose';
|
|
import { defaultsDeep as defaults } from 'lodash';
|
|
import { model as User } from '../../website/server/models/user';
|
|
import { model as Group } from '../../website/server/models/group';
|
|
import { model as Challenge } from '../../website/server/models/challenge';
|
|
import mongo from './mongo'; // eslint-disable-line
|
|
import moment from 'moment';
|
|
import i18n from '../../common/script/i18n';
|
|
import * as Tasks from '../../website/server/models/task';
|
|
|
|
afterEach((done) => {
|
|
sandbox.restore();
|
|
mongoose.connection.db.dropDatabase(done);
|
|
});
|
|
|
|
export { sleep } from './sleep';
|
|
|
|
export function generateUser (options = {}) {
|
|
return new User(options);
|
|
}
|
|
|
|
export function generateGroup (options = {}) {
|
|
return new Group(options);
|
|
}
|
|
|
|
export function generateChallenge (options = {}) {
|
|
return new Challenge(options);
|
|
}
|
|
|
|
export function generateRes (options = {}) {
|
|
let defaultRes = {
|
|
render: sandbox.stub(),
|
|
send: sandbox.stub(),
|
|
status: sandbox.stub().returnsThis(),
|
|
sendStatus: sandbox.stub().returnsThis(),
|
|
json: sandbox.stub(),
|
|
locals: {
|
|
user: generateUser(options.localsUser),
|
|
group: generateGroup(options.localsGroup),
|
|
},
|
|
set: sandbox.stub(),
|
|
t (string) {
|
|
return i18n.t(string);
|
|
},
|
|
};
|
|
|
|
return defaults(options, defaultRes);
|
|
}
|
|
|
|
export function generateReq (options = {}) {
|
|
let defaultReq = {
|
|
body: {},
|
|
query: {},
|
|
headers: {},
|
|
header: sandbox.stub().returns(null),
|
|
};
|
|
|
|
return defaults(options, defaultReq);
|
|
}
|
|
|
|
export function generateNext (func) {
|
|
return func || sandbox.stub();
|
|
}
|
|
|
|
export function generateHistory (days) {
|
|
let history = [];
|
|
let now = Number(moment().toDate());
|
|
|
|
while (days > 0) {
|
|
history.push({
|
|
value: days,
|
|
date: Number(moment(now).subtract(days, 'days').toDate()),
|
|
});
|
|
days--;
|
|
}
|
|
|
|
return history;
|
|
}
|
|
|
|
export function generateTodo (user) {
|
|
let todo = {
|
|
text: 'test todo',
|
|
type: 'todo',
|
|
value: 0,
|
|
completed: false,
|
|
};
|
|
|
|
let task = new Tasks.todo(Tasks.Task.sanitize(todo)); // eslint-disable-line babel/new-cap
|
|
task.userId = user._id;
|
|
task.save();
|
|
|
|
return task;
|
|
}
|
|
|
|
export function generateDaily (user) {
|
|
let daily = {
|
|
text: 'test daily',
|
|
type: 'daily',
|
|
value: 0,
|
|
completed: false,
|
|
};
|
|
|
|
let task = new Tasks.daily(Tasks.Task.sanitize(daily)); // eslint-disable-line babel/new-cap
|
|
task.userId = user._id;
|
|
task.save();
|
|
|
|
return task;
|
|
}
|