lint: Correct linting errors in api v3 tests

This commit is contained in:
Blade Barringer
2015-12-31 08:50:02 -06:00
parent 70151fd073
commit 9428c6d997
25 changed files with 218 additions and 234 deletions

View File

@@ -36,7 +36,7 @@ describe('GET /groups/:groupId/chat', () => {
}); });
it('returns Guild chat', () => { it('returns Guild chat', () => {
return user.get('/groups/' + group._id + '/chat') return user.get(`/groups/${group._id}/chat`)
.then((getChat) => { .then((getChat) => {
expect(getChat).to.eql(group.chat); expect(getChat).to.eql(group.chat);
}); });
@@ -67,7 +67,7 @@ describe('GET /groups/:groupId/chat', () => {
it('returns error if user is not member of requested private group', () => { it('returns error if user is not member of requested private group', () => {
return expect( return expect(
user.get('/groups/' + group._id + '/chat') user.get(`/groups/${group._id}/chat`)
) )
.to.eventually.be.rejected.and.eql({ .to.eventually.be.rejected.and.eql({
code: 404, code: 404,

View File

@@ -2,7 +2,7 @@ import {
generateUser, generateUser,
translate as t, translate as t,
} from '../../../../helpers/api-integration.helper'; } from '../../../../helpers/api-integration.helper';
import _ from 'lodash'; import { find } from 'lodash';
describe('POST /chat/:chatId/flag', () => { describe('POST /chat/:chatId/flag', () => {
let user; let user;
@@ -66,7 +66,7 @@ describe('POST /chat/:chatId/flag', () => {
return user.get(`/groups/${group._id}`); return user.get(`/groups/${group._id}`);
}) })
.then((updatedGroup) => { .then((updatedGroup) => {
let messageToCheck = _.find(updatedGroup.chat, {id: message.id}); let messageToCheck = find(updatedGroup.chat, {id: message.id});
expect(messageToCheck.flags[user._id]).to.equal(true); expect(messageToCheck.flags[user._id]).to.equal(true);
}); });
}); });
@@ -89,7 +89,7 @@ describe('POST /chat/:chatId/flag', () => {
return user.get(`/groups/${group._id}`); return user.get(`/groups/${group._id}`);
}) })
.then((updatedGroup) => { .then((updatedGroup) => {
let messageToCheck = _.find(updatedGroup.chat, {id: message.id}); let messageToCheck = find(updatedGroup.chat, {id: message.id});
expect(messageToCheck.flags[secondUser._id]).to.equal(true); expect(messageToCheck.flags[secondUser._id]).to.equal(true);
expect(messageToCheck.flagCount).to.equal(5); expect(messageToCheck.flagCount).to.equal(5);
}); });

View File

@@ -2,7 +2,7 @@ import {
generateUser, generateUser,
translate as t, translate as t,
} from '../../../../helpers/api-integration.helper'; } from '../../../../helpers/api-integration.helper';
import _ from 'lodash'; import { find } from 'lodash';
describe('POST /chat/:chatId/like', () => { describe('POST /chat/:chatId/like', () => {
let user; let user;
@@ -65,7 +65,7 @@ describe('POST /chat/:chatId/like', () => {
return user.get(`/groups/${group._id}`); return user.get(`/groups/${group._id}`);
}) })
.then((updatedGroup) => { .then((updatedGroup) => {
let messageToCheck = _.find(updatedGroup.chat, {id: message.id}); let messageToCheck = find(updatedGroup.chat, {id: message.id});
expect(messageToCheck.likes[user._id]).to.equal(true); expect(messageToCheck.likes[user._id]).to.equal(true);
}); });
}); });
@@ -89,7 +89,7 @@ describe('POST /chat/:chatId/like', () => {
return user.get(`/groups/${group._id}`); return user.get(`/groups/${group._id}`);
}) })
.then((updatedGroup) => { .then((updatedGroup) => {
let messageToCheck = _.find(updatedGroup.chat, {id: message.id}); let messageToCheck = find(updatedGroup.chat, {id: message.id});
expect(messageToCheck.likes[user._id]).to.equal(false); expect(messageToCheck.likes[user._id]).to.equal(false);
}); });
}); });

View File

