diff --git a/test/api/v3/integration/chat/GET-chat.test.js b/test/api/v3/integration/chat/GET-chat.test.js index 26ed88f70b..edaca2ca2d 100644 --- a/test/api/v3/integration/chat/GET-chat.test.js +++ b/test/api/v3/integration/chat/GET-chat.test.js @@ -36,7 +36,7 @@ describe('GET /groups/:groupId/chat', () => { }); it('returns Guild chat', () => { - return user.get('/groups/' + group._id + '/chat') + return user.get(`/groups/${group._id}/chat`) .then((getChat) => { 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', () => { return expect( - user.get('/groups/' + group._id + '/chat') + user.get(`/groups/${group._id}/chat`) ) .to.eventually.be.rejected.and.eql({ code: 404, diff --git a/test/api/v3/integration/chat/POST-chat.flag.test.js b/test/api/v3/integration/chat/POST-chat.flag.test.js index c5178b7af8..3a0d494272 100644 --- a/test/api/v3/integration/chat/POST-chat.flag.test.js +++ b/test/api/v3/integration/chat/POST-chat.flag.test.js @@ -2,7 +2,7 @@ import { generateUser, translate as t, } from '../../../../helpers/api-integration.helper'; -import _ from 'lodash'; +import { find } from 'lodash'; describe('POST /chat/:chatId/flag', () => { let user; @@ -66,7 +66,7 @@ describe('POST /chat/:chatId/flag', () => { return user.get(`/groups/${group._id}`); }) .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); }); }); @@ -89,7 +89,7 @@ describe('POST /chat/:chatId/flag', () => { return user.get(`/groups/${group._id}`); }) .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.flagCount).to.equal(5); }); diff --git a/test/api/v3/integration/chat/POST-chat.like.test.js b/test/api/v3/integration/chat/POST-chat.like.test.js index 40f530174c..05d40f6e9f 100644 --- a/test/api/v3/integration/chat/POST-chat.like.test.js +++ b/test/api/v3/integration/chat/POST-chat.like.test.js @@ -2,7 +2,7 @@ import { generateUser, translate as t, } from '../../../../helpers/api-integration.helper'; -import _ from 'lodash'; +import { find } from 'lodash'; describe('POST /chat/:chatId/like', () => { let user; @@ -65,7 +65,7 @@ describe('POST /chat/:chatId/like', () => { return user.get(`/groups/${group._id}`); }) .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); }); }); @@ -89,7 +89,7 @@ describe('POST /chat/:chatId/like', () => { return user.get(`/groups/${group._id}`); }) .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); }); }); diff --git a/test/api/v3/integration/groups/POST-groups.test.js b/test/api/v3/integration/groups/POST-groups.test.js index f2ec45b06d..da532cc8d3 100644 --- a/test/api/v3/integration/groups/POST-groups.test.js +++ b/test/api/v3/integration/groups/POST-groups.test.js @@ -20,7 +20,7 @@ describe('POST /group', () => { return expect( user.post('/groups', { name: groupName, - type: groupType + type: groupType, }) ) .to.eventually.be.rejected.and.eql({ @@ -38,7 +38,7 @@ describe('POST /group', () => { return generateUser({balance: 1}).then((generatedUser) => { return generatedUser.post('/groups', { name: groupName, - type: groupType + type: groupType, }); }) .then((result) => { @@ -54,13 +54,12 @@ describe('POST /group', () => { let groupName = 'Test Private Guild'; let groupType = 'guild'; let groupPrivacy = 'private'; - let tmpUser; return generateUser({balance: 1}).then((generatedUser) => { return generatedUser.post('/groups', { name: groupName, type: groupType, - privacy: groupPrivacy + privacy: groupPrivacy, }); }) .then((result) => { @@ -80,7 +79,7 @@ describe('POST /group', () => { return user.post('/groups', { name: groupName, - type: groupType + type: groupType, }) .then((result) => { expect(result._id).to.exist; @@ -98,7 +97,7 @@ describe('POST /group', () => { tmpUser = generatedUser; return tmpUser.post('/groups', { name: groupName, - type: groupType + type: groupType, }); }) .then(() => { diff --git a/test/api/v3/integration/tags/PUT-tags_id.test.js b/test/api/v3/integration/tags/PUT-tags_id.test.js index e8a4335444..94a76ec39c 100644 --- a/test/api/v3/integration/tags/PUT-tags_id.test.js +++ b/test/api/v3/integration/tags/PUT-tags_id.test.js @@ -12,13 +12,11 @@ describe('PUT /tags/:tagId', () => { }); it('updates a tag given it\'s id', () => { - let length; - return user.post('/tags', {name: 'Tag 1'}) .then((createdTag) => { return user.put(`/tags/${createdTag._id}`, { name: 'Tag updated', - ignored: true + ignored: true, }); }) .then((updatedTag) => { diff --git a/test/api/v3/integration/tasks/DELETE-tasks_id.test.js b/test/api/v3/integration/tasks/DELETE-tasks_id.test.js index ad92739c9a..91f02b7844 100644 --- a/test/api/v3/integration/tasks/DELETE-tasks_id.test.js +++ b/test/api/v3/integration/tasks/DELETE-tasks_id.test.js @@ -25,9 +25,9 @@ describe('DELETE /tasks/:id', () => { }); it('deletes a user\'s task', () => { - return user.del('/tasks/' + task._id) + return user.del(`/tasks/${task._id}`) .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, error: 'NotFound', message: t('taskNotFound'), @@ -54,7 +54,7 @@ describe('DELETE /tasks/:id', () => { }); }) .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, error: 'NotFound', message: t('taskNotFound'), diff --git a/test/api/v3/integration/tasks/GET-tasks.test.js b/test/api/v3/integration/tasks/GET-tasks.test.js index 8a191f17bb..0772046f0b 100644 --- a/test/api/v3/integration/tasks/GET-tasks.test.js +++ b/test/api/v3/integration/tasks/GET-tasks.test.js @@ -1,6 +1,5 @@ import { generateUser, - translate as t, } from '../../../../helpers/api-integration.helper'; import Q from 'q'; diff --git a/test/api/v3/integration/tasks/GET-tasks_id.test.js b/test/api/v3/integration/tasks/GET-tasks_id.test.js index 993e2c127f..a4ae455d6a 100644 --- a/test/api/v3/integration/tasks/GET-tasks_id.test.js +++ b/test/api/v3/integration/tasks/GET-tasks_id.test.js @@ -26,7 +26,7 @@ describe('GET /tasks/:id', () => { }); it('gets specified task', () => { - return user.get('/tasks/' + task._id) + return user.get(`/tasks/${task._id}`) .then((getTask) => { expect(getTask).to.eql(task); }); @@ -38,7 +38,9 @@ describe('GET /tasks/:id', () => { context('task cannot be accessed', () => { 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, error: 'NotFound', message: t('taskNotFound'), @@ -57,7 +59,7 @@ describe('GET /tasks/:id', () => { type: 'habit', }); }).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, error: 'NotFound', message: t('taskNotFound'), diff --git a/test/api/v3/integration/tasks/POST-tasks_id_score_direction.test.js b/test/api/v3/integration/tasks/POST-tasks_id_score_direction.test.js index 2d7e10e745..2978d93657 100644 --- a/test/api/v3/integration/tasks/POST-tasks_id_score_direction.test.js +++ b/test/api/v3/integration/tasks/POST-tasks_id_score_direction.test.js @@ -47,29 +47,29 @@ describe('POST /tasks/:id/score/:direction', () => { it('completes todo when direction is 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)); }); it('moves completed todos out of user.tasksOrder.todos', () => { return user.get('/user') - .then(user => { - expect(user.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1); + .then(usr => { + expect(usr.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1); }).then(() => user.post(`/tasks/${todo._id}/score/up`)) .then(() => user.get(`/tasks/${todo._id}`)) .then((updatedTask) => { expect(updatedTask.completed).to.equal(true); return user.get('/user'); }) - .then((user) => { - expect(user.tasksOrder.todos.indexOf(todo._id)).to.equal(-1); + .then((usr) => { + expect(usr.tasksOrder.todos.indexOf(todo._id)).to.equal(-1); }); }); it('moves un-completed todos back into user.tasksOrder.todos', () => { return user.get('/user') - .then(user => { - expect(user.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1); + .then(usr => { + 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/down`)) .then(() => user.get(`/tasks/${todo._id}`)) @@ -77,16 +77,16 @@ describe('POST /tasks/:id/score/:direction', () => { expect(updatedTask.completed).to.equal(false); return user.get('/user'); }) - .then((user) => { - let l = user.tasksOrder.todos.length; - expect(user.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 + .then((usr) => { + let l = usr.tasksOrder.todos.length; + expect(usr.tasksOrder.todos.indexOf(todo._id)).not.to.equal(-1); + 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', () => { return user.post(`/tasks/${todo._id}/score/down`) - .then((res) => user.get(`/tasks/${todo._id}`)) + .then(() => user.get(`/tasks/${todo._id}`)) .then((updatedTask) => { 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', () => { return user.post(`/tasks/${todo._id}/score/up`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${todo._id}/score/down`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${todo._id}/score/up`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${todo._id}/score/down`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${todo._id}/score/up`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${todo._id}/score/down`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { 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)); }); it('uncompletes daily when direction is 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)); }); @@ -175,7 +175,7 @@ describe('POST /tasks/:id/score/:direction', () => { it('increases user\'s mp when direction is up', () => { return user.post(`/tasks/${daily._id}/score/up`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${daily._id}/score/down`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${daily._id}/score/up`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${daily._id}/score/down`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${daily._id}/score/up`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${daily._id}/score/down`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { expect(updatedUser.stats.gp).to.be.lessThan(user.stats.gp); }); @@ -223,7 +223,7 @@ describe('POST /tasks/:id/score/:direction', () => { }); context('habits', () => { - let habit, minusHabit, plusHabit, neitherHabit; + let habit, minusHabit, plusHabit, neitherHabit; // eslint-disable-line no-unused-vars beforeEach(() => { return user.post('/tasks', { @@ -262,7 +262,7 @@ describe('POST /tasks/:id/score/:direction', () => { it('increases user\'s mp when direction is up', () => { return user.post(`/tasks/${habit._id}/score/up`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${habit._id}/score/down`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${habit._id}/score/up`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${habit._id}/score/up`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp); }); @@ -308,7 +308,7 @@ describe('POST /tasks/:id/score/:direction', () => { it('purchases reward', () => { return user.post(`/tasks/${reward._id}/score/up`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${reward._id}/score/up`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${reward._id}/score/up`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { 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', () => { return user.post(`/tasks/${reward._id}/score/up`) - .then((res) => user.get(`/user`)) + .then(() => user.get(`/user`)) .then((updatedUser) => { expect(user.stats.mp).to.equal(updatedUser.stats.mp); }); diff --git a/test/api/v3/integration/tasks/PUT-tasks_id.test.js b/test/api/v3/integration/tasks/PUT-tasks_id.test.js index 99fdb83615..3092d3bd84 100644 --- a/test/api/v3/integration/tasks/PUT-tasks_id.test.js +++ b/test/api/v3/integration/tasks/PUT-tasks_id.test.js @@ -1,6 +1,5 @@ import { generateUser, - translate as t, } from '../../../../helpers/api-integration.helper'; import { v4 as generateUUID } from 'uuid'; @@ -28,7 +27,7 @@ describe('PUT /tasks/:id', () => { it(`ignores setting _id, type, userId, history, createdAt, updatedAt, challenge, completed, streak, dateCompleted fields`, () => { - user.put('/tasks/' + task._id, { + user.put(`/tasks/${task._id}`, { _id: 123, type: 'daily', userId: 123, @@ -54,7 +53,7 @@ describe('PUT /tasks/:id', () => { }); it('ignores invalid fields', () => { - user.put('/tasks/' + task._id, { + user.put(`/tasks/${task._id}`, { notValid: true, }).then((savedTask) => { expect(savedTask.notValid).to.be.a('undefined'); @@ -118,12 +117,12 @@ describe('PUT /tasks/:id', () => { checklist: [ {text: 123, completed: false}, {text: 456, completed: true}, - ] - }).then((savedTodo) => { + ], + }).then(() => { return user.put(`/tasks/${todo._id}`, { checklist: [ {text: 789, completed: false}, - ] + ], }); }).then((savedTodo2) => { expect(savedTodo2.checklist.length).to.equal(1); @@ -136,9 +135,9 @@ describe('PUT /tasks/:id', () => { let finalUUID = generateUUID(); return user.put(`/tasks/${todo._id}`, { tags: [generateUUID(), generateUUID()], - }).then((savedTodo) => { + }).then(() => { return user.put(`/tasks/${todo._id}`, { - tags: [finalUUID] + tags: [finalUUID], }); }).then((savedTodo2) => { expect(savedTodo2.tags.length).to.equal(1); @@ -161,8 +160,6 @@ describe('PUT /tasks/:id', () => { }); it('updates a daily', () => { - let now = new Date(); - return user.put(`/tasks/${daily._id}`, { text: 'some new text', notes: 'some new notes', @@ -181,12 +178,12 @@ describe('PUT /tasks/:id', () => { checklist: [ {text: 123, completed: false}, {text: 456, completed: true}, - ] - }).then((savedDaily) => { + ], + }).then(() => { return user.put(`/tasks/${daily._id}`, { checklist: [ {text: 789, completed: false}, - ] + ], }); }).then((savedDaily2) => { expect(savedDaily2.checklist.length).to.equal(1); @@ -199,9 +196,9 @@ describe('PUT /tasks/:id', () => { let finalUUID = generateUUID(); return user.put(`/tasks/${daily._id}`, { tags: [generateUUID(), generateUUID()], - }).then((savedDaily) => { + }).then(() => { return user.put(`/tasks/${daily._id}`, { - tags: [finalUUID] + tags: [finalUUID], }); }).then((savedDaily2) => { 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', () => { return user.put(`/tasks/${daily._id}`, { frequency: 'daily', - }).then((savedDaily) => { + }).then(() => { return user.put(`/tasks/${daily._id}`, { repeat: { m: false, - su: false - } + su: false, + }, }); }).then((savedDaily2) => { expect(savedDaily2.repeat).to.eql({ @@ -235,7 +232,7 @@ describe('PUT /tasks/:id', () => { it('updates everyX, even if frequency is set to weekly', () => { return user.put(`/tasks/${daily._id}`, { frequency: 'weekly', - }).then((savedDaily) => { + }).then(() => { return user.put(`/tasks/${daily._id}`, { everyX: 5, }); diff --git a/test/api/v3/integration/tasks/checklists/DELETE-tasks_taskId_checklist_itemId.test.js b/test/api/v3/integration/tasks/checklists/DELETE-tasks_taskId_checklist_itemId.test.js index 094619e1fd..d013878a74 100644 --- a/test/api/v3/integration/tasks/checklists/DELETE-tasks_taskId_checklist_itemId.test.js +++ b/test/api/v3/integration/tasks/checklists/DELETE-tasks_taskId_checklist_itemId.test.js @@ -46,15 +46,13 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => { }); }); - it('does not work with rewards', () => { - let reward; - return expect(user.post('/tasks', { + it('does not work with rewards', async () => { + let reward = await user.post('/tasks', { type: 'reward', text: 'reward with checklist', - }).then(createdTask => { - reward = createdTask; - return user.del(`/tasks/${reward._id}/checklist/${generateUUID()}`); - }).then(checklistItem => {})).to.eventually.be.rejected.and.eql({ + }); + + await expect(user.del(`/tasks/${reward._id}/checklist/${generateUUID()}`)).to.eventually.be.rejected.and.eql({ code: 400, error: 'BadRequest', message: t('checklistOnlyDailyTodo'), diff --git a/test/api/v3/integration/tasks/checklists/POST-tasks_taskId_checklist.test.js b/test/api/v3/integration/tasks/checklists/POST-tasks_taskId_checklist.test.js index 4654871ac5..e9b695effd 100644 --- a/test/api/v3/integration/tasks/checklists/POST-tasks_taskId_checklist.test.js +++ b/test/api/v3/integration/tasks/checklists/POST-tasks_taskId_checklist.test.js @@ -66,7 +66,7 @@ describe('POST /tasks/:taskId/checklist/', () => { it('fails on task not found', () => { return expect(user.post(`/tasks/${generateUUID()}/checklist`, { - text: 'Checklist Item 1' + text: 'Checklist Item 1', })).to.eventually.be.rejected.and.eql({ code: 404, error: 'NotFound', diff --git a/test/api/v3/integration/tasks/checklists/POST-tasks_taskId_checklist_itemId_score.test.js b/test/api/v3/integration/tasks/checklists/POST-tasks_taskId_checklist_itemId_score.test.js index 727aaea74c..667ef41446 100644 --- a/test/api/v3/integration/tasks/checklists/POST-tasks_taskId_checklist_itemId_score.test.js +++ b/test/api/v3/integration/tasks/checklists/POST-tasks_taskId_checklist_itemId_score.test.js @@ -45,15 +45,13 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => { }); }); - it('fails on rewards', () => { - let reward; - return expect(user.post('/tasks', { + it('fails on rewards', async () => { + let reward = await user.post('/tasks', { type: 'reward', text: 'reward with checklist', - }).then(createdTask => { - reward = createdTask; - return user.post(`/tasks/${reward._id}/checklist/${generateUUID()}/score`); - }).then(checklistItem => {})).to.eventually.be.rejected.and.eql({ + }); + + await expect(user.post(`/tasks/${reward._id}/checklist/${generateUUID()}/score`)).to.eventually.be.rejected.and.eql({ code: 400, error: 'BadRequest', message: t('checklistOnlyDailyTodo'), diff --git a/test/api/v3/integration/tasks/checklists/PUT-tasks_taskId_checklist_itemId.test.js b/test/api/v3/integration/tasks/checklists/PUT-tasks_taskId_checklist_itemId.test.js index 149d1bedca..988574bbf8 100644 --- a/test/api/v3/integration/tasks/checklists/PUT-tasks_taskId_checklist_itemId.test.js +++ b/test/api/v3/integration/tasks/checklists/PUT-tasks_taskId_checklist_itemId.test.js @@ -32,30 +32,26 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => { }); }); - it('fails on habits', () => { - let habit; - return expect(user.post('/tasks', { + it('fails on habits', async () => { + let habit = await user.post('/tasks', { type: 'habit', text: 'habit with checklist', - }).then(createdTask => { - habit = createdTask; - return user.put(`/tasks/${habit._id}/checklist/${generateUUID()}`); - })).to.eventually.be.rejected.and.eql({ + }); + + await expect(user.put(`/tasks/${habit._id}/checklist/${generateUUID()}`)).to.eventually.be.rejected.and.eql({ code: 400, error: 'BadRequest', message: t('checklistOnlyDailyTodo'), }); }); - it('fails on rewards', () => { - let reward; - return expect(user.post('/tasks', { + it('fails on rewards', async () => { + let reward = await user.post('/tasks', { type: 'reward', text: 'reward with checklist', - }).then(createdTask => { - reward = createdTask; - return user.put(`/tasks/${reward._id}/checklist/${generateUUID()}`); - }).then(checklistItem => {})).to.eventually.be.rejected.and.eql({ + }); + + await expect(user.put(`/tasks/${reward._id}/checklist/${generateUUID()}`)).to.eventually.be.rejected.and.eql({ code: 400, error: 'BadRequest', message: t('checklistOnlyDailyTodo'), diff --git a/test/api/v3/integration/tasks/tags/DELETE-tasks_taskId_tags_tagId.test.js b/test/api/v3/integration/tasks/tags/DELETE-tasks_taskId_tags_tagId.test.js index ddb78b7262..c01b71fa2c 100644 --- a/test/api/v3/integration/tasks/tags/DELETE-tasks_taskId_tags_tagId.test.js +++ b/test/api/v3/integration/tasks/tags/DELETE-tasks_taskId_tags_tagId.test.js @@ -26,7 +26,7 @@ describe('DELETE /tasks/:taskId/tags/:tagId', () => { }).then(createdTag => { tag = createdTag; return user.post(`/tasks/${task._id}/tags/${tag._id}`); - }).then(savedTask => { + }).then(() => { return user.del(`/tasks/${task._id}/tags/${tag._id}`); }).then(() => user.get(`/tasks/${task._id}`)) .then(updatedTask => { @@ -35,8 +35,6 @@ describe('DELETE /tasks/:taskId/tags/:tagId', () => { }); it('only deletes existing tags', () => { - let task; - return expect(user.post('/tasks', { type: 'habit', text: 'Task with tag', diff --git a/test/api/v3/integration/user/auth/POST-register_local.test.js b/test/api/v3/integration/user/auth/POST-register_local.test.js index 0e11e7b924..a0f83717ea 100644 --- a/test/api/v3/integration/user/auth/POST-register_local.test.js +++ b/test/api/v3/integration/user/auth/POST-register_local.test.js @@ -37,7 +37,7 @@ describe('POST /user/auth/local/register', () => { username, email, password, - confirmPassword: confirmPassword, + confirmPassword, })).to.eventually.be.rejected.and.eql({ code: 400, error: 'BadRequest', @@ -104,8 +104,8 @@ describe('POST /user/auth/local/register', () => { return expect(api.post('/user/auth/local/register', { username, - email: email, - confirmPassword: confirmPassword, + email, + confirmPassword, })).to.eventually.be.rejected.and.eql({ code: 400, error: 'BadRequest', @@ -123,7 +123,7 @@ describe('POST /user/auth/local/register', () => { return generateUser({ 'auth.local.username': 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'; return expect(api.post('/user/auth/local/register', { - username: username, - email: uniqueEmail, - password: password, + username, + email: uniqueEmail, + password, confirmPassword: password, })).to.eventually.be.rejected.and.eql({ code: 401, @@ -181,7 +181,7 @@ describe('POST /user/auth/local/register', () => { }).then((user) => { expect(user.flags.tour).to.not.be.empty; - each(user.flags.tour, (value, attribute) => { + each(user.flags.tour, (value) => { expect(value).to.eql(-2); }); }); @@ -232,7 +232,7 @@ describe('POST /user/auth/local/register', () => { }).then((user) => { 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); }); }); diff --git a/test/api/v3/unit/libs/analyticsService.test.js b/test/api/v3/unit/libs/analyticsService.test.js index c8536bc887..8ff14c2408 100644 --- a/test/api/v3/unit/libs/analyticsService.test.js +++ b/test/api/v3/unit/libs/analyticsService.test.js @@ -6,12 +6,12 @@ describe('analyticsService', () => { let amplitudeNock, gaNock; beforeEach(() => { - amplitudeNock = nock( 'https://api.amplitude.com') + amplitudeNock = nock('https://api.amplitude.com') .filteringPath(/httpapi.*/g, '') .post('/') .reply(200, {status: 'OK'}); - gaNock = nock( 'http://www.google-analytics.com'); + gaNock = nock('http://www.google-analytics.com'); }); describe('#track', () => { @@ -23,14 +23,14 @@ describe('analyticsService', () => { category: 'behavior', uuid: 'unique-user-id', resting: true, - cronCount: 5 + cronCount: 5, }; }); context('Amplitude', () => { it('calls out to amplitude', () => { return analyticsService.track(eventType, data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -42,7 +42,7 @@ describe('analyticsService', () => { .filteringPath(/httpapi.*user_id.*no-user-id-was-provided.*/g, ''); return analyticsService.track(eventType, data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -52,7 +52,7 @@ describe('analyticsService', () => { .filteringPath(/httpapi.*platform.*server.*/g, ''); return analyticsService.track(eventType, data) - .then((res) => { + .then(() => { 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, ''); return analyticsService.track(eventType, data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -74,7 +74,7 @@ describe('analyticsService', () => { .filteringPath(/httpapi.*itemName.*Fox%20Ears.*/g, ''); return analyticsService.track(eventType, data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -86,7 +86,7 @@ describe('analyticsService', () => { .filteringPath(/httpapi.*itemName.*Wolf%20Egg.*/g, ''); return analyticsService.track(eventType, data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -98,7 +98,7 @@ describe('analyticsService', () => { .filteringPath(/httpapi.*itemName.*Bare%20Bones%20Cake.*/g, ''); return analyticsService.track(eventType, data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -110,7 +110,7 @@ describe('analyticsService', () => { .filteringPath(/httpapi.*itemName.*Golden%20Hatching%20Potion.*/g, ''); return analyticsService.track(eventType, data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -122,7 +122,7 @@ describe('analyticsService', () => { .filteringPath(/httpapi.*itemName.*Attack%20of%20the%20Mundane%2C%20Part%201%3A%20Dish%20Disaster!.*/g, ''); return analyticsService.track(eventType, data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -134,7 +134,7 @@ describe('analyticsService', () => { .filteringPath(/httpapi.*itemName.*Seafoam.*/g, ''); return analyticsService.track(eventType, data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -142,14 +142,14 @@ describe('analyticsService', () => { it('sends user data if provided', () => { let stats = { class: 'wizard', exp: 5, gp: 23, hp: 10, lvl: 4, mp: 30 }; let user = { - stats: stats, + stats, contributor: { level: 1 }, purchased: { plan: { planId: 'foo-plan' } }, flags: {tour: {intro: -2}}, habits: [{_id: 'habit'}], dailys: [{_id: 'daily'}], todos: [{_id: 'todo'}], - rewards: [{_id: 'reward'}] + rewards: [{_id: 'reward'}], }; 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, ''); return analyticsService.track(eventType, data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -171,7 +171,7 @@ describe('analyticsService', () => { .reply(200, {status: 'OK'}); return analyticsService.track(eventType, data) - .then((res) => { + .then(() => { gaNock.done(); }); }); @@ -182,7 +182,7 @@ describe('analyticsService', () => { .reply(200, {status: 'OK'}); return analyticsService.track(eventType, data) - .then((res) => { + .then(() => { gaNock.done(); }); }); @@ -201,14 +201,14 @@ describe('analyticsService', () => { purchaseValue: 8, purchaseType: 'checkout', gift: false, - quantity: 1 + quantity: 1, }; }); context('Amplitude', () => { it('calls out to amplitude', () => { return analyticsService.trackPurchase(data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -220,7 +220,7 @@ describe('analyticsService', () => { .filteringPath(/httpapi.*user_id.*no-user-id-was-provided.*/g, ''); return analyticsService.trackPurchase(data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -230,7 +230,7 @@ describe('analyticsService', () => { .filteringPath(/httpapi.*platform.*server.*/g, ''); return analyticsService.trackPurchase(data) - .then((res) => { + .then(() => { 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, ''); return analyticsService.trackPurchase(data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -248,14 +248,14 @@ describe('analyticsService', () => { it('sends user data if provided', () => { let stats = { class: 'wizard', exp: 5, gp: 23, hp: 10, lvl: 4, mp: 30 }; let user = { - stats: stats, + stats, contributor: { level: 1 }, purchased: { plan: { planId: 'foo-plan' } }, flags: {tour: {intro: -2}}, habits: [{_id: 'habit'}], dailys: [{_id: 'daily'}], todos: [{_id: 'todo'}], - rewards: [{_id: 'reward'}] + rewards: [{_id: 'reward'}], }; 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, ''); return analyticsService.trackPurchase(data) - .then((res) => { + .then(() => { amplitudeNock.done(); }); }); @@ -277,7 +277,7 @@ describe('analyticsService', () => { .reply(200, {status: 'OK'}); return analyticsService.trackPurchase(data) - .then((res) => { + .then(() => { gaNock.done(); }); }); @@ -290,7 +290,7 @@ describe('analyticsService', () => { .reply(200, {status: 'OK'}); return analyticsService.trackPurchase(data) - .then((res) => { + .then(() => { gaNock.done(); }); }); diff --git a/test/api/v3/unit/libs/baseModel.test.js b/test/api/v3/unit/libs/baseModel.test.js index 98835b1c29..95960c704d 100644 --- a/test/api/v3/unit/libs/baseModel.test.js +++ b/test/api/v3/unit/libs/baseModel.test.js @@ -32,7 +32,7 @@ describe('Base model plugin', () => { it('can sanitize input objects', () => { baseModel(schema, { - noSet: ['noUpdateForMe'] + noSet: ['noUpdateForMe'], }); 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', () => { baseModel(schema, { - noSet: ['noUpdateForMe'] + noSet: ['noUpdateForMe'], }); expect(schema.statics.sanitize).to.exist; @@ -59,7 +59,7 @@ describe('Base model plugin', () => { it('can make fields private', () => { baseModel(schema, { - private: ['amPrivate'] + private: ['amPrivate'], }); expect(schema.options.toJSON.transform).to.exist; @@ -73,7 +73,7 @@ describe('Base model plugin', () => { it('accepts a further transform function for toJSON', () => { let options = { private: ['amPrivate'], - toJSONTransform: sandbox.stub().returns(true) + toJSONTransform: sandbox.stub().returns(true), }; baseModel(schema, options); @@ -88,7 +88,7 @@ describe('Base model plugin', () => { it('accepts a transform function for sanitize', () => { let options = { private: ['amPrivate'], - sanitizeTransform: sandbox.stub().returns(true) + sanitizeTransform: sandbox.stub().returns(true), }; baseModel(schema, options); diff --git a/test/api/v3/unit/libs/buildManifest.test.js b/test/api/v3/unit/libs/buildManifest.test.js index e719d8c434..0978d8fb41 100644 --- a/test/api/v3/unit/libs/buildManifest.test.js +++ b/test/api/v3/unit/libs/buildManifest.test.js @@ -11,8 +11,9 @@ describe('Build Manifest', () => { }); it('throws an error in case the page does not exist', () => { - let getManifestFilesFn = () => { getManifestFiles('strange name here'); }; - expect(getManifestFilesFn).to.throw(Error); + expect(() => { + getManifestFiles('strange name here'); + }).to.throw(Error); }); }); }); diff --git a/test/api/v3/unit/libs/email.test.js b/test/api/v3/unit/libs/email.test.js index 5cfd1b542f..bb7741dce7 100644 --- a/test/api/v3/unit/libs/email.test.js +++ b/test/api/v3/unit/libs/email.test.js @@ -1,3 +1,4 @@ +/* eslint-disable global-require */ import request from 'request'; import nconf from 'nconf'; import nodemailer from 'nodemailer'; @@ -14,17 +15,17 @@ function getUser () { }, facebook: { emails: [{ - value: 'email@facebook' + value: 'email@facebook', }], displayName: 'fb display name', - } + }, }, profile: { name: 'profile name', }, preferences: { emailNotifications: { - unsubscribeFromAll: false + unsubscribeFromAll: false, }, }, }; @@ -63,7 +64,7 @@ describe('emails', () => { attachEmail.send(); expect(sendMailSpy).to.be.calledOnce; deferred.reject(); - deferred.promise.catch((err) => { + deferred.promise.catch(() => { expect(logger.error).to.be.calledOnce; done(); }); @@ -93,8 +94,8 @@ describe('emails', () => { let attachEmail = require(pathToEmailLib); let getUserInfo = attachEmail.getUserInfo; let user = getUser(); - delete user.profile['name']; - delete user.auth['local']; + delete user.profile.name; + delete user.auth.local; let data = getUserInfo(user, ['name', 'email', '_id', 'canSend']); @@ -108,9 +109,9 @@ describe('emails', () => { let attachEmail = require(pathToEmailLib); let getUserInfo = attachEmail.getUserInfo; let user = getUser(); - delete user.profile['name']; - delete user.auth.local['email']; - delete user.auth['facebook']; + delete user.profile.name; + delete user.auth.local.email; + delete user.auth.facebook; let data = getUserInfo(user, ['name', 'email', '_id', 'canSend']); @@ -148,8 +149,8 @@ describe('emails', () => { to: sinon.match((value) => { return Array.isArray(value) && value[0].name === mailingInfo.name; }, 'matches mailing info array'), - } - } + }, + }, })); }); @@ -160,7 +161,7 @@ describe('emails', () => { let emailType = 'an email type'; let mailingInfo = { name: 'my name', - //email: 'my@email', + // email: 'my@email', }; sendTxnEmail(mailingInfo, emailType); @@ -180,8 +181,8 @@ describe('emails', () => { data: { emailType: sinon.match.same(emailType), to: sinon.match(val => val[0]._id === mailingInfo._id), - } - } + }, + }, })); }); @@ -204,13 +205,12 @@ describe('emails', () => { return value[0].name === 'BASE_URL'; }, 'matches variables'), personalVariables: sinon.match((value) => { - return (value[0].rcpt === mailingInfo.email - && value[0].vars[0].name === 'RECIPIENT_NAME' - && value[0].vars[1].name === 'RECIPIENT_UNSUB_URL' - ); + return value[0].rcpt === mailingInfo.email && + value[0].vars[0].name === 'RECIPIENT_NAME' && + value[0].vars[1].name === 'RECIPIENT_UNSUB_URL'; }, 'matches personal variables'), - } - } + }, + }, })); }); }); diff --git a/test/api/v3/unit/libs/webhooks.test.js b/test/api/v3/unit/libs/webhooks.test.js index 62aeee3922..9bef501257 100644 --- a/test/api/v3/unit/libs/webhooks.test.js +++ b/test/api/v3/unit/libs/webhooks.test.js @@ -2,7 +2,6 @@ import request from 'request'; import { sendTaskWebhook } from '../../../../../website/src/libs/api-v3/webhook'; describe('webhooks', () => { - beforeEach(() => { sandbox.stub(request, 'post'); }); @@ -15,12 +14,12 @@ describe('webhooks', () => { let task = { details: { _id: 'task-id' }, delta: 1.4, - direction: 'up' + direction: 'up', }; let data = { - task: task, - user: { _id: 'user-id' } + task, + user: { _id: 'user-id' }, }; it('does not send if no webhook endpoints exist', () => { @@ -37,8 +36,8 @@ describe('webhooks', () => { sort: 0, id: 'some-id', enabled: false, - url: 'http://example.org/endpoint' - } + url: 'http://example.org/endpoint', + }, }; sendTaskWebhook(webhooks, data); @@ -52,8 +51,8 @@ describe('webhooks', () => { sort: 0, id: 'some-id', enabled: true, - url: 'http://malformedurl/endpoint' - } + url: 'http://malformedurl/endpoint', + }, }; sendTaskWebhook(webhooks, data); @@ -67,8 +66,8 @@ describe('webhooks', () => { sort: 0, id: 'some-id', enabled: true, - url: 'http://example.org/endpoint' - } + url: 'http://example.org/endpoint', + }, }; sendTaskWebhook(webhooks, data); @@ -81,10 +80,10 @@ describe('webhooks', () => { task: { _id: 'task-id' }, delta: 1.4, user: { - _id: 'user-id' - } + _id: 'user-id', + }, }, - json: true + json: true, }); }); @@ -94,14 +93,14 @@ describe('webhooks', () => { sort: 0, id: 'some-id', enabled: true, - url: 'http://example.org/endpoint' + url: 'http://example.org/endpoint', }, 'second-webhook': { sort: 1, id: 'second-webhook', enabled: true, - url: 'http://example.com/2/endpoint' - } + url: 'http://example.com/2/endpoint', + }, }; sendTaskWebhook(webhooks, data); @@ -114,10 +113,10 @@ describe('webhooks', () => { task: { _id: 'task-id' }, delta: 1.4, user: { - _id: 'user-id' - } + _id: 'user-id', + }, }, - json: true + json: true, }); expect(request.post).to.be.calledWith({ url: 'http://example.com/2/endpoint', @@ -126,10 +125,10 @@ describe('webhooks', () => { task: { _id: 'task-id' }, delta: 1.4, user: { - _id: 'user-id' - } + _id: 'user-id', + }, }, - json: true + json: true, }); }); }); diff --git a/test/api/v3/unit/middlewares/analytics.test.js b/test/api/v3/unit/middlewares/analytics.test.js index cc09c8f39a..bcaa7898e2 100644 --- a/test/api/v3/unit/middlewares/analytics.test.js +++ b/test/api/v3/unit/middlewares/analytics.test.js @@ -1,3 +1,4 @@ +/* eslint-disable global-require */ import { generateRes, generateReq, @@ -6,7 +7,7 @@ import { import analyticsService from '../../../../../website/src/libs/api-v3/analyticsService'; import nconf from 'nconf'; -describe('analytics middleware', function () { +describe('analytics middleware', () => { let res, req, next; let pathToAnalyticsMiddleware = '../../../../../website/src/middlewares/api-v3/analytics'; @@ -23,7 +24,7 @@ describe('analytics middleware', function () { delete require.cache[require.resolve(pathToAnalyticsMiddleware)]; }); - it('attaches analytics object res.locals', function () { + it('attaches analytics object res.locals', () => { let attachAnalytics = require(pathToAnalyticsMiddleware); attachAnalytics(req, res, next); diff --git a/test/api/v3/unit/middlewares/errorHandler.test.js b/test/api/v3/unit/middlewares/errorHandler.test.js index 80e1ab08d1..269390b35b 100644 --- a/test/api/v3/unit/middlewares/errorHandler.test.js +++ b/test/api/v3/unit/middlewares/errorHandler.test.js @@ -115,7 +115,7 @@ describe('errorHandler', () => { error: 'BadRequest', message: 'Invalid request parameters.', 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', message: 'User validation failed.', errors: [ - {path: 'auth.local.email', message: 'Invalid email.', value: 'not an email'} - ] + { path: 'auth.local.email', message: 'Invalid email.', value: 'not an email' }, + ], }); }); diff --git a/test/api/v3/unit/middlewares/getUserLanguage.test.js b/test/api/v3/unit/middlewares/getUserLanguage.test.js index 94693e6713..43b0cb0ab8 100644 --- a/test/api/v3/unit/middlewares/getUserLanguage.test.js +++ b/test/api/v3/unit/middlewares/getUserLanguage.test.js @@ -7,15 +7,13 @@ import getUserLanguage from '../../../../../website/src/middlewares/api-v3/getUs import { i18n } from '../../../../../common'; import Q from 'q'; import { model as User } from '../../../../../website/src/models/user'; -import { translations } from '../../../../../website/src/libs/api-v3/i18n'; -import accepts from 'accepts'; describe('getUserLanguage', () => { let res, req, next; - let checkResT = (req) => { - expect(res.t).to.be.a('function'); - expect(res.t('help')).to.equal(i18n.t('help', req.language)); + let checkResT = (resToCheck) => { + expect(resToCheck.t).to.be.a('function'); + expect(resToCheck.t('help')).to.equal(i18n.t('help', req.language)); }; beforeEach(() => { @@ -32,7 +30,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, next); expect(req.language).to.equal('es'); - checkResT(req); + checkResT(res); }); it('falls back to english if the query parameter language does not exists', () => { @@ -42,7 +40,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, next); expect(req.language).to.equal('en'); - checkResT(req); + checkResT(res); }); it('uses query even if the request includes a user and session', () => { @@ -59,12 +57,12 @@ describe('getUserLanguage', () => { }; req.session = { - userId: 123 + userId: 123, }; getUserLanguage(req, res, next); expect(req.language).to.equal('es'); - checkResT(req); + checkResT(res); }); }); @@ -80,7 +78,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, next); expect(req.language).to.equal('it'); - checkResT(req); + checkResT(res); }); it('falls back to english if the user preferred language is not avalaible', (done) => { @@ -94,7 +92,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, () => { expect(req.language).to.equal('en'); - checkResT(req); + checkResT(res); done(); }); }); @@ -109,12 +107,12 @@ describe('getUserLanguage', () => { }; req.session = { - userId: 123 + userId: 123, }; getUserLanguage(req, res, next); expect(req.language).to.equal('it'); - checkResT(req); + checkResT(res); }); }); @@ -125,18 +123,18 @@ describe('getUserLanguage', () => { return Q.resolve({ preferences: { language: 'it', - } + }, }); - } + }, }); req.session = { - userId: 123 + userId: 123, }; getUserLanguage(req, res, () => { expect(req.language).to.equal('it'); - checkResT(req); + checkResT(res); done(); }); }); @@ -148,7 +146,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, () => { expect(req.language).to.equal('pt'); - checkResT(req); + checkResT(res); done(); }); }); @@ -158,7 +156,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, () => { expect(req.language).to.equal('he'); - checkResT(req); + checkResT(res); done(); }); }); @@ -168,7 +166,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, () => { expect(req.language).to.equal('he'); - checkResT(req); + checkResT(res); done(); }); }); @@ -178,7 +176,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, () => { expect(req.language).to.equal('fr'); - checkResT(req); + checkResT(res); done(); }); }); @@ -188,7 +186,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, () => { expect(req.language).to.equal('fr'); - checkResT(req); + checkResT(res); done(); }); }); @@ -198,7 +196,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, () => { expect(req.language).to.equal('es'); - checkResT(req); + checkResT(res); done(); }); }); @@ -208,7 +206,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, () => { expect(req.language).to.equal('es_419'); - checkResT(req); + checkResT(res); done(); }); }); @@ -218,7 +216,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, () => { expect(req.language).to.equal('es_419'); - checkResT(req); + checkResT(res); done(); }); }); @@ -228,7 +226,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, () => { expect(req.language).to.equal('zh_TW'); - checkResT(req); + checkResT(res); done(); }); }); @@ -238,7 +236,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, () => { expect(req.language).to.equal('en'); - checkResT(req); + checkResT(res); done(); }); }); @@ -248,7 +246,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, () => { expect(req.language).to.equal('en'); - checkResT(req); + checkResT(res); done(); }); }); @@ -258,7 +256,7 @@ describe('getUserLanguage', () => { getUserLanguage(req, res, () => { expect(req.language).to.equal('en'); - checkResT(req); + checkResT(res); done(); }); }); diff --git a/test/api/v3/unit/middlewares/response.js b/test/api/v3/unit/middlewares/response.js index 15bb9881a5..25916e1ef3 100644 --- a/test/api/v3/unit/middlewares/response.js +++ b/test/api/v3/unit/middlewares/response.js @@ -5,7 +5,7 @@ import { } from '../../../../helpers/api-unit.helper'; import responseMiddleware from '../../../../../website/src/middlewares/api-v3/response'; -describe('response middleware', function () { +describe('response middleware', () => { let res, req, next; 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); 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); 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); res.respond(403, {field: 1});