fix test lint

This commit is contained in:
Matteo Pagliazzi
2019-10-08 20:45:38 +02:00
parent e37f4467f8
commit 85fb5f33aa
367 changed files with 6635 additions and 6080 deletions

View File

@@ -1,3 +1,4 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
translate as t,
@@ -6,7 +7,6 @@ import {
generateChallenge,
server,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('DELETE /tasks/:id', () => {
let user;
@@ -57,9 +57,9 @@ describe('DELETE /tasks/:id', () => {
});
it('sends task activity webhooks if task is user owned', async () => {
let uuid = generateUUID();
const uuid = generateUUID();
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
});
@@ -78,20 +78,20 @@ describe('DELETE /tasks/:id', () => {
await sleep();
let body = server.getWebhookData(uuid);
const body = server.getWebhookData(uuid);
expect(body.type).to.eql('deleted');
expect(body.task).to.eql(task);
});
it('does not send task activity webhooks if task is not user owned', async () => {
let uuid = generateUUID();
const uuid = generateUUID();
await user.update({
balance: 10,
});
let guild = await generateGroup(user);
let challenge = await generateChallenge(user, guild);
const guild = await generateGroup(user);
const challenge = await generateChallenge(user, guild);
await user.post(`/challenges/${challenge._id}/join`);
await user.post('/user/webhook', {
@@ -104,7 +104,7 @@ describe('DELETE /tasks/:id', () => {
},
});
let challengeTask = await user.post(`/tasks/challenge/${challenge._id}`, {
const challengeTask = await user.post(`/tasks/challenge/${challenge._id}`, {
text: 'test habit',
type: 'habit',
});
@@ -113,7 +113,7 @@ describe('DELETE /tasks/:id', () => {
await sleep();
let body = server.getWebhookData(uuid);
const body = server.getWebhookData(uuid);
expect(body).to.not.exist;
});
@@ -129,8 +129,8 @@ describe('DELETE /tasks/:id', () => {
});
it('cannot delete a task owned by someone else', async () => {
let anotherUser = await generateUser();
let anotherUsersTask = await anotherUser.post('/tasks/user', {
const anotherUser = await generateUser();
const anotherUsersTask = await anotherUser.post('/tasks/user', {
text: 'test habit',
type: 'habit',
});
@@ -143,7 +143,7 @@ describe('DELETE /tasks/:id', () => {
});
it('removes a task from user.tasksOrder', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
});

View File

@@ -1,18 +1,18 @@
import { each } from 'lodash';
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateGroup,
generateChallenge,
translate as t,
} from '../../../../helpers/api-integration/v3';
import { each } from 'lodash';
import { v4 as generateUUID } from 'uuid';
describe('GET /tasks/:taskId', () => {
let user;
let guild;
let challenge;
let task;
let tasksToTest = {
const tasksToTest = {
habit: {
text: 'test habit',
type: 'habit',
@@ -58,12 +58,12 @@ describe('GET /tasks/:taskId', () => {
});
it('gets challenge task', async () => {
let getTask = await user.get(`/tasks/${task._id}`);
const getTask = await user.get(`/tasks/${task._id}`);
expect(getTask).to.eql(task);
});
it('returns error when user is not a member of the challenge', async () => {
let anotherUser = await generateUser();
const anotherUser = await generateUser();
await expect(anotherUser.get(`/tasks/${task._id}`)).to.eventually.be.rejected.and.eql({
code: 404,

View File

@@ -1,8 +1,8 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('GET /tasks/:id', () => {
let user;
@@ -23,13 +23,13 @@ describe('GET /tasks/:id', () => {
});
it('gets specified task', async () => {
let getTask = await user.get(`/tasks/${task._id}`);
const getTask = await user.get(`/tasks/${task._id}`);
expect(getTask).to.eql(task);
});
it('can use alias to retrieve task', async () => {
let getTask = await user.get(`/tasks/${task.alias}`);
const getTask = await user.get(`/tasks/${task.alias}`);
expect(getTask).to.eql(task);
});
@@ -40,7 +40,7 @@ describe('GET /tasks/:id', () => {
context('task cannot be accessed', () => {
it('cannot get a non-existant task', async () => {
let dummyId = generateUUID();
const dummyId = generateUUID();
await expect(user.get(`/tasks/${dummyId}`)).to.eventually.be.rejected.and.eql({
code: 404,
@@ -50,8 +50,8 @@ describe('GET /tasks/:id', () => {
});
it('cannot get a task owned by someone else', async () => {
let anotherUser = await generateUser();
let task = await user.post('/tasks/user', {
const anotherUser = await generateUser();
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
});

View File

@@ -11,21 +11,21 @@ describe('GET /tasks/user', () => {
});
it('returns all user\'s tasks', async () => {
let createdTasks = await user.post('/tasks/user', [{text: 'test habit', type: 'habit'}, {text: 'test todo', type: 'todo'}]);
let tasks = await user.get('/tasks/user');
const createdTasks = await user.post('/tasks/user', [{ text: 'test habit', type: 'habit' }, { text: 'test todo', type: 'todo' }]);
const tasks = await user.get('/tasks/user');
expect(tasks.length).to.equal(createdTasks.length + 1); // Plus one for generated todo
});
it('returns only a type of user\'s tasks if req.query.type is specified', async () => {
let createdTasks = await user.post('/tasks/user', [
{text: 'test habit', type: 'habit'},
{text: 'test daily', type: 'daily'},
{text: 'test reward', type: 'reward'},
{text: 'test todo', type: 'todo'},
const createdTasks = await user.post('/tasks/user', [
{ text: 'test habit', type: 'habit' },
{ text: 'test daily', type: 'daily' },
{ text: 'test reward', type: 'reward' },
{ text: 'test todo', type: 'todo' },
]);
let habits = await user.get('/tasks/user?type=habits');
let dailys = await user.get('/tasks/user?type=dailys');
let rewards = await user.get('/tasks/user?type=rewards');
const habits = await user.get('/tasks/user?type=habits');
const dailys = await user.get('/tasks/user?type=dailys');
const rewards = await user.get('/tasks/user?type=rewards');
expect(habits.length).to.be.at.least(1);
expect(habits[0]._id).to.equal(createdTasks[0]._id);
@@ -36,28 +36,28 @@ describe('GET /tasks/user', () => {
});
it('returns uncompleted todos if req.query.type is "todos"', async () => {
let existingTodos = await user.get('/tasks/user?type=todos');
const existingTodos = await user.get('/tasks/user?type=todos');
// populate user with other task types
await user.post('/tasks/user', [
{text: 'daily', type: 'daily'},
{text: 'reward', type: 'reward'},
{text: 'habit', type: 'habit'},
{ text: 'daily', type: 'daily' },
{ text: 'reward', type: 'reward' },
{ text: 'habit', type: 'habit' },
]);
let newUncompletedTodos = await user.post('/tasks/user', [
{text: 'test todo 1', type: 'todo'},
{text: 'test todo 2', type: 'todo'},
const newUncompletedTodos = await user.post('/tasks/user', [
{ text: 'test todo 1', type: 'todo' },
{ text: 'test todo 2', type: 'todo' },
]);
let todoToBeCompleted = await user.post('/tasks/user', {
const todoToBeCompleted = await user.post('/tasks/user', {
text: 'wll be completed todo', type: 'todo',
});
await user.post(`/tasks/${todoToBeCompleted._id}/score/up`);
let uncompletedTodos = [...existingTodos, ...newUncompletedTodos];
const uncompletedTodos = [...existingTodos, ...newUncompletedTodos];
let todos = await user.get('/tasks/user?type=todos');
const todos = await user.get('/tasks/user?type=todos');
expect(todos.length).to.be.gte(2);
expect(todos.length).to.eql(uncompletedTodos.length);
@@ -66,11 +66,11 @@ describe('GET /tasks/user', () => {
});
it('returns completed todos sorted by reverse completion date if req.query.type is "completedTodos"', async () => {
let todo1 = await user.post('/tasks/user', {text: 'todo to complete 1', type: 'todo'});
let todo2 = await user.post('/tasks/user', {text: 'todo to complete 2', type: 'todo'});
const todo1 = await user.post('/tasks/user', { text: 'todo to complete 1', type: 'todo' });
const todo2 = await user.post('/tasks/user', { text: 'todo to complete 2', type: 'todo' });
await user.sync();
let initialTodoCount = user.tasksOrder.todos.length;
const initialTodoCount = user.tasksOrder.todos.length;
await user.post(`/tasks/${todo2._id}/score/up`);
await user.post(`/tasks/${todo1._id}/score/up`);
@@ -78,17 +78,17 @@ describe('GET /tasks/user', () => {
expect(user.tasksOrder.todos.length).to.equal(initialTodoCount - 2);
let completedTodos = await user.get('/tasks/user?type=completedTodos');
const completedTodos = await user.get('/tasks/user?type=completedTodos');
expect(completedTodos.length).to.equal(2);
expect(completedTodos[completedTodos.length - 1].text).to.equal('todo to complete 2'); // last is the todo that was completed most recently
});
it('returns completed todos sorted by reverse completion date if req.query.type is "_allCompletedTodos"', async () => {
let todo1 = await user.post('/tasks/user', {text: 'todo to complete 1', type: 'todo'});
let todo2 = await user.post('/tasks/user', {text: 'todo to complete 2', type: 'todo'});
const todo1 = await user.post('/tasks/user', { text: 'todo to complete 1', type: 'todo' });
const todo2 = await user.post('/tasks/user', { text: 'todo to complete 2', type: 'todo' });
await user.sync();
let initialTodoCount = user.tasksOrder.todos.length;
const initialTodoCount = user.tasksOrder.todos.length;
await user.post(`/tasks/${todo2._id}/score/up`);
await user.post(`/tasks/${todo1._id}/score/up`);
@@ -96,25 +96,25 @@ describe('GET /tasks/user', () => {
expect(user.tasksOrder.todos.length).to.equal(initialTodoCount - 2);
let allCompletedTodos = await user.get('/tasks/user?type=_allCompletedTodos');
const allCompletedTodos = await user.get('/tasks/user?type=_allCompletedTodos');
expect(allCompletedTodos.length).to.equal(2);
expect(allCompletedTodos[allCompletedTodos.length - 1].text).to.equal('todo to complete 2');
});
it('returns only some completed todos if req.query.type is "completedTodos" or "_allCompletedTodos"', async () => {
const LIMIT = 30;
let numberOfTodos = LIMIT + 1;
let todosInput = [];
const numberOfTodos = LIMIT + 1;
const todosInput = [];
for (let i = 0; i < numberOfTodos; i++) {
todosInput[i] = {text: 'todo to complete ${i}', type: 'todo'};
for (let i = 0; i < numberOfTodos; i += 1) {
todosInput[i] = { text: `todo to complete ${i}`, type: 'todo' };
}
let todos = await user.post('/tasks/user', todosInput);
const todos = await user.post('/tasks/user', todosInput);
await user.sync();
let initialTodoCount = user.tasksOrder.todos.length;
const initialTodoCount = user.tasksOrder.todos.length;
for (let i = 0; i < numberOfTodos; i++) {
let id = todos[i]._id;
for (let i = 0; i < numberOfTodos; i += 1) {
const id = todos[i]._id;
await user.post(`/tasks/${id}/score/up`); // eslint-disable-line no-await-in-loop
}
@@ -122,17 +122,17 @@ describe('GET /tasks/user', () => {
expect(user.tasksOrder.todos.length).to.equal(initialTodoCount - numberOfTodos);
let completedTodos = await user.get('/tasks/user?type=completedTodos');
const completedTodos = await user.get('/tasks/user?type=completedTodos');
expect(completedTodos.length).to.equal(LIMIT);
let allCompletedTodos = await user.get('/tasks/user?type=_allCompletedTodos');
const allCompletedTodos = await user.get('/tasks/user?type=_allCompletedTodos');
expect(allCompletedTodos.length).to.equal(numberOfTodos);
});
it('returns dailies with isDue for the date specified', async () => {
// @TODO Add required format
let startDate = moment().subtract('1', 'days').toISOString();
let createdTasks = await user.post('/tasks/user', [
const startDate = moment().subtract('1', 'days').toISOString();
const createdTasks = await user.post('/tasks/user', [
{
text: 'test daily',
type: 'daily',
@@ -141,24 +141,25 @@ describe('GET /tasks/user', () => {
everyX: 2,
},
]);
let dailys = await user.get('/tasks/user?type=dailys');
const dailys = await user.get('/tasks/user?type=dailys');
expect(dailys.length).to.be.at.least(1);
expect(dailys[0]._id).to.equal(createdTasks._id);
expect(dailys[0].isDue).to.be.false;
let dailys2 = await user.get(`/tasks/user?type=dailys&dueDate=${startDate}`);
const dailys2 = await user.get(`/tasks/user?type=dailys&dueDate=${startDate}`);
expect(dailys2[0]._id).to.equal(createdTasks._id);
expect(dailys2[0].isDue).to.be.true;
});
xit('returns dailies with isDue for the date specified and will add CDS offset if time is not supplied and assumes timezones', async () => {
let timezone = 420;
const timezone = 420;
await user.update({
'preferences.dayStart': 0,
'preferences.timezoneOffset': timezone,
});
let startDate = moment().zone(timezone).subtract('4', 'days').startOf('day').toISOString();
const startDate = moment().zone(timezone).subtract('4', 'days').startOf('day')
.toISOString();
await user.post('/tasks/user', [
{
text: 'test daily',
@@ -169,23 +170,24 @@ describe('GET /tasks/user', () => {
},
]);
let today = moment().format('YYYY-MM-DD');
let dailys = await user.get(`/tasks/user?type=dailys&dueDate=${today}`);
const today = moment().format('YYYY-MM-DD');
const dailys = await user.get(`/tasks/user?type=dailys&dueDate=${today}`);
expect(dailys[0].isDue).to.be.true;
let yesterday = moment().subtract('1', 'days').format('YYYY-MM-DD');
let dailys2 = await user.get(`/tasks/user?type=dailys&dueDate=${yesterday}`);
const yesterday = moment().subtract('1', 'days').format('YYYY-MM-DD');
const dailys2 = await user.get(`/tasks/user?type=dailys&dueDate=${yesterday}`);
expect(dailys2[0].isDue).to.be.false;
});
xit('returns dailies with isDue for the date specified and will add CDS offset if time is not supplied and assumes timezones', async () => {
let timezone = 240;
const timezone = 240;
await user.update({
'preferences.dayStart': 0,
'preferences.timezoneOffset': timezone,
});
let startDate = moment().zone(timezone).subtract('4', 'days').startOf('day').toISOString();
const startDate = moment().zone(timezone).subtract('4', 'days').startOf('day')
.toISOString();
await user.post('/tasks/user', [
{
text: 'test daily',
@@ -196,22 +198,23 @@ describe('GET /tasks/user', () => {
},
]);
let today = moment().format('YYYY-MM-DD');
let dailys = await user.get(`/tasks/user?type=dailys&dueDate=${today}`);
const today = moment().format('YYYY-MM-DD');
const dailys = await user.get(`/tasks/user?type=dailys&dueDate=${today}`);
expect(dailys[0].isDue).to.be.true;
let yesterday = moment().subtract('1', 'days').format('YYYY-MM-DD');
let dailys2 = await user.get(`/tasks/user?type=dailys&dueDate=${yesterday}`);
const yesterday = moment().subtract('1', 'days').format('YYYY-MM-DD');
const dailys2 = await user.get(`/tasks/user?type=dailys&dueDate=${yesterday}`);
expect(dailys2[0].isDue).to.be.false;
});
xit('returns dailies with isDue for the date specified and will add CDS offset if time is not supplied and assumes timezones', async () => {
let timezone = 540;
const timezone = 540;
await user.update({
'preferences.dayStart': 0,
'preferences.timezoneOffset': timezone,
});
let startDate = moment().zone(timezone).subtract('4', 'days').startOf('day').toISOString();
const startDate = moment().zone(timezone).subtract('4', 'days').startOf('day')
.toISOString();
await user.post('/tasks/user', [
{
text: 'test daily',
@@ -222,12 +225,12 @@ describe('GET /tasks/user', () => {
},
]);
let today = moment().format('YYYY-MM-DD');
let dailys = await user.get(`/tasks/user?type=dailys&dueDate=${today}`);
const today = moment().format('YYYY-MM-DD');
const dailys = await user.get(`/tasks/user?type=dailys&dueDate=${today}`);
expect(dailys[0].isDue).to.be.true;
let yesterday = moment().subtract('1', 'days').format('YYYY-MM-DD');
let dailys2 = await user.get(`/tasks/user?type=dailys&dueDate=${yesterday}`);
const yesterday = moment().subtract('1', 'days').format('YYYY-MM-DD');
const dailys2 = await user.get(`/tasks/user?type=dailys&dueDate=${yesterday}`);
expect(dailys2[0].isDue).to.be.false;
});
});

View File

@@ -6,18 +6,18 @@ import {
describe('POST /tasks/clearCompletedTodos', () => {
it('deletes all completed todos except the ones from a challenge and group', async () => {
let user = await generateUser({balance: 1});
let guild = await generateGroup(user);
let challenge = await generateChallenge(user, guild);
const user = await generateUser({ balance: 1 });
const guild = await generateGroup(user);
const challenge = await generateChallenge(user, guild);
await user.post(`/challenges/${challenge._id}/join`);
let initialTodoCount = user.tasksOrder.todos.length;
const initialTodoCount = user.tasksOrder.todos.length;
await user.post('/tasks/user', [
{text: 'todo 1', type: 'todo'},
{text: 'todo 2', type: 'todo'},
{text: 'todo 3', type: 'todo'},
{text: 'todo 4', type: 'todo'},
{text: 'todo 5', type: 'todo'},
{ text: 'todo 1', type: 'todo' },
{ text: 'todo 2', type: 'todo' },
{ text: 'todo 3', type: 'todo' },
{ text: 'todo 4', type: 'todo' },
{ text: 'todo 5', type: 'todo' },
]);
await user.post(`/tasks/challenge/${challenge._id}`, {
@@ -25,26 +25,27 @@ describe('POST /tasks/clearCompletedTodos', () => {
type: 'todo',
});
let groupTask = await user.post(`/tasks/group/${guild._id}`, {
const groupTask = await user.post(`/tasks/group/${guild._id}`, {
text: 'todo 7',
type: 'todo',
});
await user.post(`/tasks/${groupTask._id}/assign/${user._id}`);
let tasks = await user.get('/tasks/user?type=todos');
const tasks = await user.get('/tasks/user?type=todos');
expect(tasks.length).to.equal(initialTodoCount + 7);
for (let task of tasks) {
for (const task of tasks) { // eslint-disable-line
if (['todo 2', 'todo 3', 'todo 6'].indexOf(task.text) !== -1) {
await user.post(`/tasks/${task._id}/score/up`); // eslint-disable-line no-await-in-loop
}
}
await user.post('/tasks/clearCompletedTodos');
let completedTodos = await user.get('/tasks/user?type=completedTodos');
let todos = await user.get('/tasks/user?type=todos');
let allTodos = todos.concat(completedTodos);
expect(allTodos.length).to.equal(initialTodoCount + 5); // + 7 - 3 completed (but one is from challenge)
const completedTodos = await user.get('/tasks/user?type=completedTodos');
const todos = await user.get('/tasks/user?type=todos');
const allTodos = todos.concat(completedTodos);
// + 7 - 3 completed (but one is from challenge)
expect(allTodos.length).to.equal(initialTodoCount + 5);
expect(allTodos[allTodos.length - 1].text).to.equal('todo 6'); // last completed todo
});
});

View File

@@ -1,10 +1,10 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
sleep,
translate as t,
server,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /tasks/:id/score/:direction', () => {
let user;
@@ -17,25 +17,25 @@ describe('POST /tasks/:id/score/:direction', () => {
context('all', () => {
it('can use an id to identify the task', async () => {
let todo = await user.post('/tasks/user', {
const todo = await user.post('/tasks/user', {
text: 'test todo',
type: 'todo',
alias: 'alias',
});
let res = await user.post(`/tasks/${todo._id}/score/up`);
const res = await user.post(`/tasks/${todo._id}/score/up`);
expect(res).to.be.ok;
});
it('can use a alias in place of the id', async () => {
let todo = await user.post('/tasks/user', {
const todo = await user.post('/tasks/user', {
text: 'test todo',
type: 'todo',
alias: 'alias',
});
let res = await user.post(`/tasks/${todo.alias}/score/up`);
const res = await user.post(`/tasks/${todo.alias}/score/up`);
expect(res).to.be.ok;
});
@@ -49,7 +49,7 @@ describe('POST /tasks/:id/score/:direction', () => {
});
it('sends task scored webhooks', async () => {
let uuid = generateUUID();
const uuid = generateUUID();
await server.start();
await user.post('/user/webhook', {
@@ -62,7 +62,7 @@ describe('POST /tasks/:id/score/:direction', () => {
},
});
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
});
@@ -73,7 +73,7 @@ describe('POST /tasks/:id/score/:direction', () => {
await server.close();
let body = server.getWebhookData(uuid);
const body = server.getWebhookData(uuid);
expect(body.user).to.have.all.keys('_id', '_tmp', 'stats');
expect(body.user.stats).to.have.all.keys('hp', 'mp', 'exp', 'gp', 'lvl', 'class', 'points', 'str', 'con', 'int', 'per', 'buffs', 'training', 'maxHealth', 'maxMP', 'toNextLevel');
@@ -92,7 +92,7 @@ describe('POST /tasks/:id/score/:direction', () => {
});
it('sends user activity webhook when the user levels up', async () => {
let uuid = generateUUID();
const uuid = generateUUID();
await user.post('/user/webhook', {
url: `http://localhost:${server.port}/webhooks/${uuid}`,
@@ -108,7 +108,7 @@ describe('POST /tasks/:id/score/:direction', () => {
await user.update({
'stats.exp': 3000,
});
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
});
@@ -117,7 +117,7 @@ describe('POST /tasks/:id/score/:direction', () => {
await user.sync();
await sleep();
let body = server.getWebhookData(uuid);
const body = server.getWebhookData(uuid);
expect(body.type).to.eql('leveledUp');
expect(body.initialLvl).to.eql(initialLvl);
@@ -138,44 +138,45 @@ describe('POST /tasks/:id/score/:direction', () => {
it('completes todo when direction is up', async () => {
await user.post(`/tasks/${todo._id}/score/up`);
let task = await user.get(`/tasks/${todo._id}`);
const task = await user.get(`/tasks/${todo._id}`);
expect(task.completed).to.equal(true);
expect(task.dateCompleted).to.be.a('string'); // date gets converted to a string as json doesn't have a Date type
});
it('moves completed todos out of user.tasksOrder.todos', async () => {
let getUser = await user.get('/user');
const getUser = await user.get('/user');
expect(getUser.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1);
await user.post(`/tasks/${todo._id}/score/up`);
let updatedTask = await user.get(`/tasks/${todo._id}`);
const updatedTask = await user.get(`/tasks/${todo._id}`);
expect(updatedTask.completed).to.equal(true);
let updatedUser = await user.get('/user');
const updatedUser = await user.get('/user');
expect(updatedUser.tasksOrder.todos.indexOf(todo._id)).to.equal(-1);
});
it('moves un-completed todos back into user.tasksOrder.todos', async () => {
let getUser = await user.get('/user');
const getUser = await user.get('/user');
expect(getUser.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1);
await user.post(`/tasks/${todo._id}/score/up`);
await user.post(`/tasks/${todo._id}/score/down`);
let updatedTask = await user.get(`/tasks/${todo._id}`);
const updatedTask = await user.get(`/tasks/${todo._id}`);
expect(updatedTask.completed).to.equal(false);
let updatedUser = await user.get('/user');
let l = updatedUser.tasksOrder.todos.length;
const updatedUser = await user.get('/user');
const l = updatedUser.tasksOrder.todos.length;
expect(updatedUser.tasksOrder.todos.indexOf(todo._id)).not.to.equal(-1);
expect(updatedUser.tasksOrder.todos.indexOf(todo._id)).to.equal(l - 1); // Check that it was pushed at the bottom
// Check that it was pushed at the bottom
expect(updatedUser.tasksOrder.todos.indexOf(todo._id)).to.equal(l - 1);
});
it('uncompletes todo when direction is down', async () => {
await user.post(`/tasks/${todo._id}/score/up`);
await user.post(`/tasks/${todo._id}/score/down`);
let updatedTask = await user.get(`/tasks/${todo._id}`);
const updatedTask = await user.get(`/tasks/${todo._id}`);
expect(updatedTask.completed).to.equal(false);
expect(updatedTask.dateCompleted).to.be.a('undefined');
@@ -221,7 +222,8 @@ describe('POST /tasks/:id/score/:direction', () => {
});
context('user stats when direction is down', () => {
let updatedUser, initialUser;
let updatedUser; let
initialUser;
beforeEach(async () => {
await user.post(`/tasks/${todo._id}/score/up`);
@@ -256,7 +258,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('completes daily when direction is up', async () => {
await user.post(`/tasks/${daily._id}/score/up`);
let task = await user.get(`/tasks/${daily._id}`);
const task = await user.get(`/tasks/${daily._id}`);
expect(task.completed).to.equal(true);
});
@@ -264,21 +266,21 @@ describe('POST /tasks/:id/score/:direction', () => {
it('uncompletes daily when direction is down', async () => {
await user.post(`/tasks/${daily._id}/score/up`);
await user.post(`/tasks/${daily._id}/score/down`);
let task = await user.get(`/tasks/${daily._id}`);
const task = await user.get(`/tasks/${daily._id}`);
expect(task.completed).to.equal(false);
});
it('computes isDue', async () => {
await user.post(`/tasks/${daily._id}/score/up`);
let task = await user.get(`/tasks/${daily._id}`);
const task = await user.get(`/tasks/${daily._id}`);
expect(task.isDue).to.equal(true);
});
it('computes nextDue', async () => {
await user.post(`/tasks/${daily._id}/score/up`);
let task = await user.get(`/tasks/${daily._id}`);
const task = await user.get(`/tasks/${daily._id}`);
expect(task.nextDue.length).to.eql(6);
});
@@ -322,7 +324,8 @@ describe('POST /tasks/:id/score/:direction', () => {
});
context('user stats when direction is down', () => {
let updatedUser, initialUser;
let updatedUser; let
initialUser;
beforeEach(async () => {
await user.post(`/tasks/${daily._id}/score/up`);
@@ -346,7 +349,8 @@ describe('POST /tasks/:id/score/:direction', () => {
});
context('habits', () => {
let habit, minusHabit, plusHabit, neitherHabit; // eslint-disable-line no-unused-vars
let habit; let
neitherHabit; // eslint-disable-line no-unused-vars
beforeEach(async () => {
habit = await user.post('/tasks/user', {
@@ -354,18 +358,6 @@ describe('POST /tasks/:id/score/:direction', () => {
type: 'habit',
});
minusHabit = await user.post('/tasks/user', {
text: 'test min habit',
type: 'habit',
up: false,
});
plusHabit = await user.post('/tasks/user', {
text: 'test plus habit',
type: 'habit',
down: false,
});
neitherHabit = await user.post('/tasks/user', {
text: 'test neither habit',
type: 'habit',
@@ -380,40 +372,40 @@ describe('POST /tasks/:id/score/:direction', () => {
it('increases user\'s mp when direction is up', async () => {
await user.post(`/tasks/${habit._id}/score/up`);
let updatedUser = await user.get('/user');
const updatedUser = await user.get('/user');
expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp);
});
it('decreases user\'s mp when direction is down', async () => {
await user.post(`/tasks/${habit._id}/score/down`);
let updatedUser = await user.get('/user');
const updatedUser = await user.get('/user');
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
});
it('increases user\'s exp when direction is up', async () => {
await user.post(`/tasks/${habit._id}/score/up`);
let updatedUser = await user.get('/user');
const updatedUser = await user.get('/user');
expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp);
});
it('increases user\'s gold when direction is up', async () => {
await user.post(`/tasks/${habit._id}/score/up`);
let updatedUser = await user.get('/user');
const updatedUser = await user.get('/user');
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
});
// not supported anymore
it('does not add score notes to task', async () => {
let scoreNotesString = 'test-notes';
const scoreNotesString = 'test-notes';
await user.post(`/tasks/${habit._id}/score/up`, {
scoreNotes: scoreNotesString,
});
let updatedTask = await user.get(`/tasks/${habit._id}`);
const updatedTask = await user.get(`/tasks/${habit._id}`);
expect(updatedTask.history[0].scoreNotes).to.eql(undefined);
});
@@ -437,7 +429,8 @@ describe('POST /tasks/:id/score/:direction', () => {
});
context('reward', () => {
let reward, updatedUser;
let reward; let
updatedUser;
beforeEach(async () => {
reward = await user.post('/tasks/user', {

View File

@@ -1,8 +1,8 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /tasks/:taskId/move/to/:position', () => {
let user;
@@ -28,20 +28,20 @@ describe('POST /tasks/:taskId/move/to/:position', () => {
});
it('can move task to new position', async () => {
let tasks = await user.post('/tasks/user', [
{type: 'habit', text: 'habit 1'},
{type: 'habit', text: 'habit 2'},
{type: 'daily', text: 'daily 1'},
{type: 'habit', text: 'habit 3'},
{type: 'habit', text: 'habit 4'},
{type: 'todo', text: 'todo 1'},
{type: 'habit', text: 'habit 5'},
const tasks = await user.post('/tasks/user', [
{ type: 'habit', text: 'habit 1' },
{ type: 'habit', text: 'habit 2' },
{ type: 'daily', text: 'daily 1' },
{ type: 'habit', text: 'habit 3' },
{ type: 'habit', text: 'habit 4' },
{ type: 'todo', text: 'todo 1' },
{ type: 'habit', text: 'habit 5' },
]);
let taskToMove = tasks[1];
const taskToMove = tasks[1];
expect(taskToMove.text).to.equal('habit 2');
let newOrder = await user.post(`/tasks/${tasks[1]._id}/move/to/3`);
const newOrder = await user.post(`/tasks/${tasks[1]._id}/move/to/3`);
await user.sync();
expect(newOrder[3]).to.equal(taskToMove._id);
@@ -50,25 +50,25 @@ describe('POST /tasks/:taskId/move/to/:position', () => {
});
it('can move task to new position using alias', async () => {
let tasks = await user.post('/tasks/user', [
{type: 'habit', text: 'habit 1'},
{type: 'habit', text: 'habit 2', alias: 'move'},
{type: 'daily', text: 'daily 1'},
{type: 'habit', text: 'habit 3'},
{type: 'habit', text: 'habit 4'},
{type: 'todo', text: 'todo 1'},
{type: 'habit', text: 'habit 5'},
const tasks = await user.post('/tasks/user', [
{ type: 'habit', text: 'habit 1' },
{ type: 'habit', text: 'habit 2', alias: 'move' },
{ type: 'daily', text: 'daily 1' },
{ type: 'habit', text: 'habit 3' },
{ type: 'habit', text: 'habit 4' },
{ type: 'todo', text: 'todo 1' },
{ type: 'habit', text: 'habit 5' },
]);
let taskToMove = tasks[1];
const taskToMove = tasks[1];
expect(taskToMove.text).to.equal('habit 2');
let newOrder = await user.post(`/tasks/${taskToMove.alias}/move/to/3`);
const newOrder = await user.post(`/tasks/${taskToMove.alias}/move/to/3`);
expect(newOrder[3]).to.equal(taskToMove._id);
expect(newOrder.length).to.equal(5);
});
it('can\'t move completed todo', async () => {
let task = await user.post('/tasks/user', {type: 'todo', text: 'todo 1'});
const task = await user.post('/tasks/user', { type: 'todo', text: 'todo 1' });
await user.post(`/tasks/${task._id}/score/up`);
await expect(user.post(`/tasks/${task._id}/move/to/1`)).to.eventually.be.rejected.and.eql({
@@ -79,19 +79,19 @@ describe('POST /tasks/:taskId/move/to/:position', () => {
});
it('can push to bottom', async () => {
let tasks = await user.post('/tasks/user', [
{type: 'habit', text: 'habit 1'},
{type: 'habit', text: 'habit 2'},
{type: 'daily', text: 'daily 1'},
{type: 'habit', text: 'habit 3'},
{type: 'habit', text: 'habit 4'},
{type: 'todo', text: 'todo 1'},
{type: 'habit', text: 'habit 5'},
const tasks = await user.post('/tasks/user', [
{ type: 'habit', text: 'habit 1' },
{ type: 'habit', text: 'habit 2' },
{ type: 'daily', text: 'daily 1' },
{ type: 'habit', text: 'habit 3' },
{ type: 'habit', text: 'habit 4' },
{ type: 'todo', text: 'todo 1' },
{ type: 'habit', text: 'habit 5' },
]);
let taskToMove = tasks[1];
const taskToMove = tasks[1];
expect(taskToMove.text).to.equal('habit 2');
let newOrder = await user.post(`/tasks/${tasks[1]._id}/move/to/-1`);
const newOrder = await user.post(`/tasks/${tasks[1]._id}/move/to/-1`);
expect(newOrder[4]).to.equal(taskToMove._id);
expect(newOrder.length).to.equal(5);
});

View File

@@ -9,7 +9,7 @@ describe('POST /tasks/unlink-all/:challengeId', () => {
let user;
let guild;
let challenge;
let tasksToTest = {
const tasksToTest = {
habit: {
text: 'test habit',
type: 'habit',

View File

@@ -1,16 +1,16 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateGroup,
generateChallenge,
translate as t,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /tasks/unlink-one/:taskId', () => {
let user;
let guild;
let challenge;
let tasksToTest = {
const tasksToTest = {
habit: {
text: 'test habit',
type: 'habit',
@@ -70,7 +70,7 @@ describe('POST /tasks/unlink-one/:taskId', () => {
});
it('fails on task unlinked to challenge', async () => {
let daily = await user.post('/tasks/user', tasksToTest.daily);
const daily = await user.post('/tasks/user', tasksToTest.daily);
await expect(user.post(`/tasks/unlink-one/${daily._id}?keep=keep`))
.to.eventually.be.rejected.and.eql({
code: 400,
@@ -81,7 +81,7 @@ describe('POST /tasks/unlink-one/:taskId', () => {
it('fails on unbroken challenge', async () => {
await user.post(`/tasks/challenge/${challenge._id}`, tasksToTest.daily);
let [daily] = await user.get('/tasks/user');
const [daily] = await user.get('/tasks/user');
await expect(user.post(`/tasks/unlink-one/${daily._id}?keep=keep`))
.to.eventually.be.rejected.and.eql({
code: 400,
@@ -101,11 +101,11 @@ describe('POST /tasks/unlink-one/:taskId', () => {
it('unlinks a task from a challenge and deletes it on keep=remove', async () => {
await user.post(`/tasks/challenge/${challenge._id}`, tasksToTest.daily);
let [, daily] = await user.get('/tasks/user');
const [, daily] = await user.get('/tasks/user');
await user.del(`/challenges/${challenge._id}`);
await user.post(`/tasks/unlink-one/${daily._id}?keep=remove`);
const tasks = await user.get('/tasks/user');
// Only the default task should remain
expect(tasks.length).to.eql(1);
});
});
});

View File

@@ -1,10 +1,10 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
sleep,
translate as t,
server,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /tasks/user', () => {
let user;
@@ -36,8 +36,8 @@ describe('POST /tasks/user', () => {
it('returns an error if one object inside an array is invalid', async () => {
await expect(user.post('/tasks/user', [
{type: 'habitF'},
{type: 'habit'},
{ type: 'habitF' },
{ type: 'habit' },
])).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
@@ -56,7 +56,7 @@ describe('POST /tasks/user', () => {
});
it('does not update user.tasksOrder.{taskType} when the task is not saved because invalid', async () => {
let originalHabitsOrder = (await user.get('/user')).tasksOrder.habits;
const originalHabitsOrder = (await user.get('/user')).tasksOrder.habits;
await expect(user.post('/tasks/user', {
type: 'habit',
})).to.eventually.be.rejected.and.eql({
@@ -65,43 +65,43 @@ describe('POST /tasks/user', () => {
message: 'habit validation failed',
});
let updatedHabitsOrder = (await user.get('/user')).tasksOrder.habits;
const updatedHabitsOrder = (await user.get('/user')).tasksOrder.habits;
expect(updatedHabitsOrder).to.eql(originalHabitsOrder);
});
it('does not update user.tasksOrder.{taskType} when a task inside an array is not saved because invalid', async () => {
let originalHabitsOrder = (await user.get('/user')).tasksOrder.habits;
const originalHabitsOrder = (await user.get('/user')).tasksOrder.habits;
await expect(user.post('/tasks/user', [
{type: 'habit'}, // Missing text
{type: 'habit', text: 'valid'}, // Valid
{ type: 'habit' }, // Missing text
{ type: 'habit', text: 'valid' }, // Valid
])).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: 'habit validation failed',
});
let updatedHabitsOrder = (await user.get('/user')).tasksOrder.habits;
const updatedHabitsOrder = (await user.get('/user')).tasksOrder.habits;
expect(updatedHabitsOrder).to.eql(originalHabitsOrder);
});
it('does not save any task sent in an array when 1 is invalid', async () => {
let originalTasks = await user.get('/tasks/user');
const originalTasks = await user.get('/tasks/user');
await expect(user.post('/tasks/user', [
{type: 'habit'}, // Missing text
{type: 'habit', text: 'valid'}, // Valid
{ type: 'habit' }, // Missing text
{ type: 'habit', text: 'valid' }, // Valid
])).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: 'habit validation failed',
}).then(async () => {
let updatedTasks = await user.get('/tasks/user');
const updatedTasks = await user.get('/tasks/user');
expect(updatedTasks).to.eql(originalTasks);
});
});
it('automatically sets "task.userId" to user\'s uuid', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
});
@@ -112,7 +112,7 @@ describe('POST /tasks/user', () => {
it(`ignores setting userId, history, createdAt,
updatedAt, challenge, completed,
dateCompleted fields`, async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test daily',
type: 'daily',
userId: 123,
@@ -137,7 +137,7 @@ describe('POST /tasks/user', () => {
});
it('ignores invalid fields', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test daily',
type: 'daily',
notValid: true,
@@ -218,7 +218,7 @@ describe('POST /tasks/user', () => {
});
it('sends task activity webhooks', async () => {
let uuid = generateUUID();
const uuid = generateUUID();
await user.post('/user/webhook', {
url: `http://localhost:${server.port}/webhooks/${uuid}`,
@@ -229,20 +229,20 @@ describe('POST /tasks/user', () => {
},
});
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
});
await sleep();
let body = server.getWebhookData(uuid);
const body = server.getWebhookData(uuid);
expect(body.task).to.eql(task);
});
it('sends a task activity webhook for each task', async () => {
let uuid = generateUUID();
const uuid = generateUUID();
await user.post('/user/webhook', {
url: `http://localhost:${server.port}/webhooks/${uuid}`,
@@ -253,7 +253,7 @@ describe('POST /tasks/user', () => {
},
});
let tasks = await user.post('/tasks/user', [{
const tasks = await user.post('/tasks/user', [{
text: 'test habit',
type: 'habit',
}, {
@@ -263,7 +263,7 @@ describe('POST /tasks/user', () => {
await sleep();
let taskBodies = [
const taskBodies = [
server.getWebhookData(uuid),
server.getWebhookData(uuid),
];
@@ -275,13 +275,13 @@ describe('POST /tasks/user', () => {
context('all types', () => {
it('can create reminders', async () => {
let id1 = generateUUID();
const id1 = generateUUID();
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
reminders: [
{id: id1, startDate: new Date(), time: new Date()},
{ id: id1, startDate: new Date(), time: new Date() },
],
});
@@ -294,7 +294,7 @@ describe('POST /tasks/user', () => {
});
it('can create a task with a alias', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
alias: 'a_alias012',
@@ -305,7 +305,7 @@ describe('POST /tasks/user', () => {
// This is a special case for iOS requests
it('will round a priority (difficulty)', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
priority: 0.10000000000005,
@@ -317,7 +317,7 @@ describe('POST /tasks/user', () => {
context('habits', () => {
it('creates a habit', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
up: false,
@@ -334,20 +334,20 @@ describe('POST /tasks/user', () => {
});
it('updates user.tasksOrder.habits when a new habit is created', async () => {
let originalHabitsOrderLen = (await user.get('/user')).tasksOrder.habits.length;
let task = await user.post('/tasks/user', {
const originalHabitsOrderLen = (await user.get('/user')).tasksOrder.habits.length;
const task = await user.post('/tasks/user', {
type: 'habit',
text: 'an habit',
});
let updatedUser = await user.get('/user');
const updatedUser = await user.get('/user');
expect(updatedUser.tasksOrder.habits[0]).to.eql(task._id);
expect(updatedUser.tasksOrder.habits.length).to.eql(originalHabitsOrderLen + 1);
});
it('updates user.tasksOrder.habits when multiple habits are created', async () => {
let originalHabitsOrderLen = (await user.get('/user')).tasksOrder.habits.length;
let [task, task2] = await user.post('/tasks/user', [{
const originalHabitsOrderLen = (await user.get('/user')).tasksOrder.habits.length;
const [task, task2] = await user.post('/tasks/user', [{
type: 'habit',
text: 'an habit',
}, {
@@ -355,14 +355,14 @@ describe('POST /tasks/user', () => {
text: 'another habit',
}]);
let updatedUser = await user.get('/user');
const updatedUser = await user.get('/user');
expect(updatedUser.tasksOrder.habits[0]).to.eql(task2._id);
expect(updatedUser.tasksOrder.habits[1]).to.eql(task._id);
expect(updatedUser.tasksOrder.habits.length).to.eql(originalHabitsOrderLen + 2);
});
it('creates multiple habits', async () => {
let [task, task2] = await user.post('/tasks/user', [{
const [task, task2] = await user.post('/tasks/user', [{
text: 'test habit',
type: 'habit',
up: false,
@@ -392,7 +392,7 @@ describe('POST /tasks/user', () => {
});
it('defaults to setting up and down to true', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
notes: 1976,
@@ -403,11 +403,11 @@ describe('POST /tasks/user', () => {
});
it('cannot create checklists', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
checklist: [
{_id: 123, completed: false, text: 'checklist'},
{ _id: 123, completed: false, text: 'checklist' },
],
});
@@ -417,7 +417,7 @@ describe('POST /tasks/user', () => {
context('todos', () => {
it('creates a todo', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test todo',
type: 'todo',
notes: 1976,
@@ -430,7 +430,7 @@ describe('POST /tasks/user', () => {
});
it('creates multiple todos', async () => {
let [task, task2] = await user.post('/tasks/user', [{
const [task, task2] = await user.post('/tasks/user', [{
text: 'test todo',
type: 'todo',
notes: 1976,
@@ -452,20 +452,20 @@ describe('POST /tasks/user', () => {
});
it('updates user.tasksOrder.todos when a new todo is created', async () => {
let originalTodosOrderLen = (await user.get('/user')).tasksOrder.todos.length;
let task = await user.post('/tasks/user', {
const originalTodosOrderLen = (await user.get('/user')).tasksOrder.todos.length;
const task = await user.post('/tasks/user', {
type: 'todo',
text: 'a todo',
});
let updatedUser = await user.get('/user');
const updatedUser = await user.get('/user');
expect(updatedUser.tasksOrder.todos[0]).to.eql(task._id);
expect(updatedUser.tasksOrder.todos.length).to.eql(originalTodosOrderLen + 1);
});
it('updates user.tasksOrder.todos when multiple todos are created', async () => {
let originalTodosOrderLen = (await user.get('/user')).tasksOrder.todos.length;
let [task, task2] = await user.post('/tasks/user', [{
const originalTodosOrderLen = (await user.get('/user')).tasksOrder.todos.length;
const [task, task2] = await user.post('/tasks/user', [{
type: 'todo',
text: 'a todo',
}, {
@@ -473,18 +473,18 @@ describe('POST /tasks/user', () => {
text: 'another todo',
}]);
let updatedUser = await user.get('/user');
const updatedUser = await user.get('/user');
expect(updatedUser.tasksOrder.todos[0]).to.eql(task2._id);
expect(updatedUser.tasksOrder.todos[1]).to.eql(task._id);
expect(updatedUser.tasksOrder.todos.length).to.eql(originalTodosOrderLen + 2);
});
it('can create checklists', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test todo',
type: 'todo',
checklist: [
{completed: false, text: 'checklist'},
{ completed: false, text: 'checklist' },
],
});
@@ -499,9 +499,9 @@ describe('POST /tasks/user', () => {
context('dailys', () => {
it('creates a daily', async () => {
let now = new Date();
const now = new Date();
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test daily',
type: 'daily',
notes: 1976,
@@ -526,7 +526,7 @@ describe('POST /tasks/user', () => {
});
it('creates multiple dailys', async () => {
let [task, task2] = await user.post('/tasks/user', [{
const [task, task2] = await user.post('/tasks/user', [{
text: 'test daily',
type: 'daily',
notes: 1976,
@@ -548,20 +548,20 @@ describe('POST /tasks/user', () => {
});
it('updates user.tasksOrder.dailys when a new daily is created', async () => {
let originalDailysOrderLen = (await user.get('/user')).tasksOrder.dailys.length;
let task = await user.post('/tasks/user', {
const originalDailysOrderLen = (await user.get('/user')).tasksOrder.dailys.length;
const task = await user.post('/tasks/user', {
type: 'daily',
text: 'a daily',
});
let updatedUser = await user.get('/user');
const updatedUser = await user.get('/user');
expect(updatedUser.tasksOrder.dailys[0]).to.eql(task._id);
expect(updatedUser.tasksOrder.dailys.length).to.eql(originalDailysOrderLen + 1);
});
it('updates user.tasksOrder.dailys when multiple dailys are created', async () => {
let originalDailysOrderLen = (await user.get('/user')).tasksOrder.dailys.length;
let [task, task2] = await user.post('/tasks/user', [{
const originalDailysOrderLen = (await user.get('/user')).tasksOrder.dailys.length;
const [task, task2] = await user.post('/tasks/user', [{
type: 'daily',
text: 'a daily',
}, {
@@ -569,14 +569,14 @@ describe('POST /tasks/user', () => {
text: 'another daily',
}]);
let updatedUser = await user.get('/user');
const updatedUser = await user.get('/user');
expect(updatedUser.tasksOrder.dailys[0]).to.eql(task2._id);
expect(updatedUser.tasksOrder.dailys[1]).to.eql(task._id);
expect(updatedUser.tasksOrder.dailys.length).to.eql(originalDailysOrderLen + 2);
});
it('defaults to a weekly frequency, with every day set', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test daily',
type: 'daily',
});
@@ -595,7 +595,7 @@ describe('POST /tasks/user', () => {
});
it('allows repeat field to be configured', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test daily',
type: 'daily',
repeat: {
@@ -617,9 +617,9 @@ describe('POST /tasks/user', () => {
});
it('defaults startDate to today', async () => {
let today = (new Date()).getDay();
const today = (new Date()).getDay();
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test daily',
type: 'daily',
});
@@ -677,11 +677,11 @@ describe('POST /tasks/user', () => {
it('can create checklists', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test daily',
type: 'daily',
checklist: [
{completed: false, text: 'checklist'},
{ completed: false, text: 'checklist' },
],
});
@@ -696,7 +696,7 @@ describe('POST /tasks/user', () => {
context('rewards', () => {
it('creates a reward', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test reward',
type: 'reward',
notes: 1976,
@@ -711,7 +711,7 @@ describe('POST /tasks/user', () => {
});
it('creates multiple rewards', async () => {
let [task, task2] = await user.post('/tasks/user', [{
const [task, task2] = await user.post('/tasks/user', [{
text: 'test reward',
type: 'reward',
notes: 1976,
@@ -737,20 +737,20 @@ describe('POST /tasks/user', () => {
});
it('updates user.tasksOrder.rewards when a new reward is created', async () => {
let originalRewardsOrderLen = (await user.get('/user')).tasksOrder.rewards.length;
let task = await user.post('/tasks/user', {
const originalRewardsOrderLen = (await user.get('/user')).tasksOrder.rewards.length;
const task = await user.post('/tasks/user', {
type: 'reward',
text: 'a reward',
});
let updatedUser = await user.get('/user');
const updatedUser = await user.get('/user');
expect(updatedUser.tasksOrder.rewards[0]).to.eql(task._id);
expect(updatedUser.tasksOrder.rewards.length).to.eql(originalRewardsOrderLen + 1);
});
it('updates user.tasksOrder.dreward when multiple rewards are created', async () => {
let originalRewardsOrderLen = (await user.get('/user')).tasksOrder.rewards.length;
let [task, task2] = await user.post('/tasks/user', [{
const originalRewardsOrderLen = (await user.get('/user')).tasksOrder.rewards.length;
const [task, task2] = await user.post('/tasks/user', [{
type: 'reward',
text: 'a reward',
}, {
@@ -758,14 +758,14 @@ describe('POST /tasks/user', () => {
text: 'another reward',
}]);
let updatedUser = await user.get('/user');
const updatedUser = await user.get('/user');
expect(updatedUser.tasksOrder.rewards[0]).to.eql(task2._id);
expect(updatedUser.tasksOrder.rewards[1]).to.eql(task._id);
expect(updatedUser.tasksOrder.rewards.length).to.eql(originalRewardsOrderLen + 2);
});
it('defaults to a 0 value', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test reward',
type: 'reward',
});
@@ -774,7 +774,7 @@ describe('POST /tasks/user', () => {
});
it('requires value to be coerced into a number', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test reward',
type: 'reward',
value: '10',
@@ -784,11 +784,11 @@ describe('POST /tasks/user', () => {
});
it('cannot create checklists', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test reward',
type: 'reward',
checklist: [
{_id: 123, completed: false, text: 'checklist'},
{ _id: 123, completed: false, text: 'checklist' },
],
});

View File

@@ -1,4 +1,5 @@
import moment from 'moment';
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateGroup,
@@ -6,7 +7,6 @@ import {
generateChallenge,
server,
} from '../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('PUT /tasks/:id', () => {
let user;
@@ -28,7 +28,7 @@ describe('PUT /tasks/:id', () => {
it(`ignores setting _id, type, userId, history, createdAt,
updatedAt, challenge, completed, streak,
dateCompleted fields`, async () => {
let savedTask = await user.put(`/tasks/${task._id}`, {
const savedTask = await user.put(`/tasks/${task._id}`, {
_id: 123,
type: 'daily',
userId: 123,
@@ -54,7 +54,7 @@ describe('PUT /tasks/:id', () => {
});
it('ignores invalid fields', async () => {
let savedTask = await user.put(`/tasks/${task._id}`, {
const savedTask = await user.put(`/tasks/${task._id}`, {
notValid: true,
});
@@ -63,18 +63,18 @@ describe('PUT /tasks/:id', () => {
it(`only allows setting streak, alias, reminders, checklist, notes, attribute, tags
fields for challenge tasks owned by a user`, async () => {
let guild = await generateGroup(user);
let challenge = await generateChallenge(user, guild);
const guild = await generateGroup(user);
const challenge = await generateChallenge(user, guild);
await user.post(`/challenges/${challenge._id}/join`);
let challengeTask = await user.post(`/tasks/challenge/${challenge._id}`, {
const challengeTask = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'daily',
text: 'Daily in challenge',
reminders: [
{time: new Date(), startDate: new Date()},
{ time: new Date(), startDate: new Date() },
],
checklist: [
{text: 123, completed: false},
{ text: 123, completed: false },
],
collapseChecklist: false,
});
@@ -83,11 +83,11 @@ describe('PUT /tasks/:id', () => {
await user.sync();
// Pick challenge task
let challengeUserTaskId = user.tasksOrder.dailys[user.tasksOrder.dailys.length - 1];
const challengeUserTaskId = user.tasksOrder.dailys[user.tasksOrder.dailys.length - 1];
let challengeUserTask = await user.get(`/tasks/${challengeUserTaskId}`);
const challengeUserTask = await user.get(`/tasks/${challengeUserTaskId}`);
let savedChallengeUserTask = await user.put(`/tasks/${challengeUserTaskId}`, {
const savedChallengeUserTask = await user.put(`/tasks/${challengeUserTaskId}`, {
_id: 123,
type: 'daily',
userId: 123,
@@ -107,12 +107,12 @@ describe('PUT /tasks/:id', () => {
text: 'new text',
dateCompleted: 'never',
reminders: [
{time: new Date(), startDate: new Date()},
{time: new Date(), startDate: new Date()},
{ time: new Date(), startDate: new Date() },
{ time: new Date(), startDate: new Date() },
],
checklist: [
{text: 123, completed: false},
{text: 456, completed: true},
{ text: 123, completed: false },
{ text: 456, completed: true },
],
collapseChecklist: true,
notes: 'new notes',
@@ -121,7 +121,7 @@ describe('PUT /tasks/:id', () => {
});
// original task is not touched
let updatedChallengeTask = await user.get(`/tasks/${challengeTask._id}`);
const updatedChallengeTask = await user.get(`/tasks/${challengeTask._id}`);
expect(updatedChallengeTask).to.eql(challengeTask);
// ignored
@@ -134,7 +134,8 @@ describe('PUT /tasks/:id', () => {
expect(savedChallengeUserTask.text).to.equal(challengeUserTask.text);
expect(savedChallengeUserTask.history).to.eql(challengeUserTask.history);
expect(savedChallengeUserTask.createdAt).to.equal(challengeUserTask.createdAt);
expect(new Date(savedChallengeUserTask.updatedAt)).to.be.greaterThan(new Date(challengeUserTask.updatedAt));
expect(new Date(savedChallengeUserTask.updatedAt))
.to.be.greaterThan(new Date(challengeUserTask.updatedAt));
expect(savedChallengeUserTask.challenge).to.eql(challengeUserTask.challenge);
expect(savedChallengeUserTask.completed).to.equal(challengeUserTask.completed);
expect(savedChallengeUserTask.dateCompleted).to.equal(challengeUserTask.dateCompleted);
@@ -162,7 +163,7 @@ describe('PUT /tasks/:id', () => {
});
it('sends task activity webhooks if task is user owned', async () => {
let uuid = generateUUID();
const uuid = generateUUID();
await user.post('/user/webhook', {
url: `http://localhost:${server.port}/webhooks/${uuid}`,
@@ -174,31 +175,31 @@ describe('PUT /tasks/:id', () => {
},
});
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
});
let updatedTask = await user.put(`/tasks/${task.id}`, {
const updatedTask = await user.put(`/tasks/${task.id}`, {
text: 'updated text',
});
await sleep();
let body = server.getWebhookData(uuid);
const body = server.getWebhookData(uuid);
expect(body.type).to.eql('updated');
expect(body.task).to.eql(updatedTask);
});
it('does not send task activity webhooks if task is not user owned', async () => {
let uuid = generateUUID();
const uuid = generateUUID();
await user.update({
balance: 10,
});
let guild = await generateGroup(user);
let challenge = await generateChallenge(user, guild);
const guild = await generateGroup(user);
const challenge = await generateChallenge(user, guild);
await user.post(`/challenges/${challenge._id}/join`);
await user.post('/user/webhook', {
@@ -211,7 +212,7 @@ describe('PUT /tasks/:id', () => {
},
});
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
text: 'test habit',
type: 'habit',
});
@@ -222,7 +223,7 @@ describe('PUT /tasks/:id', () => {
await sleep();
let body = server.getWebhookData(uuid);
const body = server.getWebhookData(uuid);
expect(body).to.not.exist;
});
@@ -242,17 +243,17 @@ describe('PUT /tasks/:id', () => {
it('can update reminders (replace them)', async () => {
await user.put(`/tasks/${daily._id}`, {
reminders: [
{time: new Date(), startDate: new Date()},
{ time: new Date(), startDate: new Date() },
],
});
let id1 = generateUUID();
let id2 = generateUUID();
const id1 = generateUUID();
const id2 = generateUUID();
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
reminders: [
{id: id1, time: new Date(), startDate: new Date()},
{id: id2, time: new Date(), startDate: new Date()},
{ id: id1, time: new Date(), startDate: new Date() },
{ id: id2, time: new Date(), startDate: new Date() },
],
});
@@ -262,7 +263,7 @@ describe('PUT /tasks/:id', () => {
});
it('can set a alias if no other task has that alias', async () => {
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
alias: 'alias',
});
@@ -294,7 +295,7 @@ describe('PUT /tasks/:id', () => {
text: 'saved',
});
let fetchedDaily = await user.get(`/tasks/${daily._id}`);
const fetchedDaily = await user.get(`/tasks/${daily._id}`);
expect(fetchedDaily.text).to.eql('saved');
});
@@ -322,7 +323,7 @@ describe('PUT /tasks/:id', () => {
});
it('updates a habit', async () => {
let savedHabit = await user.put(`/tasks/${habit._id}`, {
const savedHabit = await user.put(`/tasks/${habit._id}`, {
text: 'some new text',
up: false,
down: false,
@@ -348,7 +349,7 @@ describe('PUT /tasks/:id', () => {
});
it('updates a todo', async () => {
let savedTodo = await user.put(`/tasks/${todo._id}`, {
const savedTodo = await user.put(`/tasks/${todo._id}`, {
text: 'some new text',
notes: 'some new notes',
});
@@ -360,14 +361,14 @@ describe('PUT /tasks/:id', () => {
it('can update checklists (replace it)', async () => {
await user.put(`/tasks/${todo._id}`, {
checklist: [
{text: 123, completed: false},
{text: 456, completed: true},
{ text: 123, completed: false },
{ text: 456, completed: true },
],
});
let savedTodo = await user.put(`/tasks/${todo._id}`, {
const savedTodo = await user.put(`/tasks/${todo._id}`, {
checklist: [
{text: 789, completed: false},
{ text: 789, completed: false },
],
});
@@ -377,12 +378,12 @@ describe('PUT /tasks/:id', () => {
});
it('can update tags (replace them)', async () => {
let finalUUID = generateUUID();
const finalUUID = generateUUID();
await user.put(`/tasks/${todo._id}`, {
tags: [generateUUID(), generateUUID()],
});
let savedTodo = await user.put(`/tasks/${todo._id}`, {
const savedTodo = await user.put(`/tasks/${todo._id}`, {
tags: [finalUUID],
});
@@ -403,7 +404,7 @@ describe('PUT /tasks/:id', () => {
});
it('updates a daily', async () => {
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
text: 'some new text',
notes: 'some new notes',
frequency: 'daily',
@@ -424,14 +425,14 @@ describe('PUT /tasks/:id', () => {
it('can update checklists (replace it)', async () => {
await user.put(`/tasks/${daily._id}`, {
checklist: [
{text: 123, completed: false},
{text: 456, completed: true},
{ text: 123, completed: false },
{ text: 456, completed: true },
],
});
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
checklist: [
{text: 789, completed: false},
{ text: 789, completed: false },
],
});
@@ -441,12 +442,12 @@ describe('PUT /tasks/:id', () => {
});
it('can update tags (replace them)', async () => {
let finalUUID = generateUUID();
const finalUUID = generateUUID();
await user.put(`/tasks/${daily._id}`, {
tags: [generateUUID(), generateUUID()],
});
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
tags: [finalUUID],
});
@@ -459,7 +460,7 @@ describe('PUT /tasks/:id', () => {
frequency: 'daily',
});
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
repeat: {
m: false,
su: false,
@@ -482,7 +483,7 @@ describe('PUT /tasks/:id', () => {
frequency: 'weekly',
});
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
everyX: 5,
});
@@ -490,7 +491,7 @@ describe('PUT /tasks/:id', () => {
});
it('defaults startDate to today if none date object is passed in', async () => {
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
frequency: 'weekly',
});
@@ -511,7 +512,7 @@ describe('PUT /tasks/:id', () => {
});
it('updates a reward', async () => {
let savedReward = await user.put(`/tasks/${reward._id}`, {
const savedReward = await user.put(`/tasks/${reward._id}`, {
text: 'some new text',
notes: 'some new notes',
value: 10,
@@ -523,7 +524,7 @@ describe('PUT /tasks/:id', () => {
});
it('requires value to be coerced into a number', async () => {
let savedReward = await user.put(`/tasks/${reward._id}`, {
const savedReward = await user.put(`/tasks/${reward._id}`, {
value: '100',
});

View File

@@ -1,10 +1,10 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateGroup,
generateChallenge,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
let user;
@@ -27,7 +27,7 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on checklist item not found', async () => {
let createdTask = await user.post(`/tasks/challenge/${challenge._id}`, {
const createdTask = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'daily',
text: 'daily with checklist',
});
@@ -40,17 +40,17 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
});
it('returns error when user is not a member of the challenge', async () => {
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'daily',
text: 'Daily with checklist',
});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, {
const savedTask = await user.post(`/tasks/${task._id}/checklist`, {
text: 'Checklist Item 1',
completed: false,
});
let anotherUser = await generateUser();
const anotherUser = await generateUser();
await expect(anotherUser.del(`/tasks/${task._id}/checklist/${savedTask.checklist[0].id}`))
.to.eventually.be.rejected.and.eql({
@@ -61,12 +61,12 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
});
it('deletes a checklist item from a daily', async () => {
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'daily',
text: 'Daily with checklist',
});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, {text: 'Checklist Item 1', completed: false});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, { text: 'Checklist Item 1', completed: false });
await user.del(`/tasks/${task._id}/checklist/${savedTask.checklist[0].id}`);
savedTask = await user.get(`/tasks/${task._id}`);
@@ -75,12 +75,12 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
});
it('deletes a checklist item from a todo', async () => {
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'todo',
text: 'Todo with checklist',
});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, {text: 'Checklist Item 1', completed: false});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, { text: 'Checklist Item 1', completed: false });
await user.del(`/tasks/${task._id}/checklist/${savedTask.checklist[0].id}`);
savedTask = await user.get(`/tasks/${task._id}`);
@@ -89,7 +89,7 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
});
it('does not work with habits', async () => {
let habit = await user.post(`/tasks/challenge/${challenge._id}`, {
const habit = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'habit',
text: 'habit with checklist',
});
@@ -102,7 +102,7 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
});
it('does not work with rewards', async () => {
let reward = await user.post(`/tasks/challenge/${challenge._id}`, {
const reward = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'reward',
text: 'reward with checklist',
});

View File

@@ -1,3 +1,4 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateGroup,
@@ -5,7 +6,6 @@ import {
sleep,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('DELETE /tasks/:id', () => {
let user;
@@ -36,7 +36,7 @@ describe('DELETE /tasks/:id', () => {
});
it('returns error when user is not leader of the challenge', async () => {
let anotherUser = await generateUser();
const anotherUser = await generateUser();
await expect(anotherUser.del(`/tasks/${task._id}`)).to.eventually.be.rejected.and.eql({
code: 401,
@@ -71,8 +71,9 @@ describe('DELETE /tasks/:id', () => {
type: 'habit',
});
let anotherUserWithNewChallengeTask = await anotherUser.get('/user');
anotherUsersNewChallengeTaskID = anotherUserWithNewChallengeTask.tasksOrder.habits[0];
const anotherUserWithNewChallengeTask = await anotherUser.get('/user');
anotherUsersNewChallengeTaskID = anotherUserWithNewChallengeTask // eslint-disable-line prefer-destructuring, max-len
.tasksOrder.habits[0];
});
it('returns error when user attempts to delete an active challenge task', async () => {
@@ -96,7 +97,8 @@ describe('DELETE /tasks/:id', () => {
});
});
// TODO for some reason this test fails on TravisCI, review after mongodb indexes have been added
// TODO for some reason this test fails on TravisCI,
// review after mongodb indexes have been added
xit('allows user to delete challenge task after challenge task is broken', async () => {
await expect(user.del(`/tasks/${newChallengeTask._id}`));

View File

@@ -1,20 +1,20 @@
import { v4 as generateUUID } from 'uuid';
import { each } from 'lodash';
import {
generateUser,
generateGroup,
generateChallenge,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
import { each } from 'lodash';
describe('GET /tasks/challenge/:challengeId', () => {
let user;
let guild;
let challenge;
let task;
let tasks = [];
const tasks = [];
let challengeWithTask;
let tasksToTest = {
const tasksToTest = {
habit: {
text: 'test habit',
type: 'habit',
@@ -46,7 +46,7 @@ describe('GET /tasks/challenge/:challengeId', () => {
});
it('returns error when challenge is not found', async () => {
let dummyId = generateUUID();
const dummyId = generateUUID();
await expect(user.get(`/tasks/challenge/${dummyId}`)).to.eventually.be.rejected.and.eql({
code: 404,
@@ -64,17 +64,17 @@ describe('GET /tasks/challenge/:challengeId', () => {
});
it('gets challenge tasks', async () => {
let getTask = await user.get(`/tasks/challenge/${challengeWithTask._id}`);
const getTask = await user.get(`/tasks/challenge/${challengeWithTask._id}`);
expect(getTask).to.eql(tasks);
});
it('gets challenge tasks filtered by type', async () => {
let challengeTasks = await user.get(`/tasks/challenge/${challengeWithTask._id}?type=${task.type}s`);
const challengeTasks = await user.get(`/tasks/challenge/${challengeWithTask._id}?type=${task.type}s`);
expect(challengeTasks).to.eql([task]);
});
it('cannot get a task owned by someone else', async () => {
let anotherUser = await generateUser();
const anotherUser = await generateUser();
await expect(anotherUser.get(`/tasks/challenge/${challengeWithTask._id}`)).to.eventually.be.rejected.and.eql({
code: 404,

View File

@@ -1,10 +1,10 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateGroup,
generateChallenge,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /tasks/:taskId/checklist/', () => {
let user;
@@ -29,12 +29,12 @@ describe('POST /tasks/:taskId/checklist/', () => {
});
it('returns error when user is not a member of the challenge', async () => {
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'daily',
text: 'Daily with checklist',
});
let anotherUser = await generateUser();
const anotherUser = await generateUser();
await expect(anotherUser.post(`/tasks/${task._id}/checklist`, {
text: 'Checklist Item 1',
@@ -49,12 +49,12 @@ describe('POST /tasks/:taskId/checklist/', () => {
});
it('adds a checklist item to a daily', async () => {
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'daily',
text: 'Daily with checklist',
});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, {
const savedTask = await user.post(`/tasks/${task._id}/checklist`, {
text: 'Checklist Item 1',
ignored: false,
_id: 123,
@@ -69,12 +69,12 @@ describe('POST /tasks/:taskId/checklist/', () => {
});
it('adds a checklist item to a todo', async () => {
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'todo',
text: 'Todo with checklist',
});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, {
const savedTask = await user.post(`/tasks/${task._id}/checklist`, {
text: 'Checklist Item 1',
ignored: false,
_id: 123,
@@ -89,7 +89,7 @@ describe('POST /tasks/:taskId/checklist/', () => {
});
it('does not add a checklist to habits', async () => {
let habit = await user.post(`/tasks/challenge/${challenge._id}`, {
const habit = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'habit',
text: 'habit with checklist',
});
@@ -104,7 +104,7 @@ describe('POST /tasks/:taskId/checklist/', () => {
});
it('does not add a checklist to rewards', async () => {
let reward = await user.post(`/tasks/challenge/${challenge._id}`, {
const reward = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'reward',
text: 'reward with checklist',
});

View File

@@ -1,11 +1,11 @@
import { v4 as generateUUID } from 'uuid';
import { find } from 'lodash';
import {
generateUser,
generateGroup,
generateChallenge,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
import { find } from 'lodash';
describe('POST /tasks/challenge/:challengeId', () => {
let user;
@@ -17,14 +17,14 @@ describe('POST /tasks/challenge/:challengeId', () => {
}
beforeEach(async () => {
user = await generateUser({balance: 1});
user = await generateUser({ balance: 1 });
guild = await generateGroup(user);
challenge = await generateChallenge(user, guild);
await user.post(`/challenges/${challenge._id}/join`);
});
it('returns error when challenge is not found', async () => {
let fakeChallengeId = generateUUID();
const fakeChallengeId = generateUUID();
await expect(user.post(`/tasks/challenge/${fakeChallengeId}`, {
text: 'test habit',
@@ -41,7 +41,7 @@ describe('POST /tasks/challenge/:challengeId', () => {
it('allows leader to add tasks to a challenge when not a member', async () => {
await user.post(`/challenges/${challenge._id}/leave`);
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
text: 'test habit',
type: 'habit',
up: false,
@@ -49,14 +49,14 @@ describe('POST /tasks/challenge/:challengeId', () => {
notes: 1976,
});
let {tasksOrder} = await user.get(`/challenges/${challenge._id}`);
const { tasksOrder } = await user.get(`/challenges/${challenge._id}`);
expect(tasksOrder.habits).to.include(task.id);
});
it('allows non-leader admin to add tasks to a challenge when not a member', async () => {
const admin = await generateUser({'contributor.admin': true});
let task = await admin.post(`/tasks/challenge/${challenge._id}`, {
const admin = await generateUser({ 'contributor.admin': true });
const task = await admin.post(`/tasks/challenge/${challenge._id}`, {
text: 'test habit from admin',
type: 'habit',
up: false,
@@ -64,7 +64,7 @@ describe('POST /tasks/challenge/:challengeId', () => {
notes: 1976,
});
let {tasksOrder} = await user.get(`/challenges/${challenge._id}`);
const { tasksOrder } = await user.get(`/challenges/${challenge._id}`);
expect(tasksOrder.habits).to.include(task.id);
});
@@ -82,7 +82,7 @@ describe('POST /tasks/challenge/:challengeId', () => {
});
it('returns error when non leader tries to edit challenge', async () => {
let userThatIsNotLeaderOfChallenge = await generateUser({
const userThatIsNotLeaderOfChallenge = await generateUser({
challenges: [challenge._id],
});
@@ -100,17 +100,17 @@ describe('POST /tasks/challenge/:challengeId', () => {
});
it('creates a habit', async () => {
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
text: 'test habit',
type: 'habit',
up: false,
down: true,
notes: 1976,
});
let challengeWithTask = await user.get(`/challenges/${challenge._id}`);
const challengeWithTask = await user.get(`/challenges/${challenge._id}`);
let memberTasks = await user.get('/tasks/user');
let userChallengeTask = find(memberTasks, findUserChallengeTask);
const memberTasks = await user.get('/tasks/user');
const userChallengeTask = find(memberTasks, findUserChallengeTask);
expect(challengeWithTask.tasksOrder.habits.indexOf(task._id)).to.be.above(-1);
expect(task.challenge.id).to.equal(challenge._id);
@@ -124,15 +124,15 @@ describe('POST /tasks/challenge/:challengeId', () => {
});
it('creates a todo', async () => {
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
text: 'test todo',
type: 'todo',
notes: 1976,
});
let challengeWithTask = await user.get(`/challenges/${challenge._id}`);
const challengeWithTask = await user.get(`/challenges/${challenge._id}`);
let memberTasks = await user.get('/tasks/user');
let userChallengeTask = find(memberTasks, findUserChallengeTask);
const memberTasks = await user.get('/tasks/user');
const userChallengeTask = find(memberTasks, findUserChallengeTask);
expect(challengeWithTask.tasksOrder.todos.indexOf(task._id)).to.be.above(-1);
expect(task.challenge.id).to.equal(challenge._id);
@@ -144,8 +144,8 @@ describe('POST /tasks/challenge/:challengeId', () => {
});
it('creates a daily', async () => {
let now = new Date();
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const now = new Date();
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
text: 'test daily',
type: 'daily',
notes: 1976,
@@ -153,10 +153,10 @@ describe('POST /tasks/challenge/:challengeId', () => {
everyX: 5,
startDate: now,
});
let challengeWithTask = await user.get(`/challenges/${challenge._id}`);
const challengeWithTask = await user.get(`/challenges/${challenge._id}`);
let memberTasks = await user.get('/tasks/user');
let userChallengeTask = find(memberTasks, findUserChallengeTask);
const memberTasks = await user.get('/tasks/user');
const userChallengeTask = find(memberTasks, findUserChallengeTask);
expect(challengeWithTask.tasksOrder.dailys.indexOf(task._id)).to.be.above(-1);
expect(task.challenge.id).to.equal(challenge._id);

View File

@@ -1,10 +1,10 @@
import { find } from 'lodash';
import {
generateUser,
generateGroup,
generateChallenge,
sleep,
} from '../../../../../helpers/api-integration/v3';
import { find } from 'lodash';
describe('POST /tasks/:id/score/:direction', () => {
let user;
@@ -29,16 +29,16 @@ describe('POST /tasks/:id/score/:direction', () => {
type: 'habit',
});
await sleep(1);
let updatedUser = await user.get('/user');
usersChallengeTaskId = updatedUser.tasksOrder.habits[0];
const updatedUser = await user.get('/user');
usersChallengeTaskId = updatedUser.tasksOrder.habits[0]; // eslint-disable-line prefer-destructuring, max-len
});
it('scores and adds history', async () => {
await user.post(`/tasks/${usersChallengeTaskId}/score/up`);
let tasks = await user.get(`/tasks/challenge/${challenge._id}`);
let task = find(tasks, {_id: habit._id});
previousTaskHistory = task.history[0];
const tasks = await user.get(`/tasks/challenge/${challenge._id}`);
const task = find(tasks, { _id: habit._id });
previousTaskHistory = task.history[0]; // eslint-disable-line prefer-destructuring, max-len
expect(task.value).to.equal(1);
expect(task.history).to.have.lengthOf(1);
@@ -47,8 +47,8 @@ describe('POST /tasks/:id/score/:direction', () => {
it('should update the history', async () => {
await user.post(`/tasks/${usersChallengeTaskId}/score/up`);
let tasks = await user.get(`/tasks/challenge/${challenge._id}`);
let task = find(tasks, {_id: habit._id});
const tasks = await user.get(`/tasks/challenge/${challenge._id}`);
const task = find(tasks, { _id: habit._id });
expect(task.history).to.have.lengthOf(1);
expect(task.history[0].date).to.not.equal(previousTaskHistory.date);
@@ -67,23 +67,23 @@ describe('POST /tasks/:id/score/:direction', () => {
type: 'daily',
});
await sleep(1);
let updatedUser = await user.get('/user');
usersChallengeTaskId = updatedUser.tasksOrder.dailys[0];
const updatedUser = await user.get('/user');
usersChallengeTaskId = updatedUser.tasksOrder.dailys[0]; // eslint-disable-line prefer-destructuring, max-len
});
it('it scores and adds history', async () => {
await user.post(`/tasks/${usersChallengeTaskId}/score/up`);
let tasks = await user.get(`/tasks/challenge/${challenge._id}`);
let task = find(tasks, {_id: daily._id});
previousTaskHistory = task.history[0];
const tasks = await user.get(`/tasks/challenge/${challenge._id}`);
const task = find(tasks, { _id: daily._id });
previousTaskHistory = task.history[0]; // eslint-disable-line prefer-destructuring
expect(task.history).to.have.lengthOf(1);
expect(task.value).to.equal(1);
});
it('should update the history', async () => {
let newCron = new Date(2015, 11, 20);
const newCron = new Date(2015, 11, 20);
await user.post('/debug/set-cron', {
lastCron: newCron,
@@ -92,8 +92,8 @@ describe('POST /tasks/:id/score/:direction', () => {
await user.post('/cron');
await user.post(`/tasks/${usersChallengeTaskId}/score/up`);
let tasks = await user.get(`/tasks/challenge/${challenge._id}`);
let task = find(tasks, {_id: daily._id});
const tasks = await user.get(`/tasks/challenge/${challenge._id}`);
const task = find(tasks, { _id: daily._id });
expect(task.history).to.have.lengthOf(1);
expect(task.history[0].date).to.not.equal(previousTaskHistory.date);
@@ -111,15 +111,15 @@ describe('POST /tasks/:id/score/:direction', () => {
type: 'todo',
});
await sleep(1);
let updatedUser = await user.get('/user');
usersChallengeTaskId = updatedUser.tasksOrder.todos[0];
const updatedUser = await user.get('/user');
usersChallengeTaskId = updatedUser.tasksOrder.todos[0]; // eslint-disable-line prefer-destructuring, max-len
});
it('scores but does not add history', async () => {
await user.post(`/tasks/${usersChallengeTaskId}/score/up`);
let tasks = await user.get(`/tasks/challenge/${challenge._id}`);
let task = find(tasks, {_id: todo._id});
const tasks = await user.get(`/tasks/challenge/${challenge._id}`);
const task = find(tasks, { _id: todo._id });
expect(task.history).to.not.exist;
expect(task.value).to.equal(1);
@@ -136,15 +136,15 @@ describe('POST /tasks/:id/score/:direction', () => {
type: 'reward',
});
await sleep(1);
let updatedUser = await user.get('/user');
usersChallengeTaskId = updatedUser.tasksOrder.todos[0];
const updatedUser = await user.get('/user');
usersChallengeTaskId = updatedUser.tasksOrder.todos[0]; // eslint-disable-line prefer-destructuring, max-len
});
it('does not score', async () => {
await user.post(`/tasks/${usersChallengeTaskId}/score/up`);
let tasks = await user.get(`/tasks/challenge/${challenge._id}`);
let task = find(tasks, {_id: reward._id});
const tasks = await user.get(`/tasks/challenge/${challenge._id}`);
const task = find(tasks, { _id: reward._id });
expect(task.history).to.not.exist;
expect(task.value).to.equal(0);

View File

@@ -1,10 +1,10 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateGroup,
generateChallenge,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('PUT /tasks/:id', () => {
let user;
@@ -42,7 +42,7 @@ describe('PUT /tasks/:id', () => {
});
it('returns error when user is not a member of the challenge', async () => {
let anotherUser = await generateUser();
const anotherUser = await generateUser();
await expect(anotherUser.put(`/tasks/${task._id}`, {
text: 'some new text',
@@ -80,7 +80,7 @@ describe('PUT /tasks/:id', () => {
it(`ignores setting _id, type, userId, history, createdAt,
updatedAt, challenge, completed, streak,
dateCompleted fields`, async () => {
let savedTask = await user.put(`/tasks/${task._id}`, {
const savedTask = await user.put(`/tasks/${task._id}`, {
_id: 123,
type: 'daily',
userId: 123,
@@ -108,7 +108,7 @@ describe('PUT /tasks/:id', () => {
});
it('ignores invalid fields', async () => {
let savedTask = await user.put(`/tasks/${task._id}`, {
const savedTask = await user.put(`/tasks/${task._id}`, {
notValid: true,
});
@@ -128,7 +128,7 @@ describe('PUT /tasks/:id', () => {
});
it('updates a habit', async () => {
let savedHabit = await user.put(`/tasks/${habit._id}`, {
const savedHabit = await user.put(`/tasks/${habit._id}`, {
text: 'some new text',
up: false,
down: false,
@@ -171,7 +171,7 @@ describe('PUT /tasks/:id', () => {
});
it('updates a todo', async () => {
let savedTodo = await user.put(`/tasks/${todo._id}`, {
const savedTodo = await user.put(`/tasks/${todo._id}`, {
text: 'some new text',
notes: 'some new notes',
});
@@ -183,14 +183,14 @@ describe('PUT /tasks/:id', () => {
it('can update checklists (replace it)', async () => {
await user.put(`/tasks/${todo._id}`, {
checklist: [
{text: 123, completed: false},
{text: 456, completed: true},
{ text: 123, completed: false },
{ text: 456, completed: true },
],
});
let savedTodo = await user.put(`/tasks/${todo._id}`, {
const savedTodo = await user.put(`/tasks/${todo._id}`, {
checklist: [
{text: 789, completed: false},
{ text: 789, completed: false },
],
});
@@ -200,12 +200,12 @@ describe('PUT /tasks/:id', () => {
});
it('can update tags (replace them)', async () => {
let finalUUID = generateUUID();
const finalUUID = generateUUID();
await user.put(`/tasks/${todo._id}`, {
tags: [generateUUID(), generateUUID()],
});
let savedTodo = await user.put(`/tasks/${todo._id}`, {
const savedTodo = await user.put(`/tasks/${todo._id}`, {
tags: [finalUUID],
});
@@ -226,7 +226,7 @@ describe('PUT /tasks/:id', () => {
});
it('updates a daily', async () => {
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
text: 'some new text',
notes: 'some new notes',
frequency: 'daily',
@@ -242,14 +242,14 @@ describe('PUT /tasks/:id', () => {
it('can update checklists (replace it)', async () => {
await user.put(`/tasks/${daily._id}`, {
checklist: [
{text: 123, completed: false},
{text: 456, completed: true},
{ text: 123, completed: false },
{ text: 456, completed: true },
],
});
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
checklist: [
{text: 789, completed: false},
{ text: 789, completed: false },
],
});
@@ -259,12 +259,12 @@ describe('PUT /tasks/:id', () => {
});
it('can update tags (replace them)', async () => {
let finalUUID = generateUUID();
const finalUUID = generateUUID();
await user.put(`/tasks/${daily._id}`, {
tags: [generateUUID(), generateUUID()],
});
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
tags: [finalUUID],
});
@@ -277,7 +277,7 @@ describe('PUT /tasks/:id', () => {
frequency: 'daily',
});
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
repeat: {
m: false,
su: false,
@@ -300,7 +300,7 @@ describe('PUT /tasks/:id', () => {
frequency: 'weekly',
});
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
everyX: 5,
});
@@ -308,7 +308,7 @@ describe('PUT /tasks/:id', () => {
});
it('defaults startDate to today if none date object is passed in', async () => {
let savedDaily = await user.put(`/tasks/${daily._id}`, {
const savedDaily = await user.put(`/tasks/${daily._id}`, {
frequency: 'weekly',
});
@@ -329,7 +329,7 @@ describe('PUT /tasks/:id', () => {
});
it('updates a reward', async () => {
let savedReward = await user.put(`/tasks/${reward._id}`, {
const savedReward = await user.put(`/tasks/${reward._id}`, {
text: 'some new text',
notes: 'some new notes',
value: 11,
@@ -341,7 +341,7 @@ describe('PUT /tasks/:id', () => {
});
it('requires value to be coerced into a number', async () => {
let savedReward = await user.put(`/tasks/${reward._id}`, {
const savedReward = await user.put(`/tasks/${reward._id}`, {
value: '100',
});

View File

@@ -1,10 +1,10 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
generateGroup,
generateChallenge,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('PUT /tasks/:taskId/checklist/:itemId', () => {
let user;
@@ -19,7 +19,7 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on task not found', async () => {
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'todo',
text: 'Todo with checklist',
});
@@ -37,17 +37,17 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('returns error when user is not a member of the challenge', async () => {
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'todo',
text: 'Todo with checklist',
});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, {
const savedTask = await user.post(`/tasks/${task._id}/checklist`, {
text: 'Checklist Item 1',
completed: false,
});
let anotherUser = await generateUser();
const anotherUser = await generateUser();
await expect(anotherUser.put(`/tasks/${task._id}/checklist/${savedTask.checklist[0].id}`, {
text: 'updated',
@@ -62,7 +62,7 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('updates a checklist item on dailies', async () => {
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'daily',
text: 'Daily with checklist',
});
@@ -85,7 +85,7 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('updates a checklist item on todos', async () => {
let task = await user.post(`/tasks/challenge/${challenge._id}`, {
const task = await user.post(`/tasks/challenge/${challenge._id}`, {
type: 'todo',
text: 'Todo with checklist',
});
@@ -108,7 +108,7 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on habits', async () => {
let habit = await user.post('/tasks/user', {
const habit = await user.post('/tasks/user', {
type: 'habit',
text: 'habit with checklist',
});
@@ -121,7 +121,7 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on rewards', async () => {
let reward = await user.post('/tasks/user', {
const reward = await user.post('/tasks/user', {
type: 'reward',
text: 'reward with checklist',
});
@@ -142,7 +142,7 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on checklist item not found', async () => {
let createdTask = await user.post('/tasks/user', {
const createdTask = await user.post('/tasks/user', {
type: 'daily',
text: 'daily with checklist',
});

View File

@@ -1,8 +1,8 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
let user;
@@ -12,12 +12,12 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
});
it('deletes a checklist item', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'daily',
text: 'Daily with checklist',
});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, {text: 'Checklist Item 1', completed: false});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, { text: 'Checklist Item 1', completed: false });
await user.del(`/tasks/${task._id}/checklist/${savedTask.checklist[0].id}`);
savedTask = await user.get(`/tasks/${task._id}`);
@@ -26,13 +26,13 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
});
it('deletes a checklist item using task alias', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'daily',
text: 'Daily with checklist',
alias: 'daily-with-alias',
});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, {text: 'Checklist Item 1', completed: false});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, { text: 'Checklist Item 1', completed: false });
await user.del(`/tasks/${task.alias}/checklist/${savedTask.checklist[0].id}`);
savedTask = await user.get(`/tasks/${task._id}`);
@@ -41,7 +41,7 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
});
it('does not work with habits', async () => {
let habit = await user.post('/tasks/user', {
const habit = await user.post('/tasks/user', {
type: 'habit',
text: 'habit with checklist',
});
@@ -54,7 +54,7 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
});
it('does not work with rewards', async () => {
let reward = await user.post('/tasks/user', {
const reward = await user.post('/tasks/user', {
type: 'reward',
text: 'reward with checklist',
});
@@ -75,7 +75,7 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on checklist item not found', async () => {
let createdTask = await user.post('/tasks/user', {
const createdTask = await user.post('/tasks/user', {
type: 'daily',
text: 'daily with checklist',
});

View File

@@ -1,8 +1,8 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /tasks/:taskId/checklist/', () => {
let user;
@@ -12,12 +12,12 @@ describe('POST /tasks/:taskId/checklist/', () => {
});
it('adds a checklist item to a task', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'daily',
text: 'Daily with checklist',
});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, {
const savedTask = await user.post(`/tasks/${task._id}/checklist`, {
text: 'Checklist Item 1',
ignored: false,
_id: 123,
@@ -32,13 +32,13 @@ describe('POST /tasks/:taskId/checklist/', () => {
});
it('can use a alias to add checklist', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'daily',
text: 'Daily with checklist',
alias: 'task-with-shortname',
});
let savedTask = await user.post(`/tasks/${task.alias}/checklist`, {
const savedTask = await user.post(`/tasks/${task.alias}/checklist`, {
text: 'Checklist Item 1',
ignored: false,
_id: 123,
@@ -53,7 +53,7 @@ describe('POST /tasks/:taskId/checklist/', () => {
});
it('does not add a checklist to habits', async () => {
let habit = await user.post('/tasks/user', {
const habit = await user.post('/tasks/user', {
type: 'habit',
text: 'habit with checklist',
});
@@ -68,7 +68,7 @@ describe('POST /tasks/:taskId/checklist/', () => {
});
it('does not add a checklist to rewards', async () => {
let reward = await user.post('/tasks/user', {
const reward = await user.post('/tasks/user', {
type: 'reward',
text: 'reward with checklist',
});

View File

@@ -1,10 +1,10 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
translate as t,
server,
sleep,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
let user;
@@ -14,7 +14,7 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
});
it('scores a checklist item', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'daily',
text: 'Daily with checklist',
});
@@ -31,7 +31,7 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
});
it('can use a alias to score a checklist item', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'daily',
text: 'Daily with checklist',
alias: 'daily-with-shortname',
@@ -49,7 +49,7 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
});
it('fails on habits', async () => {
let habit = await user.post('/tasks/user', {
const habit = await user.post('/tasks/user', {
type: 'habit',
text: 'habit with checklist',
});
@@ -64,7 +64,7 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
});
it('fails on rewards', async () => {
let reward = await user.post('/tasks/user', {
const reward = await user.post('/tasks/user', {
type: 'reward',
text: 'reward with checklist',
});
@@ -85,7 +85,7 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
});
it('fails on checklist item not found', async () => {
let createdTask = await user.post('/tasks/user', {
const createdTask = await user.post('/tasks/user', {
type: 'daily',
text: 'daily with checklist',
});
@@ -107,7 +107,7 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
});
it('sends task activity webhooks', async () => {
let uuid = generateUUID();
const uuid = generateUUID();
await user.post('/user/webhook', {
url: `http://localhost:${server.port}/webhooks/${uuid}`,
@@ -119,22 +119,22 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
},
});
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
text: 'test daily',
type: 'daily',
});
let updatedTask = await user.post(`/tasks/${task.id}/checklist`, {
const updatedTask = await user.post(`/tasks/${task.id}/checklist`, {
text: 'checklist item text',
});
let checklistItem = updatedTask.checklist[0];
const checklistItem = updatedTask.checklist[0];
let scoredItemTask = await user.post(`/tasks/${task.id}/checklist/${checklistItem.id}/score`);
const scoredItemTask = await user.post(`/tasks/${task.id}/checklist/${checklistItem.id}/score`);
await sleep();
let body = server.getWebhookData(uuid);
const body = server.getWebhookData(uuid);
expect(body.type).to.eql('checklistScored');
expect(body.task).to.eql(scoredItemTask);

View File

@@ -1,8 +1,8 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('PUT /tasks/:taskId/checklist/:itemId', () => {
let user;
@@ -12,7 +12,7 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('updates a checklist item', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'daily',
text: 'Daily with checklist',
});
@@ -35,7 +35,7 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('updates a checklist item using task alias', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'daily',
text: 'Daily with checklist',
alias: 'daily-with-shortname',
@@ -59,7 +59,7 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on habits', async () => {
let habit = await user.post('/tasks/user', {
const habit = await user.post('/tasks/user', {
type: 'habit',
text: 'habit with checklist',
});
@@ -72,7 +72,7 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on rewards', async () => {
let reward = await user.post('/tasks/user', {
const reward = await user.post('/tasks/user', {
type: 'reward',
text: 'reward with checklist',
});
@@ -93,7 +93,7 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on checklist item not found', async () => {
let createdTask = await user.post('/tasks/user', {
const createdTask = await user.post('/tasks/user', {
type: 'daily',
text: 'daily with checklist',
});

View File

@@ -1,18 +1,19 @@
import { find } from 'lodash';
import {
translate as t,
createAndPopulateGroup,
} from '../../../../../helpers/api-integration/v3';
import { find } from 'lodash';
describe('Groups DELETE /tasks/:id', () => {
let user, guild, member, member2, task;
let user; let guild; let member; let member2; let
task;
function findAssignedTask (memberTask) {
return memberTask.group.id === guild._id;
}
beforeEach(async () => {
let {group, members, groupLeader} = await createAndPopulateGroup({
const { group, members, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'Test Guild',
type: 'guild',
@@ -22,8 +23,8 @@ describe('Groups DELETE /tasks/:id', () => {
guild = group;
user = groupLeader;
member = members[0];
member2 = members[1];
member = members[0]; // eslint-disable-line prefer-destructuring
member2 = members[1]; // eslint-disable-line prefer-destructuring
task = await user.post(`/tasks/group/${guild._id}`, {
text: 'test habit',
@@ -70,8 +71,8 @@ describe('Groups DELETE /tasks/:id', () => {
await user.put(`/tasks/${task._id}/`, {
requiresApproval: true,
});
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await expect(member.post(`/tasks/${syncedTask._id}/score/up`))
.to.eventually.be.rejected.and.to.eql({
code: 401,
@@ -98,8 +99,8 @@ describe('Groups DELETE /tasks/:id', () => {
it('unlinks assigned user', async () => {
await user.del(`/tasks/${task._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
expect(syncedTask.group.broken).to.equal('TASK_DELETED');
});
@@ -107,19 +108,19 @@ describe('Groups DELETE /tasks/:id', () => {
it('unlinks all assigned users', async () => {
await user.del(`/tasks/${task._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
let member2Tasks = await member2.get('/tasks/user');
let member2SyncedTask = find(member2Tasks, findAssignedTask);
const member2Tasks = await member2.get('/tasks/user');
const member2SyncedTask = find(member2Tasks, findAssignedTask);
expect(syncedTask.group.broken).to.equal('TASK_DELETED');
expect(member2SyncedTask.group.broken).to.equal('TASK_DELETED');
});
it('prevents a user from deleting a task they are assigned to', async () => {
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await expect(member.del(`/tasks/${syncedTask._id}`))
.to.eventually.be.rejected.and.eql({
@@ -130,8 +131,8 @@ describe('Groups DELETE /tasks/:id', () => {
});
it('allows a user to delete a broken task', async () => {
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await user.del(`/tasks/${task._id}`);
@@ -146,8 +147,8 @@ describe('Groups DELETE /tasks/:id', () => {
});
it('allows a user to delete a task after leaving a group', async () => {
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await member.post(`/groups/${guild._id}/leave`);

View File

@@ -1,17 +1,18 @@
import { find } from 'lodash';
import {
createAndPopulateGroup,
} from '../../../../../helpers/api-integration/v3';
import { find } from 'lodash';
describe('GET /approvals/group/:groupId', () => {
let user, guild, member, addlMember, task, syncedTask, addlSyncedTask;
let user; let guild; let member; let addlMember; let task; let syncedTask; let
addlSyncedTask;
function findAssignedTask (memberTask) {
return memberTask.group.id === guild._id;
}
beforeEach(async () => {
let {group, members, groupLeader} = await createAndPopulateGroup({
const { group, members, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'Test Guild',
type: 'guild',
@@ -21,8 +22,8 @@ describe('GET /approvals/group/:groupId', () => {
guild = group;
user = groupLeader;
member = members[0];
addlMember = members[1];
member = members[0]; // eslint-disable-line prefer-destructuring
addlMember = members[1]; // eslint-disable-line prefer-destructuring
task = await user.post(`/tasks/group/${guild._id}`, {
text: 'test todo',
@@ -33,10 +34,10 @@ describe('GET /approvals/group/:groupId', () => {
await user.post(`/tasks/${task._id}/assign/${member._id}`);
await user.post(`/tasks/${task._id}/assign/${addlMember._id}`);
let memberTasks = await member.get('/tasks/user');
const memberTasks = await member.get('/tasks/user');
syncedTask = find(memberTasks, findAssignedTask);
let addlMemberTasks = await addlMember.get('/tasks/user');
const addlMemberTasks = await addlMember.get('/tasks/user');
addlSyncedTask = find(addlMemberTasks, findAssignedTask);
try {
@@ -53,13 +54,13 @@ describe('GET /approvals/group/:groupId', () => {
});
it('provides only user\'s own tasks when user is not the group leader', async () => {
let approvals = await member.get(`/approvals/group/${guild._id}`);
const approvals = await member.get(`/approvals/group/${guild._id}`);
expect(approvals[0]._id).to.equal(syncedTask._id);
expect(approvals[1]).to.not.exist;
});
it('allows group leaders to get a list of tasks that need approval', async () => {
let approvals = await user.get(`/approvals/group/${guild._id}`);
const approvals = await user.get(`/approvals/group/${guild._id}`);
expect(approvals[0]._id).to.equal(syncedTask._id);
expect(approvals[1]._id).to.equal(addlSyncedTask._id);
});
@@ -69,7 +70,7 @@ describe('GET /approvals/group/:groupId', () => {
managerId: member._id,
});
let approvals = await member.get(`/approvals/group/${guild._id}`);
const approvals = await member.get(`/approvals/group/${guild._id}`);
expect(approvals[0]._id).to.equal(syncedTask._id);
expect(approvals[1]._id).to.equal(addlSyncedTask._id);
});

View File

@@ -1,15 +1,16 @@
import { v4 as generateUUID } from 'uuid';
import { each } from 'lodash';
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 = {
let user; let group; let task; let
groupWithTask;
const tasks = [];
const tasksToTest = {
habit: {
text: 'test habit',
type: 'habit',
@@ -39,7 +40,7 @@ describe('GET /tasks/group/:groupId', () => {
});
it('returns error when group is not found', async () => {
let dummyId = generateUUID();
const dummyId = generateUUID();
await expect(user.get(`/tasks/group/${dummyId}`)).to.eventually.be.rejected.and.eql({
code: 404,
@@ -57,17 +58,17 @@ describe('GET /tasks/group/:groupId', () => {
});
it('gets group tasks', async () => {
let getTask = await user.get(`/tasks/group/${groupWithTask._id}`);
const 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`);
const 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();
const anotherUser = await generateUser();
await expect(anotherUser.get(`/tasks/group/${groupWithTask._id}`)).to.eventually.be.rejected.and.eql({
code: 404,

View File

@@ -1,18 +1,19 @@
import { find } from 'lodash';
import {
createAndPopulateGroup,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { find } from 'lodash';
describe('POST /tasks/:id/approve/:userId', () => {
let user, guild, member, member2, task;
let user; let guild; let member; let member2; let
task;
function findAssignedTask (memberTask) {
return memberTask.group.id === guild._id;
}
beforeEach(async () => {
let {group, members, groupLeader} = await createAndPopulateGroup({
const { group, members, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'Test Guild',
type: 'guild',
@@ -22,8 +23,8 @@ describe('POST /tasks/:id/approve/:userId', () => {
guild = group;
user = groupLeader;
member = members[0];
member2 = members[1];
member = members[0]; // eslint-disable-line prefer-destructuring
member2 = members[1]; // eslint-disable-line prefer-destructuring
task = await user.post(`/tasks/group/${guild._id}`, {
text: 'test todo',
@@ -70,9 +71,9 @@ describe('POST /tasks/:id/approve/:userId', () => {
expect(member.notifications.length).to.equal(3);
expect(member.notifications[1].type).to.equal('GROUP_TASK_APPROVED');
expect(member.notifications[1].data.message).to.equal(t('yourTaskHasBeenApproved', {taskText: task.text}));
expect(member.notifications[1].data.message).to.equal(t('yourTaskHasBeenApproved', { taskText: task.text }));
expect(member.notifications[2].type).to.equal('SCORED_TASK');
expect(member.notifications[2].data.message).to.equal(t('yourTaskHasBeenApproved', {taskText: task.text}));
expect(member.notifications[2].data.message).to.equal(t('yourTaskHasBeenApproved', { taskText: task.text }));
memberTasks = await member.get('/tasks/user');
syncedTask = find(memberTasks, findAssignedTask);
@@ -104,9 +105,9 @@ describe('POST /tasks/:id/approve/:userId', () => {
expect(member.notifications.length).to.equal(3);
expect(member.notifications[1].type).to.equal('GROUP_TASK_APPROVED');
expect(member.notifications[1].data.message).to.equal(t('yourTaskHasBeenApproved', {taskText: task.text}));
expect(member.notifications[1].data.message).to.equal(t('yourTaskHasBeenApproved', { taskText: task.text }));
expect(member.notifications[2].type).to.equal('SCORED_TASK');
expect(member.notifications[2].data.message).to.equal(t('yourTaskHasBeenApproved', {taskText: task.text}));
expect(member.notifications[2].data.message).to.equal(t('yourTaskHasBeenApproved', { taskText: task.text }));
memberTasks = await member.get('/tasks/user');
syncedTask = find(memberTasks, findAssignedTask);
@@ -122,8 +123,8 @@ describe('POST /tasks/:id/approve/:userId', () => {
});
await member2.post(`/tasks/${task._id}/assign/${member._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await expect(member.post(`/tasks/${syncedTask._id}/score/up`))
.to.eventually.be.rejected.and.to.eql({
code: 401,
@@ -154,8 +155,8 @@ describe('POST /tasks/:id/approve/:userId', () => {
await member2.post(`/tasks/${task._id}/assign/${member._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await expect(member.post(`/tasks/${syncedTask._id}/score/up`))
.to.eventually.be.rejected.and.to.eql({
code: 401,
@@ -184,7 +185,7 @@ describe('POST /tasks/:id/approve/:userId', () => {
});
it('completes master task when single-completion task is approved', async () => {
let sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
const sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
text: 'shared completion todo',
type: 'todo',
requiresApproval: true,
@@ -194,8 +195,8 @@ describe('POST /tasks/:id/approve/:userId', () => {
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member._id}`);
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member2._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await expect(member.post(`/tasks/${syncedTask._id}/score/up`))
.to.eventually.be.rejected.and.to.eql({
code: 401,
@@ -205,17 +206,15 @@ describe('POST /tasks/:id/approve/:userId', () => {
await user.post(`/tasks/${sharedCompletionTask._id}/approve/${member._id}`);
let groupTasks = await user.get(`/tasks/group/${guild._id}?type=completedTodos`);
const groupTasks = await user.get(`/tasks/group/${guild._id}?type=completedTodos`);
let masterTask = find(groupTasks, (groupTask) => {
return groupTask._id === sharedCompletionTask._id;
});
const masterTask = find(groupTasks, groupTask => groupTask._id === sharedCompletionTask._id);
expect(masterTask.completed).to.equal(true);
});
it('deletes other assigned user tasks when single-completion task is approved', async () => {
let sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
const sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
text: 'shared completion todo',
type: 'todo',
requiresApproval: true,
@@ -225,8 +224,8 @@ describe('POST /tasks/:id/approve/:userId', () => {
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member._id}`);
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member2._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await expect(member.post(`/tasks/${syncedTask._id}/score/up`))
.to.eventually.be.rejected.and.to.eql({
code: 401,
@@ -236,17 +235,18 @@ describe('POST /tasks/:id/approve/:userId', () => {
await user.post(`/tasks/${sharedCompletionTask._id}/approve/${member._id}`);
let member2Tasks = await member2.get('/tasks/user');
const member2Tasks = await member2.get('/tasks/user');
let syncedTask2 = find(member2Tasks, (memberTask) => {
return memberTask.group.taskId === sharedCompletionTask._id;
});
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 approved if all assigned must complete', async () => {
let sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
const sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
text: 'shared completion todo',
type: 'todo',
requiresApproval: true,
@@ -256,8 +256,8 @@ describe('POST /tasks/:id/approve/:userId', () => {
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member._id}`);
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member2._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await expect(member.post(`/tasks/${syncedTask._id}/score/up`))
.to.eventually.be.rejected.and.to.eql({
code: 401,
@@ -267,17 +267,15 @@ describe('POST /tasks/:id/approve/:userId', () => {
await user.post(`/tasks/${sharedCompletionTask._id}/approve/${member._id}`);
let groupTasks = await user.get(`/tasks/group/${guild._id}`);
const groupTasks = await user.get(`/tasks/group/${guild._id}`);
let masterTask = find(groupTasks, (groupTask) => {
return groupTask._id === sharedCompletionTask._id;
});
const masterTask = find(groupTasks, groupTask => groupTask._id === sharedCompletionTask._id);
expect(masterTask.completed).to.equal(false);
});
it('completes master task when all user tasks are approved if all assigned must complete', async () => {
let sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
const sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
text: 'shared completion todo',
type: 'todo',
requiresApproval: true,
@@ -287,8 +285,8 @@ describe('POST /tasks/:id/approve/:userId', () => {
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member._id}`);
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member2._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await expect(member.post(`/tasks/${syncedTask._id}/score/up`))
.to.eventually.be.rejected.and.to.eql({
code: 401,
@@ -296,8 +294,8 @@ describe('POST /tasks/:id/approve/:userId', () => {
message: t('taskApprovalHasBeenRequested'),
});
let member2Tasks = await member2.get('/tasks/user');
let member2SyncedTask = find(member2Tasks, findAssignedTask);
const member2Tasks = await member2.get('/tasks/user');
const member2SyncedTask = find(member2Tasks, findAssignedTask);
await expect(member2.post(`/tasks/${member2SyncedTask._id}/score/up`))
.to.eventually.be.rejected.and.to.eql({
code: 401,
@@ -308,11 +306,9 @@ describe('POST /tasks/:id/approve/:userId', () => {
await user.post(`/tasks/${sharedCompletionTask._id}/approve/${member._id}`);
await user.post(`/tasks/${sharedCompletionTask._id}/approve/${member2._id}`);
let groupTasks = await user.get(`/tasks/group/${guild._id}?type=completedTodos`);
const groupTasks = await user.get(`/tasks/group/${guild._id}?type=completedTodos`);
let masterTask = find(groupTasks, (groupTask) => {
return groupTask._id === sharedCompletionTask._id;
});
const masterTask = find(groupTasks, groupTask => groupTask._id === sharedCompletionTask._id);
expect(masterTask.completed).to.equal(true);
});

View File

@@ -1,18 +1,19 @@
import { find } from 'lodash';
import {
createAndPopulateGroup,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { find } from 'lodash';
describe('POST /tasks/:id/needs-work/:userId', () => {
let user, guild, member, member2, task;
let user; let guild; let member; let member2; let
task;
function findAssignedTask (memberTask) {
return memberTask.group.id === guild._id;
}
beforeEach(async () => {
let {group, members, groupLeader} = await createAndPopulateGroup({
const { group, members, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'Test Guild',
type: 'guild',
@@ -22,8 +23,8 @@ describe('POST /tasks/:id/needs-work/:userId', () => {
guild = group;
user = groupLeader;
member = members[0];
member2 = members[1];
member = members[0]; // eslint-disable-line prefer-destructuring
member2 = members[1]; // eslint-disable-line prefer-destructuring
task = await user.post(`/tasks/group/${guild._id}`, {
text: 'test todo',
@@ -84,7 +85,7 @@ describe('POST /tasks/:id/needs-work/:userId', () => {
const taskText = syncedTask.text;
const managerName = user.profile.name;
expect(notification.data.message).to.equal(t('taskNeedsWork', {taskText, managerName}));
expect(notification.data.message).to.equal(t('taskNeedsWork', { taskText, managerName }));
expect(notification.data.task.id).to.equal(syncedTask._id);
expect(notification.data.task.text).to.equal(taskText);
@@ -98,8 +99,8 @@ describe('POST /tasks/:id/needs-work/:userId', () => {
// Check that the managers' GROUP_TASK_APPROVAL notifications have been removed
await user.sync();
expect(user.notifications.find(n => {
n.data.taskId === syncedTask._id && n.type === 'GROUP_TASK_APPROVAL';
expect(user.notifications.find(n => { // eslint-disable-line arrow-body-style
return n.data.taskId === syncedTask._id && n.type === 'GROUP_TASK_APPROVAL';
})).to.equal(undefined);
});
@@ -138,7 +139,7 @@ describe('POST /tasks/:id/needs-work/:userId', () => {
const taskText = syncedTask.text;
const managerName = member2.profile.name;
expect(notification.data.message).to.equal(t('taskNeedsWork', {taskText, managerName}));
expect(notification.data.message).to.equal(t('taskNeedsWork', { taskText, managerName }));
expect(notification.data.task.id).to.equal(syncedTask._id);
expect(notification.data.task.text).to.equal(taskText);
@@ -152,12 +153,12 @@ describe('POST /tasks/:id/needs-work/:userId', () => {
// Check that the managers' GROUP_TASK_APPROVAL notifications have been removed
await Promise.all([user.sync(), member2.sync()]);
expect(user.notifications.find(n => {
n.data.taskId === syncedTask._id && n.type === 'GROUP_TASK_APPROVAL';
expect(user.notifications.find(n => { // eslint-disable-line arrow-body-style
return n.data.taskId === syncedTask._id && n.type === 'GROUP_TASK_APPROVAL';
})).to.equal(undefined);
expect(member2.notifications.find(n => {
n.data.taskId === syncedTask._id && n.type === 'GROUP_TASK_APPROVAL';
expect(member2.notifications.find(n => { // eslint-disable-line arrow-body-style
return n.data.taskId === syncedTask._id && n.type === 'GROUP_TASK_APPROVAL';
})).to.equal(undefined);
});
@@ -168,8 +169,8 @@ describe('POST /tasks/:id/needs-work/:userId', () => {
await member2.post(`/tasks/${task._id}/assign/${member._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await expect(member.post(`/tasks/${syncedTask._id}/score/up`))
.to.eventually.be.rejected.and.to.eql({

View File

@@ -1,18 +1,19 @@
import { find } from 'lodash';
import {
createAndPopulateGroup,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { find } from 'lodash';
describe('POST /tasks/:id/score/:direction', () => {
let user, guild, member, member2, task;
let user; let guild; let member; let member2; let
task;
function findAssignedTask (memberTask) {
return memberTask.group.id === guild._id;
}
beforeEach(async () => {
let {group, members, groupLeader} = await createAndPopulateGroup({
const { group, members, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'Test Guild',
type: 'guild',
@@ -22,8 +23,8 @@ describe('POST /tasks/:id/score/:direction', () => {
guild = group;
user = groupLeader;
member = members[0];
member2 = members[1];
member = members[0]; // eslint-disable-line prefer-destructuring
member2 = members[1]; // eslint-disable-line prefer-destructuring
task = await user.post(`/tasks/group/${guild._id}`, {
text: 'test todo',
@@ -39,8 +40,8 @@ describe('POST /tasks/:id/score/:direction', () => {
'preferences.language': 'cs',
});
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
const direction = 'up';
await expect(member.post(`/tasks/${syncedTask._id}/score/${direction}`))
@@ -49,7 +50,7 @@ describe('POST /tasks/:id/score/:direction', () => {
error: 'NotAuthorized',
message: t('taskApprovalHasBeenRequested'),
});
let updatedTask = await member.get(`/tasks/${syncedTask._id}`);
const updatedTask = await member.get(`/tasks/${syncedTask._id}`);
await user.sync();
@@ -71,8 +72,8 @@ describe('POST /tasks/:id/score/:direction', () => {
await user.post(`/groups/${guild._id}/add-manager`, {
managerId: member2._id,
});
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
const direction = 'up';
await expect(member.post(`/tasks/${syncedTask._id}/score/${direction}`))
@@ -81,7 +82,7 @@ describe('POST /tasks/:id/score/:direction', () => {
error: 'NotAuthorized',
message: t('taskApprovalHasBeenRequested'),
});
let updatedTask = await member.get(`/tasks/${syncedTask._id}`);
const updatedTask = await member.get(`/tasks/${syncedTask._id}`);
await user.sync();
await member2.sync();
@@ -107,8 +108,8 @@ describe('POST /tasks/:id/score/:direction', () => {
});
it('errors when approval has already been requested', async () => {
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await expect(member.post(`/tasks/${syncedTask._id}/score/up`))
.to.eventually.be.rejected.and.to.eql({
@@ -126,8 +127,8 @@ describe('POST /tasks/:id/score/:direction', () => {
});
it('allows a user to score an approved task', async () => {
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
await expect(member.post(`/tasks/${syncedTask._id}/score/up`))
.to.eventually.be.rejected.and.to.eql({
@@ -139,14 +140,14 @@ describe('POST /tasks/:id/score/:direction', () => {
await user.post(`/tasks/${task._id}/approve/${member._id}`);
await member.post(`/tasks/${syncedTask._id}/score/up`);
let updatedTask = await member.get(`/tasks/${syncedTask._id}`);
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 () => {
let sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
const sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
text: 'shared completion todo',
type: 'todo',
requiresApproval: false,
@@ -154,24 +155,23 @@ describe('POST /tasks/:id/score/:direction', () => {
});
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member._id}`);
let memberTasks = await member.get('/tasks/user');
const memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, (memberTask) => {
return memberTask.group.taskId === sharedCompletionTask._id;
});
const syncedTask = find(
memberTasks,
memberTask => memberTask.group.taskId === sharedCompletionTask._id,
);
await member.post(`/tasks/${syncedTask._id}/score/up`);
let groupTasks = await user.get(`/tasks/group/${guild._id}?type=completedTodos`);
let masterTask = find(groupTasks, (groupTask) => {
return groupTask._id === sharedCompletionTask._id;
});
const groupTasks = await user.get(`/tasks/group/${guild._id}?type=completedTodos`);
const masterTask = find(groupTasks, groupTask => groupTask._id === sharedCompletionTask._id);
expect(masterTask.completed).to.equal(true);
});
it('deletes other assigned user tasks when single-completion task is completed', async () => {
let sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
const sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
text: 'shared completion todo',
type: 'todo',
requiresApproval: false,
@@ -180,25 +180,27 @@ describe('POST /tasks/:id/score/:direction', () => {
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member._id}`);
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member2._id}`);
let memberTasks = await member.get('/tasks/user');
const memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, (memberTask) => {
return memberTask.group.taskId === sharedCompletionTask._id;
});
const syncedTask = find(
memberTasks,
memberTask => memberTask.group.taskId === sharedCompletionTask._id,
);
await member.post(`/tasks/${syncedTask._id}/score/up`);
let member2Tasks = await member2.get('/tasks/user');
const member2Tasks = await member2.get('/tasks/user');
let syncedTask2 = find(member2Tasks, (memberTask) => {
return memberTask.group.taskId === sharedCompletionTask._id;
});
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 () => {
let sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
const sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
text: 'shared completion todo',
type: 'todo',
requiresApproval: false,
@@ -207,24 +209,23 @@ describe('POST /tasks/:id/score/:direction', () => {
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member._id}`);
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member2._id}`);
let memberTasks = await member.get('/tasks/user');
const memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, (memberTask) => {
return memberTask.group.taskId === sharedCompletionTask._id;
});
const syncedTask = find(
memberTasks,
memberTask => memberTask.group.taskId === sharedCompletionTask._id,
);
await member.post(`/tasks/${syncedTask._id}/score/up`);
let groupTasks = await user.get(`/tasks/group/${guild._id}`);
let masterTask = find(groupTasks, (groupTask) => {
return groupTask._id === sharedCompletionTask._id;
});
const groupTasks = await user.get(`/tasks/group/${guild._id}`);
const masterTask = find(groupTasks, groupTask => groupTask._id === sharedCompletionTask._id);
expect(masterTask.completed).to.equal(false);
});
it('completes master task when all user tasks are completed if all assigned must complete', async () => {
let sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
const sharedCompletionTask = await user.post(`/tasks/group/${guild._id}`, {
text: 'shared completion todo',
type: 'todo',
requiresApproval: false,
@@ -233,22 +234,22 @@ describe('POST /tasks/:id/score/:direction', () => {
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member._id}`);
await user.post(`/tasks/${sharedCompletionTask._id}/assign/${member2._id}`);
let memberTasks = await member.get('/tasks/user');
let member2Tasks = await member2.get('/tasks/user');
let syncedTask = find(memberTasks, (memberTask) => {
return memberTask.group.taskId === sharedCompletionTask._id;
});
let syncedTask2 = find(member2Tasks, (memberTask) => {
return memberTask.group.taskId === sharedCompletionTask._id;
});
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`);
let groupTasks = await user.get(`/tasks/group/${guild._id}?type=completedTodos`);
let masterTask = find(groupTasks, (groupTask) => {
return groupTask._id === sharedCompletionTask._id;
});
const groupTasks = await user.get(`/tasks/group/${guild._id}?type=completedTodos`);
const masterTask = find(groupTasks, groupTask => groupTask._id === sharedCompletionTask._id);
expect(masterTask.completed).to.equal(true);
});

View File

@@ -1,18 +1,19 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
createAndPopulateGroup,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /tasks/group/:groupid', () => {
let user, guild, manager;
let groupName = 'Test Public Guild';
let groupType = 'guild';
let user; let guild; let
manager;
const groupName = 'Test Public Guild';
const groupType = 'guild';
beforeEach(async () => {
user = await generateUser({balance: 1});
let { group, groupLeader, members } = await createAndPopulateGroup({
user = await generateUser({ balance: 1 });
const { group, groupLeader, members } = await createAndPopulateGroup({
groupDetails: {
name: groupName,
type: groupType,
@@ -23,7 +24,7 @@ describe('POST /tasks/group/:groupid', () => {
guild = group;
user = groupLeader;
manager = members[0];
manager = members[0]; // eslint-disable-line prefer-destructuring
});
it('returns error when group is not found', async () => {
@@ -41,7 +42,7 @@ describe('POST /tasks/group/:groupid', () => {
});
it('returns error when user is not a member of the group', async () => {
let userWithoutChallenge = await generateUser();
const userWithoutChallenge = await generateUser();
await expect(userWithoutChallenge.post(`/tasks/group/${guild._id}`, {
text: 'test habit',
@@ -57,7 +58,7 @@ describe('POST /tasks/group/:groupid', () => {
});
it('returns error when non leader tries to create a task', async () => {
let userThatIsNotLeaderOfGroup = await generateUser({
const userThatIsNotLeaderOfGroup = await generateUser({
guilds: [guild._id],
});
@@ -75,7 +76,7 @@ describe('POST /tasks/group/:groupid', () => {
});
it('creates a habit', async () => {
let task = await user.post(`/tasks/group/${guild._id}`, {
const task = await user.post(`/tasks/group/${guild._id}`, {
text: 'test habit',
type: 'habit',
up: false,
@@ -83,7 +84,7 @@ describe('POST /tasks/group/:groupid', () => {
notes: 1976,
});
let groupTask = await user.get(`/tasks/group/${guild._id}`);
const groupTask = await user.get(`/tasks/group/${guild._id}`);
expect(groupTask[0].group.id).to.equal(guild._id);
expect(task.text).to.eql('test habit');
@@ -94,13 +95,13 @@ describe('POST /tasks/group/:groupid', () => {
});
it('creates a todo', async () => {
let task = await user.post(`/tasks/group/${guild._id}`, {
const task = await user.post(`/tasks/group/${guild._id}`, {
text: 'test todo',
type: 'todo',
notes: 1976,
});
let groupTask = await user.get(`/tasks/group/${guild._id}`);
const groupTask = await user.get(`/tasks/group/${guild._id}`);
expect(groupTask[0].group.id).to.equal(guild._id);
expect(task.text).to.eql('test todo');
@@ -109,8 +110,8 @@ describe('POST /tasks/group/:groupid', () => {
});
it('creates a daily', async () => {
let now = new Date();
let task = await user.post(`/tasks/group/${guild._id}`, {
const now = new Date();
const task = await user.post(`/tasks/group/${guild._id}`, {
text: 'test daily',
type: 'daily',
notes: 1976,
@@ -119,7 +120,7 @@ describe('POST /tasks/group/:groupid', () => {
startDate: now,
});
let groupTask = await user.get(`/tasks/group/${guild._id}`);
const groupTask = await user.get(`/tasks/group/${guild._id}`);
expect(groupTask[0].group.id).to.equal(guild._id);
expect(task.text).to.eql('test daily');
@@ -135,7 +136,7 @@ describe('POST /tasks/group/:groupid', () => {
managerId: manager._id,
});
let task = await manager.post(`/tasks/group/${guild._id}`, {
const task = await manager.post(`/tasks/group/${guild._id}`, {
text: 'test habit',
type: 'habit',
up: false,
@@ -143,7 +144,7 @@ describe('POST /tasks/group/:groupid', () => {
notes: 1976,
});
let groupTask = await manager.get(`/tasks/group/${guild._id}`);
const groupTask = await manager.get(`/tasks/group/${guild._id}`);
expect(groupTask[0].group.id).to.equal(guild._id);
expect(task.text).to.eql('test habit');

View File

@@ -1,20 +1,21 @@
import { v4 as generateUUID } from 'uuid';
import { find } from 'lodash';
import {
generateUser,
createAndPopulateGroup,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
import { find } from 'lodash';
describe('POST /tasks/:taskId/assign/:memberId', () => {
let user, guild, member, member2, task;
let user; let guild; let member; let member2; let
task;
function findAssignedTask (memberTask) {
return memberTask.group.id === guild._id;
}
beforeEach(async () => {
let {group, members, groupLeader} = await createAndPopulateGroup({
const { group, members, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'Test Guild',
type: 'guild',
@@ -24,8 +25,8 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
guild = group;
user = groupLeader;
member = members[0];
member2 = members[1];
member = members[0]; // eslint-disable-line prefer-destructuring
member2 = members[1]; // eslint-disable-line prefer-destructuring
task = await user.post(`/tasks/group/${guild._id}`, {
text: 'test habit',
@@ -46,7 +47,7 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
});
it('returns error when task is not a group task', async () => {
let nonGroupTask = await user.post('/tasks/user', {
const nonGroupTask = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
up: false,
@@ -63,7 +64,7 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
});
it('returns error when user is not a member of the group', async () => {
let nonUser = await generateUser();
const nonUser = await generateUser();
await expect(nonUser.post(`/tasks/${task._id}/assign/${member._id}`))
.to.eventually.be.rejected.and.eql({
@@ -85,9 +86,9 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
it('allows user to assign themselves (claim)', async () => {
await member.post(`/tasks/${task._id}/assign/${member._id}`);
let groupTask = await user.get(`/tasks/group/${guild._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
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;
@@ -100,7 +101,7 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
await member.post(`/tasks/${task._id}/assign/${member._id}`);
await user.sync();
await member2.sync();
let groupTask = await user.get(`/tasks/group/${guild._id}`);
const groupTask = await user.get(`/tasks/group/${guild._id}`);
expect(user.notifications.length).to.equal(2); // includes Guild Joined achievement
expect(user.notifications[1].type).to.equal('GROUP_TASK_CLAIMED');
@@ -115,9 +116,9 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
it('assigns a task to a user', async () => {
await user.post(`/tasks/${task._id}/assign/${member._id}`);
let groupTask = await user.get(`/tasks/group/${guild._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
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;
@@ -127,7 +128,7 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
await user.post(`/tasks/${task._id}/assign/${member._id}`);
await member.sync();
let groupTask = await user.get(`/tasks/group/${guild._id}`);
const groupTask = await user.get(`/tasks/group/${guild._id}`);
expect(member.notifications.length).to.equal(1);
expect(member.notifications[0].type).to.equal('GROUP_TASK_ASSIGNED');
@@ -138,13 +139,13 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
await user.post(`/tasks/${task._id}/assign/${member._id}`);
await user.post(`/tasks/${task._id}/assign/${member2._id}`);
let groupTask = await user.get(`/tasks/group/${guild._id}`);
const groupTask = await user.get(`/tasks/group/${guild._id}`);
let memberTasks = await member.get('/tasks/user');
let member1SyncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const member1SyncedTask = find(memberTasks, findAssignedTask);
let member2Tasks = await member2.get('/tasks/user');
let member2SyncedTask = find(member2Tasks, findAssignedTask);
const member2Tasks = await member2.get('/tasks/user');
const member2SyncedTask = find(member2Tasks, findAssignedTask);
expect(groupTask[0].group.assignedUsers).to.contain(member._id);
expect(groupTask[0].group.assignedUsers).to.contain(member2._id);
@@ -159,9 +160,9 @@ describe('POST /tasks/:taskId/assign/:memberId', () => {
await member2.post(`/tasks/${task._id}/assign/${member._id}`);
let groupTask = await member2.get(`/tasks/group/${guild._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const groupTask = await member2.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;

View File

@@ -4,45 +4,46 @@ import {
} from '../../../../../helpers/api-integration/v3';
describe('POST group-tasks/:taskId/move/to/:position', () => {
let user, guild;
let user; let
guild;
beforeEach(async () => {
user = await generateUser({balance: 1});
guild = await generateGroup(user, {type: 'guild'});
user = await generateUser({ balance: 1 });
guild = await generateGroup(user, { type: 'guild' });
});
it('can move task to new position', async () => {
let tasks = await user.post(`/tasks/group/${guild._id}`, [
{type: 'habit', text: 'habit 1'},
{type: 'habit', text: 'habit 2'},
{type: 'daily', text: 'daily 1'},
{type: 'habit', text: 'habit 3'},
{type: 'habit', text: 'habit 4'},
{type: 'todo', text: 'todo 1'},
{type: 'habit', text: 'habit 5'},
const tasks = await user.post(`/tasks/group/${guild._id}`, [
{ type: 'habit', text: 'habit 1' },
{ type: 'habit', text: 'habit 2' },
{ type: 'daily', text: 'daily 1' },
{ type: 'habit', text: 'habit 3' },
{ type: 'habit', text: 'habit 4' },
{ type: 'todo', text: 'todo 1' },
{ type: 'habit', text: 'habit 5' },
]);
let taskToMove = tasks[1];
const taskToMove = tasks[1];
expect(taskToMove.text).to.equal('habit 2');
let newOrder = await user.post(`/group-tasks/${tasks[1]._id}/move/to/3`);
const newOrder = await user.post(`/group-tasks/${tasks[1]._id}/move/to/3`);
expect(newOrder[3]).to.equal(taskToMove._id);
expect(newOrder.length).to.equal(5);
});
it('can push to bottom', async () => {
let tasks = await user.post(`/tasks/group/${guild._id}`, [
{type: 'habit', text: 'habit 1'},
{type: 'habit', text: 'habit 2'},
{type: 'daily', text: 'daily 1'},
{type: 'habit', text: 'habit 3'},
{type: 'habit', text: 'habit 4'},
{type: 'todo', text: 'todo 1'},
{type: 'habit', text: 'habit 5'},
const tasks = await user.post(`/tasks/group/${guild._id}`, [
{ type: 'habit', text: 'habit 1' },
{ type: 'habit', text: 'habit 2' },
{ type: 'daily', text: 'daily 1' },
{ type: 'habit', text: 'habit 3' },
{ type: 'habit', text: 'habit 4' },
{ type: 'todo', text: 'todo 1' },
{ type: 'habit', text: 'habit 5' },
]);
let taskToMove = tasks[1];
const taskToMove = tasks[1];
expect(taskToMove.text).to.equal('habit 2');
let newOrder = await user.post(`/group-tasks/${tasks[1]._id}/move/to/-1`);
const newOrder = await user.post(`/group-tasks/${tasks[1]._id}/move/to/-1`);
expect(newOrder[4]).to.equal(taskToMove._id);
expect(newOrder.length).to.equal(5);
});

View File

@@ -1,20 +1,21 @@
import { v4 as generateUUID } from 'uuid';
import { find } from 'lodash';
import {
generateUser,
createAndPopulateGroup,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
import { find } from 'lodash';
describe('POST /tasks/:taskId/unassign/:memberId', () => {
let user, guild, member, member2, task;
let user; let guild; let member; let member2; let
task;
function findAssignedTask (memberTask) {
return memberTask.group.id === guild._id;
}
beforeEach(async () => {
let {group, members, groupLeader} = await createAndPopulateGroup({
const { group, members, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'Test Guild',
type: 'guild',
@@ -24,8 +25,8 @@ describe('POST /tasks/:taskId/unassign/:memberId', () => {
guild = group;
user = groupLeader;
member = members[0];
member2 = members[1];
member = members[0]; // eslint-disable-line prefer-destructuring
member2 = members[1]; // eslint-disable-line prefer-destructuring
task = await user.post(`/tasks/group/${guild._id}`, {
text: 'test habit',
@@ -48,7 +49,7 @@ describe('POST /tasks/:taskId/unassign/:memberId', () => {
});
it('returns error when task is not a group task', async () => {
let nonGroupTask = await user.post('/tasks/user', {
const nonGroupTask = await user.post('/tasks/user', {
text: 'test habit',
type: 'habit',
up: false,
@@ -65,7 +66,7 @@ describe('POST /tasks/:taskId/unassign/:memberId', () => {
});
it('returns error when user is not a member of the group', async () => {
let nonUser = await generateUser();
const nonUser = await generateUser();
await expect(nonUser.post(`/tasks/${task._id}/unassign/${member._id}`))
.to.eventually.be.rejected.and.eql({
@@ -78,9 +79,9 @@ describe('POST /tasks/:taskId/unassign/:memberId', () => {
it('unassigns a user from a task', async () => {
await user.post(`/tasks/${task._id}/unassign/${member._id}`);
let groupTask = await user.get(`/tasks/group/${guild._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
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;
@@ -98,13 +99,13 @@ describe('POST /tasks/:taskId/unassign/:memberId', () => {
await user.post(`/tasks/${task._id}/unassign/${member._id}`);
let groupTask = await user.get(`/tasks/group/${guild._id}`);
const groupTask = await user.get(`/tasks/group/${guild._id}`);
let memberTasks = await member.get('/tasks/user');
let member1SyncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const member1SyncedTask = find(memberTasks, findAssignedTask);
let member2Tasks = await member2.get('/tasks/user');
let member2SyncedTask = find(member2Tasks, findAssignedTask);
const member2Tasks = await member2.get('/tasks/user');
const member2SyncedTask = find(member2Tasks, findAssignedTask);
expect(groupTask[0].group.assignedUsers).to.not.contain(member._id);
expect(member1SyncedTask).to.not.exist;
@@ -120,9 +121,9 @@ describe('POST /tasks/:taskId/unassign/:memberId', () => {
await member2.post(`/tasks/${task._id}/unassign/${member._id}`);
let groupTask = await member2.get(`/tasks/group/${guild._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const groupTask = await member2.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;
@@ -131,9 +132,9 @@ describe('POST /tasks/:taskId/unassign/:memberId', () => {
it('allows a user to unassign themselves', async () => {
await member.post(`/tasks/${task._id}/unassign/${member._id}`);
let groupTask = await user.get(`/tasks/group/${guild._id}`);
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
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;

View File

@@ -1,17 +1,18 @@
import { find } from 'lodash';
import {
createAndPopulateGroup, translate as t,
} from '../../../../../helpers/api-integration/v3';
import {find} from 'lodash';
describe('PUT /tasks/:id', () => {
let user, guild, member, member2, task;
let user; let guild; let member; let member2; let
task;
function findAssignedTask (memberTask) {
return memberTask.group.id === guild._id;
}
beforeEach(async () => {
let {group, members, groupLeader} = await createAndPopulateGroup({
const { group, members, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'Test Guild',
type: 'guild',
@@ -21,8 +22,8 @@ describe('PUT /tasks/:id', () => {
guild = group;
user = groupLeader;
member = members[0];
member2 = members[1];
member = members[0]; // eslint-disable-line prefer-destructuring
member2 = members[1]; // eslint-disable-line prefer-destructuring
task = await user.post(`/tasks/group/${guild._id}`, {
text: 'test habit',
@@ -37,7 +38,7 @@ describe('PUT /tasks/:id', () => {
});
it('updates a group task', async () => {
let savedHabit = await user.put(`/tasks/${task._id}`, {
const savedHabit = await user.put(`/tasks/${task._id}`, {
notes: 'some new notes',
});
@@ -56,8 +57,8 @@ describe('PUT /tasks/:id', () => {
requiresApproval: true,
});
let memberTasks = await member2.get('/tasks/user');
let syncedTask = find(memberTasks, (memberTask) => memberTask.group.taskId === task._id);
const memberTasks = await member2.get('/tasks/user');
const syncedTask = find(memberTasks, memberTask => memberTask.group.taskId === task._id);
// score up to trigger approval
await expect(member2.post(`/tasks/${syncedTask._id}/score/up`))
@@ -107,8 +108,8 @@ describe('PUT /tasks/:id', () => {
});
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
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);
@@ -123,11 +124,11 @@ describe('PUT /tasks/:id', () => {
notes: 'some new notes',
});
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
const memberTasks = await member.get('/tasks/user');
const syncedTask = find(memberTasks, findAssignedTask);
let member2Tasks = await member2.get('/tasks/user');
let member2SyncedTask = find(member2Tasks, 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);
@@ -151,8 +152,8 @@ describe('PUT /tasks/:id', () => {
});
let memberTasks = await member.get('/tasks/user');
let syncedTask = find(memberTasks, findAssignedTask);
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);

View File

@@ -1,14 +1,15 @@
import { v4 as generateUUID } from 'uuid';
import {
createAndPopulateGroup,
translate as t,
} from '../../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('DELETE group /tasks/:taskId/checklist/:itemId', () => {
let user, guild, task;
let user; let guild; let
task;
before(async () => {
let {group, groupLeader} = await createAndPopulateGroup({
const { group, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'Test Guild',
type: 'guild',
@@ -26,7 +27,7 @@ describe('DELETE group /tasks/:taskId/checklist/:itemId', () => {
text: 'Daily with checklist',
});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, {text: 'Checklist Item 1', completed: false});
let savedTask = await user.post(`/tasks/${task._id}/checklist`, { text: 'Checklist Item 1', completed: false });
await user.del(`/tasks/${task._id}/checklist/${savedTask.checklist[0].id}`);
savedTask = await user.get(`/tasks/group/${guild._id}`);
@@ -35,7 +36,7 @@ describe('DELETE group /tasks/:taskId/checklist/:itemId', () => {
});
it('does not work with habits', async () => {
let habit = await user.post(`/tasks/group/${guild._id}`, {
const habit = await user.post(`/tasks/group/${guild._id}`, {
type: 'habit',
text: 'habit with checklist',
});
@@ -48,7 +49,7 @@ describe('DELETE group /tasks/:taskId/checklist/:itemId', () => {
});
it('does not work with rewards', async () => {
let reward = await user.post(`/tasks/group/${guild._id}`, {
const reward = await user.post(`/tasks/group/${guild._id}`, {
type: 'reward',
text: 'reward with checklist',
});
@@ -69,7 +70,7 @@ describe('DELETE group /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on checklist item not found', async () => {
let createdTask = await user.post(`/tasks/group/${guild._id}`, {
const createdTask = await user.post(`/tasks/group/${guild._id}`, {
type: 'daily',
text: 'daily with checklist',
});

View File

@@ -1,14 +1,15 @@
import { v4 as generateUUID } from 'uuid';
import {
createAndPopulateGroup,
translate as t,
} from '../../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST group /tasks/:taskId/checklist/', () => {
let user, guild, task;
let user; let guild; let
task;
before(async () => {
let {group, groupLeader} = await createAndPopulateGroup({
const { group, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'Test Guild',
type: 'guild',
@@ -32,8 +33,8 @@ describe('POST group /tasks/:taskId/checklist/', () => {
_id: 123,
});
let updatedTasks = await user.get(`/tasks/group/${guild._id}`);
let updatedTask = updatedTasks[0];
const updatedTasks = await user.get(`/tasks/group/${guild._id}`);
const updatedTask = updatedTasks[0];
expect(updatedTask.checklist.length).to.equal(1);
expect(updatedTask.checklist[0].text).to.equal('Checklist Item 1');
@@ -44,7 +45,7 @@ describe('POST group /tasks/:taskId/checklist/', () => {
});
it('does not add a checklist to habits', async () => {
let habit = await user.post(`/tasks/group/${guild._id}`, {
const habit = await user.post(`/tasks/group/${guild._id}`, {
type: 'habit',
text: 'habit with checklist',
});
@@ -59,7 +60,7 @@ describe('POST group /tasks/:taskId/checklist/', () => {
});
it('does not add a checklist to rewards', async () => {
let reward = await user.post(`/tasks/group/${guild._id}`, {
const reward = await user.post(`/tasks/group/${guild._id}`, {
type: 'reward',
text: 'reward with checklist',
});

View File

@@ -1,14 +1,15 @@
import { v4 as generateUUID } from 'uuid';
import {
createAndPopulateGroup,
translate as t,
} from '../../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('PUT group /tasks/:taskId/checklist/:itemId', () => {
let user, guild, task;
let user; let guild; let
task;
before(async () => {
let {group, groupLeader} = await createAndPopulateGroup({
const { group, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'Test Guild',
type: 'guild',
@@ -44,7 +45,7 @@ describe('PUT group /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on habits', async () => {
let habit = await user.post(`/tasks/group/${guild._id}`, {
const habit = await user.post(`/tasks/group/${guild._id}`, {
type: 'habit',
text: 'habit with checklist',
});
@@ -57,7 +58,7 @@ describe('PUT group /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on rewards', async () => {
let reward = await user.post(`/tasks/group/${guild._id}`, {
const reward = await user.post(`/tasks/group/${guild._id}`, {
type: 'reward',
text: 'reward with checklist',
});
@@ -78,7 +79,7 @@ describe('PUT group /tasks/:taskId/checklist/:itemId', () => {
});
it('fails on checklist item not found', async () => {
let createdTask = await user.post(`/tasks/group/${guild._id}`, {
const createdTask = await user.post(`/tasks/group/${guild._id}`, {
type: 'daily',
text: 'daily with checklist',
});

View File

@@ -1,14 +1,17 @@
import { v4 as generateUUID } from 'uuid';
import {
createAndPopulateGroup,
translate as t,
} from '../../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
// Currently we do not support adding tags to group original tasks, but if we do in the future, these tests will check
// Currently we do not support adding tags to group original tasks,
// but if we do in the future, these tests will check
xdescribe('DELETE group /tasks/:taskId/tags/:tagId', () => {
let user, guild, task;
let user; let guild; let
task;
before(async () => {
let {group, groupLeader} = await createAndPopulateGroup({
const { group, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'Test Guild',
type: 'guild',
@@ -26,18 +29,18 @@ xdescribe('DELETE group /tasks/:taskId/tags/:tagId', () => {
text: 'Task with tag',
});
let tag = await user.post('/tags', {name: 'Tag 1'});
const tag = await user.post('/tags', { name: 'Tag 1' });
await user.post(`/tasks/${task._id}/tags/${tag.id}`);
await user.del(`/tasks/${task._id}/tags/${tag.id}`);
let updatedTask = await user.get(`/tasks/group/${guild._id}`);
const updatedTask = await user.get(`/tasks/group/${guild._id}`);
expect(updatedTask[0].tags.length).to.equal(0);
});
it('only deletes existing tags', async () => {
let createdTask = await user.post(`/tasks/group/${guild._id}`, {
const createdTask = await user.post(`/tasks/group/${guild._id}`, {
type: 'habit',
text: 'Task with tag',
});

View File

@@ -1,15 +1,17 @@
import { v4 as generateUUID } from 'uuid';
import {
createAndPopulateGroup,
translate as t,
} from '../../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
// Currently we do not support adding tags to group original tasks, but if we do in the future, these tests will check
// Currently we do not support adding tags to group original tasks,
// but if we do in the future, these tests will check
xdescribe('POST group /tasks/:taskId/tags/:tagId', () => {
let user, guild, task;
let user; let guild; let
task;
before(async () => {
let {group, groupLeader} = await createAndPopulateGroup({
const { group, groupLeader } = await createAndPopulateGroup({
groupDetails: {
name: 'Test Guild',
type: 'guild',
@@ -27,8 +29,8 @@ xdescribe('POST group /tasks/:taskId/tags/:tagId', () => {
text: 'Task with tag',
});
let tag = await user.post('/tags', {name: 'Tag 1'});
let savedTask = await user.post(`/tasks/${task._id}/tags/${tag.id}`);
const tag = await user.post('/tags', { name: 'Tag 1' });
const savedTask = await user.post(`/tasks/${task._id}/tags/${tag.id}`);
expect(savedTask.tags[0]).to.equal(tag.id);
});
@@ -39,7 +41,7 @@ xdescribe('POST group /tasks/:taskId/tags/:tagId', () => {
text: 'Task with tag',
});
let tag = await user.post('/tags', {name: 'Tag 1'});
const tag = await user.post('/tags', { name: 'Tag 1' });
await user.post(`/tasks/${task._id}/tags/${tag.id}`);

View File

@@ -1,8 +1,8 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('DELETE /tasks/:taskId/tags/:tagId', () => {
let user;
@@ -12,40 +12,40 @@ describe('DELETE /tasks/:taskId/tags/:tagId', () => {
});
it('removes a tag from a task', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'habit',
text: 'Task with tag',
});
let tag = await user.post('/tags', {name: 'Tag 1'});
const tag = await user.post('/tags', { name: 'Tag 1' });
await user.post(`/tasks/${task._id}/tags/${tag.id}`);
await user.del(`/tasks/${task._id}/tags/${tag.id}`);
let updatedTask = await user.get(`/tasks/${task._id}`);
const updatedTask = await user.get(`/tasks/${task._id}`);
expect(updatedTask.tags.length).to.equal(0);
});
it('removes a tag from a task using task short name', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'habit',
text: 'Task with tag',
alias: 'habit-with-alias',
});
let tag = await user.post('/tags', {name: 'Tag 1'});
const tag = await user.post('/tags', { name: 'Tag 1' });
await user.post(`/tasks/${task._id}/tags/${tag.id}`);
await user.del(`/tasks/${task.alias}/tags/${tag.id}`);
let updatedTask = await user.get(`/tasks/${task._id}`);
const updatedTask = await user.get(`/tasks/${task._id}`);
expect(updatedTask.tags.length).to.equal(0);
});
it('only deletes existing tags', async () => {
let createdTask = await user.post('/tasks/user', {
const createdTask = await user.post('/tasks/user', {
type: 'habit',
text: 'Task with tag',
});

View File

@@ -1,8 +1,8 @@
import { v4 as generateUUID } from 'uuid';
import {
generateUser,
translate as t,
} from '../../../../../helpers/api-integration/v3';
import { v4 as generateUUID } from 'uuid';
describe('POST /tasks/:taskId/tags/:tagId', () => {
let user;
@@ -12,37 +12,37 @@ describe('POST /tasks/:taskId/tags/:tagId', () => {
});
it('adds a tag to a task', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'habit',
text: 'Task with tag',
});
let tag = await user.post('/tags', {name: 'Tag 1'});
let savedTask = await user.post(`/tasks/${task._id}/tags/${tag.id}`);
const tag = await user.post('/tags', { name: 'Tag 1' });
const savedTask = await user.post(`/tasks/${task._id}/tags/${tag.id}`);
expect(savedTask.tags[0]).to.equal(tag.id);
});
it('adds a tag to a task with alias', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'habit',
text: 'Task with tag',
alias: 'habit-with-alias',
});
let tag = await user.post('/tags', {name: 'Tag 1'});
let savedTask = await user.post(`/tasks/${task.alias}/tags/${tag.id}`);
const tag = await user.post('/tags', { name: 'Tag 1' });
const savedTask = await user.post(`/tasks/${task.alias}/tags/${tag.id}`);
expect(savedTask.tags[0]).to.equal(tag.id);
});
it('does not add a tag to a task twice', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'habit',
text: 'Task with tag',
});
let tag = await user.post('/tags', {name: 'Tag 1'});
const tag = await user.post('/tags', { name: 'Tag 1' });
await user.post(`/tasks/${task._id}/tags/${tag.id}`);
@@ -54,7 +54,7 @@ describe('POST /tasks/:taskId/tags/:tagId', () => {
});
it('does not add a non existing tag to a task', async () => {
let task = await user.post('/tasks/user', {
const task = await user.post('/tasks/user', {
type: 'habit',
text: 'Task with tag',
});