@@ -20,7 +20,7 @@ describe('POST /group', () => {
return expect( return expect(
user.post('/groups', { user.post('/groups', {
name: groupName, name: groupName,
type: groupType type: groupType,
}) })
) )
.to.eventually.be.rejected.and.eql({ .to.eventually.be.rejected.and.eql({
@@ -38,7 +38,7 @@ describe('POST /group', () => {
return generateUser({balance: 1}).then((generatedUser) => { return generateUser({balance: 1}).then((generatedUser) => {
return generatedUser.post('/groups', { return generatedUser.post('/groups', {
name: groupName, name: groupName,
type: groupType type: groupType,
}); });
}) })
.then((result) => { .then((result) => {
@@ -54,13 +54,12 @@ describe('POST /group', () => {
let groupName = 'Test Private Guild'; let groupName = 'Test Private Guild';
let groupType = 'guild'; let groupType = 'guild';
let groupPrivacy = 'private'; let groupPrivacy = 'private';
let tmpUser;
return generateUser({balance: 1}).then((generatedUser) => { return generateUser({balance: 1}).then((generatedUser) => {
return generatedUser.post('/groups', { return generatedUser.post('/groups', {
name: groupName, name: groupName,
type: groupType, type: groupType,
privacy: groupPrivacy privacy: groupPrivacy,
}); });
}) })
.then((result) => { .then((result) => {
@@ -80,7 +79,7 @@ describe('POST /group', () => {
return user.post('/groups', { return user.post('/groups', {
name: groupName, name: groupName,
type: groupType type: groupType,
}) })
.then((result) => { .then((result) => {
expect(result._id).to.exist; expect(result._id).to.exist;
@@ -98,7 +97,7 @@ describe('POST /group', () => {
tmpUser = generatedUser; tmpUser = generatedUser;
return tmpUser.post('/groups', { return tmpUser.post('/groups', {
name: groupName, name: groupName,
type: groupType type: groupType,
}); });
}) })
.then(() => { .then(() => {

View File

@@ -12,13 +12,11 @@ describe('PUT /tags/:tagId', () => {
}); });
it('updates a tag given it\'s id', () => { it('updates a tag given it\'s id', () => {
let length;
return user.post('/tags', {name: 'Tag 1'}) return user.post('/tags', {name: 'Tag 1'})
.then((createdTag) => { .then((createdTag) => {
return user.put(`/tags/${createdTag._id}`, { return user.put(`/tags/${createdTag._id}`, {
name: 'Tag updated', name: 'Tag updated',
ignored: true ignored: true,
}); });
}) })
.then((updatedTag) => { .then((updatedTag) => {

View File

@@ -25,9 +25,9 @@ describe('DELETE /tasks/:id', () => {
}); });
it('deletes a user\'s task', () => { it('deletes a user\'s task', () => {
return user.del('/tasks/' + task._id) return user.del(`/tasks/${task._id}`)
.then(() => { .then(() => {
return expect(user.get('/tasks/' + task._id)).to.eventually.be.rejected.and.eql({ return expect(user.get(`/tasks/${task._id}`)).to.eventually.be.rejected.and.eql({
code: 404, code: 404,
error: 'NotFound', error: 'NotFound',
message: t('taskNotFound'), message: t('taskNotFound'),
@@ -54,7 +54,7 @@ describe('DELETE /tasks/:id', () => {
}); });
}) })
.then((task2) => { .then((task2) => {
return expect(user.del('/tasks/' + task2._id)).to.eventually.be.rejected.and.eql({ return expect(user.del(`/tasks/${task2._id}`)).to.eventually.be.rejected.and.eql({
code: 404, code: 404,
error: 'NotFound', error: 'NotFound',
message: t('taskNotFound'), message: t('taskNotFound'),

View File

@@ -1,6 +1,5 @@
import { import {
generateUser, generateUser,
translate as t,
} from '../../../../helpers/api-integration.helper'; } from '../../../../helpers/api-integration.helper';
import Q from 'q'; import Q from 'q';

View File

@@ -26,7 +26,7 @@ describe('GET /tasks/:id', () => {
}); });
it('gets specified task', () => { it('gets specified task', () => {
return user.get('/tasks/' + task._id) return user.get(`/tasks/${task._id}`)
.then((getTask) => { .then((getTask) => {
expect(getTask).to.eql(task); expect(getTask).to.eql(task);
}); });
@@ -38,7 +38,9 @@ describe('GET /tasks/:id', () => {
context('task cannot be accessed', () => { context('task cannot be accessed', () => {
it('cannot get a non-existant task', () => { it('cannot get a non-existant task', () => {
return expect(user.get('/tasks/' + generateUUID())).to.eventually.be.rejected.and.eql({ let dummyId = generateUUID();
return expect(user.get(`/tasks/${dummyId}`)).to.eventually.be.rejected.and.eql({
code: 404, code: 404,
error: 'NotFound', error: 'NotFound',
message: t('taskNotFound'), message: t('taskNotFound'),
@@ -57,7 +59,7 @@ describe('GET /tasks/:id', () => {
type: 'habit', type: 'habit',
}); });
}).then((task) => { }).then((task) => {
return expect(anotherUser.get('/tasks/' + task._id)).to.eventually.be.rejected.and.eql({ return expect(anotherUser.get(`/tasks/${task._id}`)).to.eventually.be.rejected.and.eql({
code: 404, code: 404,
error: 'NotFound', error: 'NotFound',
message: t('taskNotFound'), message: t('taskNotFound'),

View File

@@ -47,29 +47,29 @@ describe('POST /tasks/:id/score/:direction', () => {
it('completes todo when direction is up', () => { it('completes todo when direction is up', () => {
return user.post(`/tasks/${todo._id}/score/up`) return user.post(`/tasks/${todo._id}/score/up`)
.then((res) => user.get(`/tasks/${todo._id}`)) .then(() => user.get(`/tasks/${todo._id}`))
.then((task) => expect(task.completed).to.equal(true)); .then((task) => expect(task.completed).to.equal(true));
}); });
it('moves completed todos out of user.tasksOrder.todos', () => { it('moves completed todos out of user.tasksOrder.todos', () => {
return user.get('/user') return user.get('/user')
.then(user => { .then(usr => {
expect(user.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1); expect(usr.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1);
}).then(() => user.post(`/tasks/${todo._id}/score/up`)) }).then(() => user.post(`/tasks/${todo._id}/score/up`))
.then(() => user.get(`/tasks/${todo._id}`)) .then(() => user.get(`/tasks/${todo._id}`))
.then((updatedTask) => { .then((updatedTask) => {
expect(updatedTask.completed).to.equal(true); expect(updatedTask.completed).to.equal(true);
return user.get('/user'); return user.get('/user');
}) })
.then((user) => { .then((usr) => {
expect(user.tasksOrder.todos.indexOf(todo._id)).to.equal(-1); expect(usr.tasksOrder.todos.indexOf(todo._id)).to.equal(-1);
}); });
}); });
it('moves un-completed todos back into user.tasksOrder.todos', () => { it('moves un-completed todos back into user.tasksOrder.todos', () => {
return user.get('/user') return user.get('/user')
.then(user => { .then(usr => {
expect(user.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1); expect(usr.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1);
}).then(() => user.post(`/tasks/${todo._id}/score/up`)) }).then(() => user.post(`/tasks/${todo._id}/score/up`))
.then(() => user.post(`/tasks/${todo._id}/score/down`)) .then(() => user.post(`/tasks/${todo._id}/score/down`))
.then(() => user.get(`/tasks/${todo._id}`)) .then(() => user.get(`/tasks/${todo._id}`))
@@ -77,16 +77,16 @@ describe('POST /tasks/:id/score/:direction', () => {
expect(updatedTask.completed).to.equal(false); expect(updatedTask.completed).to.equal(false);
return user.get('/user'); return user.get('/user');
}) })
.then((user) => { .then((usr) => {
let l = user.tasksOrder.todos.length; let l = usr.tasksOrder.todos.length;
expect(user.tasksOrder.todos.indexOf(todo._id)).not.to.equal(-1); expect(usr.tasksOrder.todos.indexOf(todo._id)).not.to.equal(-1);
expect(user.tasksOrder.todos.indexOf(todo._id)).to.equal(l - 1); // Check that it was pushed at the bottom expect(usr.tasksOrder.todos.indexOf(todo._id)).to.equal(l - 1); // Check that it was pushed at the bottom
}); });
}); });
it('uncompletes todo when direction is down', () => { it('uncompletes todo when direction is down', () => {
return user.post(`/tasks/${todo._id}/score/down`) return user.post(`/tasks/${todo._id}/score/down`)
.then((res) => user.get(`/tasks/${todo._id}`)) .then(() => user.get(`/tasks/${todo._id}`))
.then((updatedTask) => { .then((updatedTask) => {
expect(updatedTask.completed).to.equal(false); expect(updatedTask.completed).to.equal(false);
}); });
@@ -98,7 +98,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('increases user\'s mp when direction is up', () => { it('increases user\'s mp when direction is up', () => {
return user.post(`/tasks/${todo._id}/score/up`) return user.post(`/tasks/${todo._id}/score/up`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp); expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp);
}); });
@@ -106,7 +106,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('decreases user\'s mp when direction is down', () => { it('decreases user\'s mp when direction is down', () => {
return user.post(`/tasks/${todo._id}/score/down`) return user.post(`/tasks/${todo._id}/score/down`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp); expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
}); });
@@ -114,7 +114,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('increases user\'s exp when direction is up', () => { it('increases user\'s exp when direction is up', () => {
return user.post(`/tasks/${todo._id}/score/up`) return user.post(`/tasks/${todo._id}/score/up`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp); expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp);
}); });
@@ -122,7 +122,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('decreases user\'s exp when direction is down', () => { it('decreases user\'s exp when direction is down', () => {
return user.post(`/tasks/${todo._id}/score/down`) return user.post(`/tasks/${todo._id}/score/down`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.exp).to.be.lessThan(user.stats.exp); expect(updatedUser.stats.exp).to.be.lessThan(user.stats.exp);
}); });
@@ -130,7 +130,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('increases user\'s gold when direction is up', () => { it('increases user\'s gold when direction is up', () => {
return user.post(`/tasks/${todo._id}/score/up`) return user.post(`/tasks/${todo._id}/score/up`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp); expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
}); });
@@ -138,7 +138,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('decreases user\'s gold when direction is down', () => { it('decreases user\'s gold when direction is down', () => {
return user.post(`/tasks/${todo._id}/score/down`) return user.post(`/tasks/${todo._id}/score/down`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.gp).to.be.lessThan(user.stats.gp); expect(updatedUser.stats.gp).to.be.lessThan(user.stats.gp);
}); });
@@ -159,13 +159,13 @@ describe('POST /tasks/:id/score/:direction', () => {
it('completes daily when direction is up', () => { it('completes daily when direction is up', () => {
return user.post(`/tasks/${daily._id}/score/up`) return user.post(`/tasks/${daily._id}/score/up`)
.then((res) => user.get(`/tasks/${daily._id}`)) .then(() => user.get(`/tasks/${daily._id}`))
.then((task) => expect(task.completed).to.equal(true)); .then((task) => expect(task.completed).to.equal(true));
}); });
it('uncompletes daily when direction is down', () => { it('uncompletes daily when direction is down', () => {
return user.post(`/tasks/${daily._id}/score/down`) return user.post(`/tasks/${daily._id}/score/down`)
.then((res) => user.get(`/tasks/${daily._id}`)) .then(() => user.get(`/tasks/${daily._id}`))
.then((task) => expect(task.completed).to.equal(false)); .then((task) => expect(task.completed).to.equal(false));
}); });
@@ -175,7 +175,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('increases user\'s mp when direction is up', () => { it('increases user\'s mp when direction is up', () => {
return user.post(`/tasks/${daily._id}/score/up`) return user.post(`/tasks/${daily._id}/score/up`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp); expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp);
}); });
@@ -183,7 +183,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('decreases user\'s mp when direction is down', () => { it('decreases user\'s mp when direction is down', () => {
return user.post(`/tasks/${daily._id}/score/down`) return user.post(`/tasks/${daily._id}/score/down`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp); expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
}); });
@@ -191,7 +191,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('increases user\'s exp when direction is up', () => { it('increases user\'s exp when direction is up', () => {
return user.post(`/tasks/${daily._id}/score/up`) return user.post(`/tasks/${daily._id}/score/up`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp); expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp);
}); });
@@ -199,7 +199,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('decreases user\'s exp when direction is down', () => { it('decreases user\'s exp when direction is down', () => {
return user.post(`/tasks/${daily._id}/score/down`) return user.post(`/tasks/${daily._id}/score/down`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.exp).to.be.lessThan(user.stats.exp); expect(updatedUser.stats.exp).to.be.lessThan(user.stats.exp);
}); });
@@ -207,7 +207,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('increases user\'s gold when direction is up', () => { it('increases user\'s gold when direction is up', () => {
return user.post(`/tasks/${daily._id}/score/up`) return user.post(`/tasks/${daily._id}/score/up`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp); expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
}); });
@@ -215,7 +215,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('decreases user\'s gold when direction is down', () => { it('decreases user\'s gold when direction is down', () => {
return user.post(`/tasks/${daily._id}/score/down`) return user.post(`/tasks/${daily._id}/score/down`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.gp).to.be.lessThan(user.stats.gp); expect(updatedUser.stats.gp).to.be.lessThan(user.stats.gp);
}); });
@@ -223,7 +223,7 @@ describe('POST /tasks/:id/score/:direction', () => {
}); });
context('habits', () => { context('habits', () => {
let habit, minusHabit, plusHabit, neitherHabit; let habit, minusHabit, plusHabit, neitherHabit; // eslint-disable-line no-unused-vars
beforeEach(() => { beforeEach(() => {
return user.post('/tasks', { return user.post('/tasks', {
@@ -262,7 +262,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('increases user\'s mp when direction is up', () => { it('increases user\'s mp when direction is up', () => {
return user.post(`/tasks/${habit._id}/score/up`) return user.post(`/tasks/${habit._id}/score/up`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp); expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp);
}); });
@@ -270,7 +270,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('decreases user\'s mp when direction is down', () => { it('decreases user\'s mp when direction is down', () => {
return user.post(`/tasks/${habit._id}/score/down`) return user.post(`/tasks/${habit._id}/score/down`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp); expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
}); });
@@ -278,7 +278,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('increases user\'s exp when direction is up', () => { it('increases user\'s exp when direction is up', () => {
return user.post(`/tasks/${habit._id}/score/up`) return user.post(`/tasks/${habit._id}/score/up`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp); expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp);
}); });
@@ -286,7 +286,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('increases user\'s gold when direction is up', () => { it('increases user\'s gold when direction is up', () => {
return user.post(`/tasks/${habit._id}/score/up`) return user.post(`/tasks/${habit._id}/score/up`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp); expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
}); });
@@ -308,7 +308,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('purchases reward', () => { it('purchases reward', () => {
return user.post(`/tasks/${reward._id}/score/up`) return user.post(`/tasks/${reward._id}/score/up`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(user.stats.gp).to.equal(updatedUser.stats.gp + 5); expect(user.stats.gp).to.equal(updatedUser.stats.gp + 5);
}); });
@@ -316,7 +316,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('does not change user\'s mp', () => { it('does not change user\'s mp', () => {
return user.post(`/tasks/${reward._id}/score/up`) return user.post(`/tasks/${reward._id}/score/up`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(user.stats.mp).to.equal(updatedUser.stats.mp); expect(user.stats.mp).to.equal(updatedUser.stats.mp);
}); });
@@ -324,7 +324,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('does not change user\'s exp', () => { it('does not change user\'s exp', () => {
return user.post(`/tasks/${reward._id}/score/up`) return user.post(`/tasks/${reward._id}/score/up`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(user.stats.exp).to.equal(updatedUser.stats.exp); expect(user.stats.exp).to.equal(updatedUser.stats.exp);
}); });
@@ -332,7 +332,7 @@ describe('POST /tasks/:id/score/:direction', () => {
it('does not allow a down direction', () => { it('does not allow a down direction', () => {
return user.post(`/tasks/${reward._id}/score/up`) return user.post(`/tasks/${reward._id}/score/up`)
.then((res) => user.get(`/user`)) .then(() => user.get(`/user`))
.then((updatedUser) => { .then((updatedUser) => {
expect(user.stats.mp).to.equal(updatedUser.stats.mp); expect(user.stats.mp).to.equal(updatedUser.stats.mp);
}); });

View File

@@ -1,6 +1,5 @@
import { import {
generateUser, generateUser,
translate as t,
} from '../../../../helpers/api-integration.helper'; } from '../../../../helpers/api-integration.helper';
import { v4 as generateUUID } from 'uuid'; import { v4 as generateUUID } from 'uuid';
@@ -28,7 +27,7 @@ describe('PUT /tasks/:id', () => {
it(`ignores setting _id, type, userId, history, createdAt, it(`ignores setting _id, type, userId, history, createdAt,
updatedAt, challenge, completed, streak, updatedAt, challenge, completed, streak,
dateCompleted fields`, () => { dateCompleted fields`, () => {
user.put('/tasks/' + task._id, { user.put(`/tasks/${task._id}`, {
_id: 123, _id: 123,
type: 'daily', type: 'daily',
userId: 123, userId: 123,
@@ -54,7 +53,7 @@ describe('PUT /tasks/:id', () => {
}); });
it('ignores invalid fields', () => { it('ignores invalid fields', () => {
user.put('/tasks/' + task._id, { user.put(`/tasks/${task._id}`, {
notValid: true, notValid: true,
}).then((savedTask) => { }).then((savedTask) => {
expect(savedTask.notValid).to.be.a('undefined'); expect(savedTask.notValid).to.be.a('undefined');
@@ -118,12 +117,12 @@ describe('PUT /tasks/:id', () => {
checklist: [ checklist: [
{text: 123, completed: false}, {text: 123, completed: false},
{text: 456, completed: true}, {text: 456, completed: true},
] ],
}).then((savedTodo) => { }).then(() => {
return user.put(`/tasks/${todo._id}`, { return user.put(`/tasks/${todo._id}`, {
checklist: [ checklist: [
{text: 789, completed: false}, {text: 789, completed: false},
] ],
}); });
}).then((savedTodo2) => { }).then((savedTodo2) => {
expect(savedTodo2.checklist.length).to.equal(1); expect(savedTodo2.checklist.length).to.equal(1);
@@ -136,9 +135,9 @@ describe('PUT /tasks/:id', () => {
let finalUUID = generateUUID(); let finalUUID = generateUUID();
return user.put(`/tasks/${todo._id}`, { return user.put(`/tasks/${todo._id}`, {
tags: [generateUUID(), generateUUID()], tags: [generateUUID(), generateUUID()],
}).then((savedTodo) => { }).then(() => {
return user.put(`/tasks/${todo._id}`, { return user.put(`/tasks/${todo._id}`, {
tags: [finalUUID] tags: [finalUUID],
}); });
}).then((savedTodo2) => { }).then((savedTodo2) => {
expect(savedTodo2.tags.length).to.equal(1); expect(savedTodo2.tags.length).to.equal(1);
@@ -161,8 +160,6 @@ describe('PUT /tasks/:id', () => {
}); });
it('updates a daily', () => { it('updates a daily', () => {
let now = new Date();
return user.put(`/tasks/${daily._id}`, { return user.put(`/tasks/${daily._id}`, {
text: 'some new text', text: 'some new text',
notes: 'some new notes', notes: 'some new notes',
@@ -181,12 +178,12 @@ describe('PUT /tasks/:id', () => {
checklist: [ checklist: [
{text: 123, completed: false}, {text: 123, completed: false},
{text: 456, completed: true}, {text: 456, completed: true},
] ],
}).then((savedDaily) => { }).then(() => {
return user.put(`/tasks/${daily._id}`, { return user.put(`/tasks/${daily._id}`, {
checklist: [ checklist: [
{text: 789, completed: false}, {text: 789, completed: false},
] ],
}); });
}).then((savedDaily2) => { }).then((savedDaily2) => {
expect(savedDaily2.checklist.length).to.equal(1); expect(savedDaily2.checklist.length).to.equal(1);
@@ -199,9 +196,9 @@ describe('PUT /tasks/:id', () => {
let finalUUID = generateUUID(); let finalUUID = generateUUID();
return user.put(`/tasks/${daily._id}`, { return user.put(`/tasks/${daily._id}`, {
tags: [generateUUID(), generateUUID()], tags: [generateUUID(), generateUUID()],
}).then((savedDaily) => { }).then(() => {
return user.put(`/tasks/${daily._id}`, { return user.put(`/tasks/${daily._id}`, {
tags: [finalUUID] tags: [finalUUID],
}); });
}).then((savedDaily2) => { }).then((savedDaily2) => {
expect(savedDaily2.tags.length).to.equal(1); expect(savedDaily2.tags.length).to.equal(1);
@@ -212,12 +209,12 @@ describe('PUT /tasks/:id', () => {
it('updates repeat, even if frequency is set to daily', () => { it('updates repeat, even if frequency is set to daily', () => {
return user.put(`/tasks/${daily._id}`, { return user.put(`/tasks/${daily._id}`, {
frequency: 'daily', frequency: 'daily',
}).then((savedDaily) => { }).then(() => {
return user.put(`/tasks/${daily._id}`, { return user.put(`/tasks/${daily._id}`, {
repeat: { repeat: {
m: false, m: false,
su: false su: false,
} },
}); });
}).then((savedDaily2) => { }).then((savedDaily2) => {
expect(savedDaily2.repeat).to.eql({ expect(savedDaily2.repeat).to.eql({
@@ -235,7 +232,7 @@ describe('PUT /tasks/:id', () => {
it('updates everyX, even if frequency is set to weekly', () => { it('updates everyX, even if frequency is set to weekly', () => {
return user.put(`/tasks/${daily._id}`, { return user.put(`/tasks/${daily._id}`, {
frequency: 'weekly', frequency: 'weekly',
}).then((savedDaily) => { }).then(() => {
return user.put(`/tasks/${daily._id}`, { return user.put(`/tasks/${daily._id}`, {
everyX: 5, everyX: 5,
}); });

View File

@@ -46,15 +46,13 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
}); });
}); });
it('does not work with rewards', () => { it('does not work with rewards', async () => {
let reward; let reward = await user.post('/tasks', {
return expect(user.post('/tasks', {
type: 'reward', type: 'reward',
text: 'reward with checklist', text: 'reward with checklist',
}).then(createdTask => { });
reward = createdTask;
return user.del(`/tasks/${reward._id}/checklist/${generateUUID()}`); await expect(user.del(`/tasks/${reward._id}/checklist/${generateUUID()}`)).to.eventually.be.rejected.and.eql({
}).then(checklistItem => {})).to.eventually.be.rejected.and.eql({
code: 400, code: 400,
error: 'BadRequest', error: 'BadRequest',
message: t('checklistOnlyDailyTodo'), message: t('checklistOnlyDailyTodo'),

View File

@@ -66,7 +66,7 @@ describe('POST /tasks/:taskId/checklist/', () => {
it('fails on task not found', () => { it('fails on task not found', () => {
return expect(user.post(`/tasks/${generateUUID()}/checklist`, { return expect(user.post(`/tasks/${generateUUID()}/checklist`, {
text: 'Checklist Item 1' text: 'Checklist Item 1',
})).to.eventually.be.rejected.and.eql({ })).to.eventually.be.rejected.and.eql({
code: 404, code: 404,
error: 'NotFound', error: 'NotFound',

View File

@@ -45,15 +45,13 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
}); });
}); });
it('fails on rewards', () => { it('fails on rewards', async () => {
let reward; let reward = await user.post('/tasks', {
return expect(user.post('/tasks', {
type: 'reward', type: 'reward',
text: 'reward with checklist', text: 'reward with checklist',
}).then(createdTask => { });
reward = createdTask;
return user.post(`/tasks/${reward._id}/checklist/${generateUUID()}/score`); await expect(user.post(`/tasks/${reward._id}/checklist/${generateUUID()}/score`)).to.eventually.be.rejected.and.eql({
}).then(checklistItem => {})).to.eventually.be.rejected.and.eql({
code: 400, code: 400,
error: 'BadRequest', error: 'BadRequest',
message: t('checklistOnlyDailyTodo'), message: t('checklistOnlyDailyTodo'),

View File

@@ -32,30 +32,26 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
}); });
}); });
it('fails on habits', () => { it('fails on habits', async () => {
let habit; let habit = await user.post('/tasks', {
return expect(user.post('/tasks', {
type: 'habit', type: 'habit',
text: 'habit with checklist', text: 'habit with checklist',
}).then(createdTask => { });
habit = createdTask;
return user.put(`/tasks/${habit._id}/checklist/${generateUUID()}`); await expect(user.put(`/tasks/${habit._id}/checklist/${generateUUID()}`)).to.eventually.be.rejected.and.eql({
})).to.eventually.be.rejected.and.eql({
code: 400, code: 400,
error: 'BadRequest', error: 'BadRequest',
message: t('checklistOnlyDailyTodo'), message: t('checklistOnlyDailyTodo'),
}); });
}); });
it('fails on rewards', () => { it('fails on rewards', async () => {
let reward; let reward = await user.post('/tasks', {
return expect(user.post('/tasks', {
type: 'reward', type: 'reward',
text: 'reward with checklist', text: 'reward with checklist',
}).then(createdTask => { });
reward = createdTask;
return user.put(`/tasks/${reward._id}/checklist/${generateUUID()}`); await expect(user.put(`/tasks/${reward._id}/checklist/${generateUUID()}`)).to.eventually.be.rejected.and.eql({
}).then(checklistItem => {})).to.eventually.be.rejected.and.eql({
code: 400, code: 400,
error: 'BadRequest', error: 'BadRequest',
message: t('checklistOnlyDailyTodo'), message: t('checklistOnlyDailyTodo'),

View File

@@ -26,7 +26,7 @@ describe('DELETE /tasks/:taskId/tags/:tagId', () => {
}).then(createdTag => { }).then(createdTag => {
tag = createdTag; tag = createdTag;
return user.post(`/tasks/${task._id}/tags/${tag._id}`); return user.post(`/tasks/${task._id}/tags/${tag._id}`);
}).then(savedTask => { }).then(() => {
return user.del(`/tasks/${task._id}/tags/${tag._id}`); return user.del(`/tasks/${task._id}/tags/${tag._id}`);
}).then(() => user.get(`/tasks/${task._id}`)) }).then(() => user.get(`/tasks/${task._id}`))
.then(updatedTask => { .then(updatedTask => {
@@ -35,8 +35,6 @@ describe('DELETE /tasks/:taskId/tags/:tagId', () => {
}); });
it('only deletes existing tags', () => { it('only deletes existing tags', () => {
let task;
return expect(user.post('/tasks', { return expect(user.post('/tasks', {
type: 'habit', type: 'habit',
text: 'Task with tag', text: 'Task with tag',

View File

@@ -37,7 +37,7 @@ describe('POST /user/auth/local/register', () => {
username, username,
email, email,
password, password,
confirmPassword: confirmPassword, confirmPassword,
})).to.eventually.be.rejected.and.eql({ })).to.eventually.be.rejected.and.eql({
code: 400, code: 400,
error: 'BadRequest', error: 'BadRequest',
@@ -104,8 +104,8 @@ describe('POST /user/auth/local/register', () => {
return expect(api.post('/user/auth/local/register', { return expect(api.post('/user/auth/local/register', {
username, username,
email: email, email,
confirmPassword: confirmPassword, confirmPassword,
})).to.eventually.be.rejected.and.eql({ })).to.eventually.be.rejected.and.eql({
code: 400, code: 400,
error: 'BadRequest', error: 'BadRequest',
@@ -123,7 +123,7 @@ describe('POST /user/auth/local/register', () => {
return generateUser({ return generateUser({
'auth.local.username': username, 'auth.local.username': username,
'auth.local.lowerCaseUsername': username, 'auth.local.lowerCaseUsername': username,
'auth.local.email': email 'auth.local.email': email,
}); });
}); });
@@ -133,9 +133,9 @@ describe('POST /user/auth/local/register', () => {
let password = 'password'; let password = 'password';
return expect(api.post('/user/auth/local/register', { return expect(api.post('/user/auth/local/register', {
username: username, username,
email: uniqueEmail, email: uniqueEmail,
password: password, password,
confirmPassword: password, confirmPassword: password,
})).to.eventually.be.rejected.and.eql({ })).to.eventually.be.rejected.and.eql({
code: 401, code: 401,
@@ -181,7 +181,7 @@ describe('POST /user/auth/local/register', () => {
}).then((user) => { }).then((user) => {
expect(user.flags.tour).to.not.be.empty; expect(user.flags.tour).to.not.be.empty;
each(user.flags.tour, (value, attribute) => { each(user.flags.tour, (value) => {
expect(value).to.eql(-2); expect(value).to.eql(-2);
}); });
}); });
@@ -232,7 +232,7 @@ describe('POST /user/auth/local/register', () => {
}).then((user) => { }).then((user) => {
expect(user.flags.tour).to.not.be.empty; expect(user.flags.tour).to.not.be.empty;
each(user.flags.tutorial.common, (value, attribute) => { each(user.flags.tutorial.common, (value) => {
expect(value).to.eql(true); expect(value).to.eql(true);
}); });
}); });

View File

@@ -6,12 +6,12 @@ describe('analyticsService', () => {
let amplitudeNock, gaNock; let amplitudeNock, gaNock;
beforeEach(() => { beforeEach(() => {
amplitudeNock = nock( 'https://api.amplitude.com') amplitudeNock = nock('https://api.amplitude.com')
.filteringPath(/httpapi.*/g, '') .filteringPath(/httpapi.*/g, '')
.post('/') .post('/')
.reply(200, {status: 'OK'}); .reply(200, {status: 'OK'});
gaNock = nock( 'http://www.google-analytics.com'); gaNock = nock('http://www.google-analytics.com');
}); });
describe('#track', () => { describe('#track', () => {
@@ -23,14 +23,14 @@ describe('analyticsService', () => {
category: 'behavior', category: 'behavior',
uuid: 'unique-user-id', uuid: 'unique-user-id',
resting: true, resting: true,
cronCount: 5 cronCount: 5,
}; };
}); });
context('Amplitude', () => { context('Amplitude', () => {
it('calls out to amplitude', () => { it('calls out to amplitude', () => {
return analyticsService.track(eventType, data) return analyticsService.track(eventType, data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -42,7 +42,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*user_id.*no-user-id-was-provided.*/g, ''); .filteringPath(/httpapi.*user_id.*no-user-id-was-provided.*/g, '');
return analyticsService.track(eventType, data) return analyticsService.track(eventType, data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -52,7 +52,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*platform.*server.*/g, ''); .filteringPath(/httpapi.*platform.*server.*/g, '');
return analyticsService.track(eventType, data) return analyticsService.track(eventType, data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -62,7 +62,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*event_properties%22%3A%7B%22category%22%3A%22behavior%22%2C%22resting%22%3Atrue%2C%22cronCount%22%3A5%7D%2C%22.*/g, ''); .filteringPath(/httpapi.*event_properties%22%3A%7B%22category%22%3A%22behavior%22%2C%22resting%22%3Atrue%2C%22cronCount%22%3A5%7D%2C%22.*/g, '');
return analyticsService.track(eventType, data) return analyticsService.track(eventType, data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -74,7 +74,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*itemName.*Fox%20Ears.*/g, ''); .filteringPath(/httpapi.*itemName.*Fox%20Ears.*/g, '');
return analyticsService.track(eventType, data) return analyticsService.track(eventType, data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -86,7 +86,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*itemName.*Wolf%20Egg.*/g, ''); .filteringPath(/httpapi.*itemName.*Wolf%20Egg.*/g, '');
return analyticsService.track(eventType, data) return analyticsService.track(eventType, data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -98,7 +98,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*itemName.*Bare%20Bones%20Cake.*/g, ''); .filteringPath(/httpapi.*itemName.*Bare%20Bones%20Cake.*/g, '');
return analyticsService.track(eventType, data) return analyticsService.track(eventType, data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -110,7 +110,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*itemName.*Golden%20Hatching%20Potion.*/g, ''); .filteringPath(/httpapi.*itemName.*Golden%20Hatching%20Potion.*/g, '');
return analyticsService.track(eventType, data) return analyticsService.track(eventType, data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -122,7 +122,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*itemName.*Attack%20of%20the%20Mundane%2C%20Part%201%3A%20Dish%20Disaster!.*/g, ''); .filteringPath(/httpapi.*itemName.*Attack%20of%20the%20Mundane%2C%20Part%201%3A%20Dish%20Disaster!.*/g, '');
return analyticsService.track(eventType, data) return analyticsService.track(eventType, data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -134,7 +134,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*itemName.*Seafoam.*/g, ''); .filteringPath(/httpapi.*itemName.*Seafoam.*/g, '');
return analyticsService.track(eventType, data) return analyticsService.track(eventType, data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -142,14 +142,14 @@ describe('analyticsService', () => {
it('sends user data if provided', () => { it('sends user data if provided', () => {
let stats = { class: 'wizard', exp: 5, gp: 23, hp: 10, lvl: 4, mp: 30 }; let stats = { class: 'wizard', exp: 5, gp: 23, hp: 10, lvl: 4, mp: 30 };
let user = { let user = {
stats: stats, stats,
contributor: { level: 1 }, contributor: { level: 1 },
purchased: { plan: { planId: 'foo-plan' } }, purchased: { plan: { planId: 'foo-plan' } },
flags: {tour: {intro: -2}}, flags: {tour: {intro: -2}},
habits: [{_id: 'habit'}], habits: [{_id: 'habit'}],
dailys: [{_id: 'daily'}], dailys: [{_id: 'daily'}],
todos: [{_id: 'todo'}], todos: [{_id: 'todo'}],
rewards: [{_id: 'reward'}] rewards: [{_id: 'reward'}],
}; };
data.user = user; data.user = user;
@@ -158,7 +158,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*user_properties%22%3A%7B%22Class%22%3A%22wizard%22%2C%22Experience%22%3A5%2C%22Gold%22%3A23%2C%22Health%22%3A10%2C%22Level%22%3A4%2C%22Mana%22%3A30%2C%22tutorialComplete%22%3Atrue%2C%22Number%20Of%20Tasks%22%3A%7B%22habits%22%3A1%2C%22dailys%22%3A1%2C%22todos%22%3A1%2C%22rewards%22%3A1%7D%2C%22contributorLevel%22%3A1%2C%22subscription%22%3A%22foo-plan%22%7D%2C%22.*/g, ''); .filteringPath(/httpapi.*user_properties%22%3A%7B%22Class%22%3A%22wizard%22%2C%22Experience%22%3A5%2C%22Gold%22%3A23%2C%22Health%22%3A10%2C%22Level%22%3A4%2C%22Mana%22%3A30%2C%22tutorialComplete%22%3Atrue%2C%22Number%20Of%20Tasks%22%3A%7B%22habits%22%3A1%2C%22dailys%22%3A1%2C%22todos%22%3A1%2C%22rewards%22%3A1%7D%2C%22contributorLevel%22%3A1%2C%22subscription%22%3A%22foo-plan%22%7D%2C%22.*/g, '');
return analyticsService.track(eventType, data) return analyticsService.track(eventType, data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -171,7 +171,7 @@ describe('analyticsService', () => {
.reply(200, {status: 'OK'}); .reply(200, {status: 'OK'});
return analyticsService.track(eventType, data) return analyticsService.track(eventType, data)
.then((res) => { .then(() => {
gaNock.done(); gaNock.done();
}); });
}); });
@@ -182,7 +182,7 @@ describe('analyticsService', () => {
.reply(200, {status: 'OK'}); .reply(200, {status: 'OK'});
return analyticsService.track(eventType, data) return analyticsService.track(eventType, data)
.then((res) => { .then(() => {
gaNock.done(); gaNock.done();
}); });
}); });
@@ -201,14 +201,14 @@ describe('analyticsService', () => {
purchaseValue: 8, purchaseValue: 8,
purchaseType: 'checkout', purchaseType: 'checkout',
gift: false, gift: false,
quantity: 1 quantity: 1,
}; };
}); });
context('Amplitude', () => { context('Amplitude', () => {
it('calls out to amplitude', () => { it('calls out to amplitude', () => {
return analyticsService.trackPurchase(data) return analyticsService.trackPurchase(data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -220,7 +220,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*user_id.*no-user-id-was-provided.*/g, ''); .filteringPath(/httpapi.*user_id.*no-user-id-was-provided.*/g, '');
return analyticsService.trackPurchase(data) return analyticsService.trackPurchase(data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -230,7 +230,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*platform.*server.*/g, ''); .filteringPath(/httpapi.*platform.*server.*/g, '');
return analyticsService.trackPurchase(data) return analyticsService.trackPurchase(data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -240,7 +240,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*aypal-checkout%22%2C%22paymentMethod%22%3A%22PayPal%22%2C%22itemPurchased%22%3A%22Gems%22%2C%22purchaseType%22%3A%22checkout%22%2C%22gift%22%3Afalse%2C%22quantity%22%3A1%7D%2C%22event_type%22%3A%22purchase%22%2C%22revenue.*/g, ''); .filteringPath(/httpapi.*aypal-checkout%22%2C%22paymentMethod%22%3A%22PayPal%22%2C%22itemPurchased%22%3A%22Gems%22%2C%22purchaseType%22%3A%22checkout%22%2C%22gift%22%3Afalse%2C%22quantity%22%3A1%7D%2C%22event_type%22%3A%22purchase%22%2C%22revenue.*/g, '');
return analyticsService.trackPurchase(data) return analyticsService.trackPurchase(data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -248,14 +248,14 @@ describe('analyticsService', () => {
it('sends user data if provided', () => { it('sends user data if provided', () => {
let stats = { class: 'wizard', exp: 5, gp: 23, hp: 10, lvl: 4, mp: 30 }; let stats = { class: 'wizard', exp: 5, gp: 23, hp: 10, lvl: 4, mp: 30 };
let user = { let user = {
stats: stats, stats,
contributor: { level: 1 }, contributor: { level: 1 },
purchased: { plan: { planId: 'foo-plan' } }, purchased: { plan: { planId: 'foo-plan' } },
flags: {tour: {intro: -2}}, flags: {tour: {intro: -2}},
habits: [{_id: 'habit'}], habits: [{_id: 'habit'}],
dailys: [{_id: 'daily'}], dailys: [{_id: 'daily'}],
todos: [{_id: 'todo'}], todos: [{_id: 'todo'}],
rewards: [{_id: 'reward'}] rewards: [{_id: 'reward'}],
}; };
data.user = user; data.user = user;
@@ -264,7 +264,7 @@ describe('analyticsService', () => {
.filteringPath(/httpapi.*user_properties%22%3A%7B%22Class%22%3A%22wizard%22%2C%22Experience%22%3A5%2C%22Gold%22%3A23%2C%22Health%22%3A10%2C%22Level%22%3A4%2C%22Mana%22%3A30%2C%22tutorialComplete%22%3Atrue%2C%22Number%20Of%20Tasks%22%3A%7B%22habits%22%3A1%2C%22dailys%22%3A1%2C%22todos%22%3A1%2C%22rewards%22%3A1%7D%2C%22contributorLevel%22%3A1%2C%22subscription%22%3A%22foo-plan%22%7D%2C%22.*/g, ''); .filteringPath(/httpapi.*user_properties%22%3A%7B%22Class%22%3A%22wizard%22%2C%22Experience%22%3A5%2C%22Gold%22%3A23%2C%22Health%22%3A10%2C%22Level%22%3A4%2C%22Mana%22%3A30%2C%22tutorialComplete%22%3Atrue%2C%22Number%20Of%20Tasks%22%3A%7B%22habits%22%3A1%2C%22dailys%22%3A1%2C%22todos%22%3A1%2C%22rewards%22%3A1%7D%2C%22contributorLevel%22%3A1%2C%22subscription%22%3A%22foo-plan%22%7D%2C%22.*/g, '');
return analyticsService.trackPurchase(data) return analyticsService.trackPurchase(data)
.then((res) => { .then(() => {
amplitudeNock.done(); amplitudeNock.done();
}); });
}); });
@@ -277,7 +277,7 @@ describe('analyticsService', () => {
.reply(200, {status: 'OK'}); .reply(200, {status: 'OK'});
return analyticsService.trackPurchase(data) return analyticsService.trackPurchase(data)
.then((res) => { .then(() => {
gaNock.done(); gaNock.done();
}); });
}); });
@@ -290,7 +290,7 @@ describe('analyticsService', () => {
.reply(200, {status: 'OK'}); .reply(200, {status: 'OK'});
return analyticsService.trackPurchase(data) return analyticsService.trackPurchase(data)
.then((res) => { .then(() => {
gaNock.done(); gaNock.done();
}); });
}); });

View File

@@ -32,7 +32,7 @@ describe('Base model plugin', () => {
it('can sanitize input objects', () => { it('can sanitize input objects', () => {
baseModel(schema, { baseModel(schema, {
noSet: ['noUpdateForMe'] noSet: ['noUpdateForMe'],
}); });
expect(schema.statics.sanitize).to.exist; expect(schema.statics.sanitize).to.exist;
@@ -45,7 +45,7 @@ describe('Base model plugin', () => {
it('accepts an array of additional fields to sanitize at runtime', () => { it('accepts an array of additional fields to sanitize at runtime', () => {
baseModel(schema, { baseModel(schema, {
noSet: ['noUpdateForMe'] noSet: ['noUpdateForMe'],
}); });
expect(schema.statics.sanitize).to.exist; expect(schema.statics.sanitize).to.exist;
@@ -59,7 +59,7 @@ describe('Base model plugin', () => {
it('can make fields private', () => { it('can make fields private', () => {
baseModel(schema, { baseModel(schema, {
private: ['amPrivate'] private: ['amPrivate'],
}); });
expect(schema.options.toJSON.transform).to.exist; expect(schema.options.toJSON.transform).to.exist;
@@ -73,7 +73,7 @@ describe('Base model plugin', () => {
it('accepts a further transform function for toJSON', () => { it('accepts a further transform function for toJSON', () => {
let options = { let options = {
private: ['amPrivate'], private: ['amPrivate'],
toJSONTransform: sandbox.stub().returns(true) toJSONTransform: sandbox.stub().returns(true),
}; };
baseModel(schema, options); baseModel(schema, options);
@@ -88,7 +88,7 @@ describe('Base model plugin', () => {
it('accepts a transform function for sanitize', () => { it('accepts a transform function for sanitize', () => {
let options = { let options = {
private: ['amPrivate'], private: ['amPrivate'],
sanitizeTransform: sandbox.stub().returns(true) sanitizeTransform: sandbox.stub().returns(true),
}; };
baseModel(schema, options); baseModel(schema, options);

View File

@@ -11,8 +11,9 @@ describe('Build Manifest', () => {
}); });
it('throws an error in case the page does not exist', () => { it('throws an error in case the page does not exist', () => {
let getManifestFilesFn = () => { getManifestFiles('strange name here'); }; expect(() => {
expect(getManifestFilesFn).to.throw(Error); getManifestFiles('strange name here');
}).to.throw(Error);
}); });
}); });
}); });

View File

@@ -1,3 +1,4 @@
/* eslint-disable global-require */
import request from 'request'; import request from 'request';
import nconf from 'nconf'; import nconf from 'nconf';
import nodemailer from 'nodemailer'; import nodemailer from 'nodemailer';
@@ -14,17 +15,17 @@ function getUser () {
}, },
facebook: { facebook: {
emails: [{ emails: [{
value: 'email@facebook' value: 'email@facebook',
}], }],
displayName: 'fb display name', displayName: 'fb display name',
} },
}, },
profile: { profile: {
name: 'profile name', name: 'profile name',
}, },
preferences: { preferences: {
emailNotifications: { emailNotifications: {
unsubscribeFromAll: false unsubscribeFromAll: false,
}, },
}, },
}; };
@@ -63,7 +64,7 @@ describe('emails', () => {
attachEmail.send(); attachEmail.send();
expect(sendMailSpy).to.be.calledOnce; expect(sendMailSpy).to.be.calledOnce;
deferred.reject(); deferred.reject();
deferred.promise.catch((err) => { deferred.promise.catch(() => {
expect(logger.error).to.be.calledOnce; expect(logger.error).to.be.calledOnce;
done(); done();
}); });
@@ -93,8 +94,8 @@ describe('emails', () => {
let attachEmail = require(pathToEmailLib); let attachEmail = require(pathToEmailLib);
let getUserInfo = attachEmail.getUserInfo; let getUserInfo = attachEmail.getUserInfo;
let user = getUser(); let user = getUser();
delete user.profile['name']; delete user.profile.name;
delete user.auth['local']; delete user.auth.local;
let data = getUserInfo(user, ['name', 'email', '_id', 'canSend']); let data = getUserInfo(user, ['name', 'email', '_id', 'canSend']);
@@ -108,9 +109,9 @@ describe('emails', () => {
let attachEmail = require(pathToEmailLib); let attachEmail = require(pathToEmailLib);
let getUserInfo = attachEmail.getUserInfo; let getUserInfo = attachEmail.getUserInfo;
let user = getUser(); let user = getUser();
delete user.profile['name']; delete user.profile.name;
delete user.auth.local['email']; delete user.auth.local.email;
delete user.auth['facebook']; delete user.auth.facebook;
let data = getUserInfo(user, ['name', 'email', '_id', 'canSend']); let data = getUserInfo(user, ['name', 'email', '_id', 'canSend']);
@@ -148,8 +149,8 @@ describe('emails', () => {
to: sinon.match((value) => { to: sinon.match((value) => {
return Array.isArray(value) && value[0].name === mailingInfo.name; return Array.isArray(value) && value[0].name === mailingInfo.name;
}, 'matches mailing info array'), }, 'matches mailing info array'),
} },
} },
})); }));
}); });
@@ -160,7 +161,7 @@ describe('emails', () => {
let emailType = 'an email type'; let emailType = 'an email type';
let mailingInfo = { let mailingInfo = {
name: 'my name', name: 'my name',
//email: 'my@email', // email: 'my@email',
}; };
sendTxnEmail(mailingInfo, emailType); sendTxnEmail(mailingInfo, emailType);
@@ -180,8 +181,8 @@ describe('emails', () => {
data: { data: {
emailType: sinon.match.same(emailType), emailType: sinon.match.same(emailType),
to: sinon.match(val => val[0]._id === mailingInfo._id), to: sinon.match(val => val[0]._id === mailingInfo._id),
} },
} },
})); }));
}); });
@@ -204,13 +205,12 @@ describe('emails', () => {
return value[0].name === 'BASE_URL'; return value[0].name === 'BASE_URL';
}, 'matches variables'), }, 'matches variables'),
personalVariables: sinon.match((value) => { personalVariables: sinon.match((value) => {
return (value[0].rcpt === mailingInfo.email return value[0].rcpt === mailingInfo.email &&
&& value[0].vars[0].name === 'RECIPIENT_NAME' value[0].vars[0].name === 'RECIPIENT_NAME' &&
&& value[0].vars[1].name === 'RECIPIENT_UNSUB_URL' value[0].vars[1].name === 'RECIPIENT_UNSUB_URL';
);
}, 'matches personal variables'), }, 'matches personal variables'),
} },
} },
})); }));
}); });
}); });

View File

@@ -2,7 +2,6 @@ import request from 'request';
import { sendTaskWebhook } from '../../../../../website/src/libs/api-v3/webhook'; import { sendTaskWebhook } from '../../../../../website/src/libs/api-v3/webhook';
describe('webhooks', () => { describe('webhooks', () => {
beforeEach(() => { beforeEach(() => {
sandbox.stub(request, 'post'); sandbox.stub(request, 'post');
}); });
@@ -15,12 +14,12 @@ describe('webhooks', () => {
let task = { let task = {
details: { _id: 'task-id' }, details: { _id: 'task-id' },
delta: 1.4, delta: 1.4,
direction: 'up' direction: 'up',
}; };
let data = { let data = {
task: task, task,
user: { _id: 'user-id' } user: { _id: 'user-id' },
}; };
it('does not send if no webhook endpoints exist', () => { it('does not send if no webhook endpoints exist', () => {
@@ -37,8 +36,8 @@ describe('webhooks', () => {
sort: 0, sort: 0,
id: 'some-id', id: 'some-id',
enabled: false, enabled: false,
url: 'http://example.org/endpoint' url: 'http://example.org/endpoint',
} },
}; };
sendTaskWebhook(webhooks, data); sendTaskWebhook(webhooks, data);
@@ -52,8 +51,8 @@ describe('webhooks', () => {
sort: 0, sort: 0,
id: 'some-id', id: 'some-id',
enabled: true, enabled: true,
url: 'http://malformedurl/endpoint' url: 'http://malformedurl/endpoint',
} },
}; };
sendTaskWebhook(webhooks, data); sendTaskWebhook(webhooks, data);
@@ -67,8 +66,8 @@ describe('webhooks', () => {
sort: 0, sort: 0,
id: 'some-id', id: 'some-id',
enabled: true, enabled: true,
url: 'http://example.org/endpoint' url: 'http://example.org/endpoint',
} },
}; };
sendTaskWebhook(webhooks, data); sendTaskWebhook(webhooks, data);
@@ -81,10 +80,10 @@ describe('webhooks', () => {
task: { _id: 'task-id' }, task: { _id: 'task-id' },
delta: 1.4, delta: 1.4,
user: { user: {
_id: 'user-id' _id: 'user-id',
} },
}, },
json: true json: true,
}); });
}); });
@@ -94,14 +93,14 @@ describe('webhooks', () => {
sort: 0, sort: 0,
id: 'some-id', id: 'some-id',
enabled: true, enabled: true,
url: 'http://example.org/endpoint' url: 'http://example.org/endpoint',
}, },
'second-webhook': { 'second-webhook': {
sort: 1, sort: 1,
id: 'second-webhook', id: 'second-webhook',
enabled: true, enabled: true,
url: 'http://example.com/2/endpoint' url: 'http://example.com/2/endpoint',
} },
}; };
sendTaskWebhook(webhooks, data); sendTaskWebhook(webhooks, data);
@@ -114,10 +113,10 @@ describe('webhooks', () => {
task: { _id: 'task-id' }, task: { _id: 'task-id' },
delta: 1.4, delta: 1.4,
user: { user: {
_id: 'user-id' _id: 'user-id',
} },
}, },
json: true json: true,
}); });
expect(request.post).to.be.calledWith({ expect(request.post).to.be.calledWith({
url: 'http://example.com/2/endpoint', url: 'http://example.com/2/endpoint',
@@ -126,10 +125,10 @@ describe('webhooks', () => {
task: { _id: 'task-id' }, task: { _id: 'task-id' },
delta: 1.4, delta: 1.4,
user: { user: {
_id: 'user-id' _id: 'user-id',
} },
}, },
json: true json: true,
}); });
}); });
}); });

View File

@@ -1,3 +1,4 @@
/* eslint-disable global-require */
import { import {
generateRes, generateRes,
generateReq, generateReq,
@@ -6,7 +7,7 @@ import {
import analyticsService from '../../../../../website/src/libs/api-v3/analyticsService'; import analyticsService from '../../../../../website/src/libs/api-v3/analyticsService';
import nconf from 'nconf'; import nconf from 'nconf';
describe('analytics middleware', function () { describe('analytics middleware', () => {
let res, req, next; let res, req, next;
let pathToAnalyticsMiddleware = '../../../../../website/src/middlewares/api-v3/analytics'; let pathToAnalyticsMiddleware = '../../../../../website/src/middlewares/api-v3/analytics';
@@ -23,7 +24,7 @@ describe('analytics middleware', function () {
delete require.cache[require.resolve(pathToAnalyticsMiddleware)]; delete require.cache[require.resolve(pathToAnalyticsMiddleware)];
}); });
it('attaches analytics object res.locals', function () { it('attaches analytics object res.locals', () => {
let attachAnalytics = require(pathToAnalyticsMiddleware); let attachAnalytics = require(pathToAnalyticsMiddleware);
attachAnalytics(req, res, next); attachAnalytics(req, res, next);

View File

@@ -115,7 +115,7 @@ describe('errorHandler', () => {
error: 'BadRequest', error: 'BadRequest',
message: 'Invalid request parameters.', message: 'Invalid request parameters.',
errors: [ errors: [
{param: error[0].param, value: error[0].value, message: error[0].msg} { param: error[0].param, value: error[0].value, message: error[0].msg },
], ],
}); });
}); });
@@ -142,8 +142,8 @@ describe('errorHandler', () => {
error: 'BadRequest', error: 'BadRequest',
message: 'User validation failed.', message: 'User validation failed.',
errors: [ errors: [
{path: 'auth.local.email', message: 'Invalid email.', value: 'not an email'} { path: 'auth.local.email', message: 'Invalid email.', value: 'not an email' },
] ],
}); });
}); });

View File

@@ -7,15 +7,13 @@ import getUserLanguage from '../../../../../website/src/middlewares/api-v3/getUs
import { i18n } from '../../../../../common'; import { i18n } from '../../../../../common';
import Q from 'q'; import Q from 'q';
import { model as User } from '../../../../../website/src/models/user'; import { model as User } from '../../../../../website/src/models/user';
import { translations } from '../../../../../website/src/libs/api-v3/i18n';
import accepts from 'accepts';
describe('getUserLanguage', () => { describe('getUserLanguage', () => {
let res, req, next; let res, req, next;
let checkResT = (req) => { let checkResT = (resToCheck) => {
expect(res.t).to.be.a('function'); expect(resToCheck.t).to.be.a('function');
expect(res.t('help')).to.equal(i18n.t('help', req.language)); expect(resToCheck.t('help')).to.equal(i18n.t('help', req.language));
}; };
beforeEach(() => { beforeEach(() => {
@@ -32,7 +30,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, next); getUserLanguage(req, res, next);
expect(req.language).to.equal('es'); expect(req.language).to.equal('es');
checkResT(req); checkResT(res);
}); });
it('falls back to english if the query parameter language does not exists', () => { it('falls back to english if the query parameter language does not exists', () => {
@@ -42,7 +40,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, next); getUserLanguage(req, res, next);
expect(req.language).to.equal('en'); expect(req.language).to.equal('en');
checkResT(req); checkResT(res);
}); });
it('uses query even if the request includes a user and session', () => { it('uses query even if the request includes a user and session', () => {
@@ -59,12 +57,12 @@ describe('getUserLanguage', () => {
}; };
req.session = { req.session = {
userId: 123 userId: 123,
}; };
getUserLanguage(req, res, next); getUserLanguage(req, res, next);
expect(req.language).to.equal('es'); expect(req.language).to.equal('es');
checkResT(req); checkResT(res);
}); });
}); });
@@ -80,7 +78,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, next); getUserLanguage(req, res, next);
expect(req.language).to.equal('it'); expect(req.language).to.equal('it');
checkResT(req); checkResT(res);
}); });
it('falls back to english if the user preferred language is not avalaible', (done) => { it('falls back to english if the user preferred language is not avalaible', (done) => {
@@ -94,7 +92,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('en'); expect(req.language).to.equal('en');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });
@@ -109,12 +107,12 @@ describe('getUserLanguage', () => {
}; };
req.session = { req.session = {
userId: 123 userId: 123,
}; };
getUserLanguage(req, res, next); getUserLanguage(req, res, next);
expect(req.language).to.equal('it'); expect(req.language).to.equal('it');
checkResT(req); checkResT(res);
}); });
}); });
@@ -125,18 +123,18 @@ describe('getUserLanguage', () => {
return Q.resolve({ return Q.resolve({
preferences: { preferences: {
language: 'it', language: 'it',
} },
}); });
} },
}); });
req.session = { req.session = {
userId: 123 userId: 123,
}; };
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('it'); expect(req.language).to.equal('it');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });
@@ -148,7 +146,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('pt'); expect(req.language).to.equal('pt');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });
@@ -158,7 +156,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('he'); expect(req.language).to.equal('he');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });
@@ -168,7 +166,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('he'); expect(req.language).to.equal('he');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });
@@ -178,7 +176,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('fr'); expect(req.language).to.equal('fr');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });
@@ -188,7 +186,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('fr'); expect(req.language).to.equal('fr');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });
@@ -198,7 +196,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('es'); expect(req.language).to.equal('es');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });
@@ -208,7 +206,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('es_419'); expect(req.language).to.equal('es_419');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });
@@ -218,7 +216,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('es_419'); expect(req.language).to.equal('es_419');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });
@@ -228,7 +226,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('zh_TW'); expect(req.language).to.equal('zh_TW');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });
@@ -238,7 +236,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('en'); expect(req.language).to.equal('en');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });
@@ -248,7 +246,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('en'); expect(req.language).to.equal('en');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });
@@ -258,7 +256,7 @@ describe('getUserLanguage', () => {
getUserLanguage(req, res, () => { getUserLanguage(req, res, () => {
expect(req.language).to.equal('en'); expect(req.language).to.equal('en');
checkResT(req); checkResT(res);
done(); done();
}); });
}); });

View File

@@ -5,7 +5,7 @@ import {
} from '../../../../helpers/api-unit.helper'; } from '../../../../helpers/api-unit.helper';
import responseMiddleware from '../../../../../website/src/middlewares/api-v3/response'; import responseMiddleware from '../../../../../website/src/middlewares/api-v3/response';
describe('response middleware', function () { describe('response middleware', () => {
let res, req, next; let res, req, next;
beforeEach(() => { beforeEach(() => {
@@ -15,13 +15,13 @@ describe('response middleware', function () {
}); });
it('attaches respond method to res', function () { it('attaches respond method to res', () => {
responseMiddleware(req, res, next); responseMiddleware(req, res, next);
expect(res.respond).to.exist; expect(res.respond).to.exist;
}); });
it('can be used to respond to requests', function () { it('can be used to respond to requests', () => {
responseMiddleware(req, res, next); responseMiddleware(req, res, next);
res.respond(200, {field: 1}); res.respond(200, {field: 1});
@@ -34,7 +34,7 @@ describe('response middleware', function () {
}); });
}); });
it('treats status >= 400 as failures', function () { it('treats status >= 400 as failures', () => {
responseMiddleware(req, res, next); responseMiddleware(req, res, next);
res.respond(403, {field: 1}); res.respond(403, {field: 1});