mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 23:27:26 +01:00
lint: Correct linting errors in v3 tests
This commit is contained in:
@@ -17,7 +17,7 @@ describe('GET /tags/:tagId', () => {
|
||||
return user.post('/tags', {name: 'Tag 1'})
|
||||
.then((tag) => {
|
||||
createdTag = tag;
|
||||
return user.get(`/tags/${createdTag._id}`)
|
||||
return user.get(`/tags/${createdTag._id}`);
|
||||
})
|
||||
.then((tag) => {
|
||||
expect(tag).to.deep.equal(createdTag);
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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'),
|
||||
@@ -63,5 +63,6 @@ describe('DELETE /tasks/:id', () => {
|
||||
});
|
||||
|
||||
it('cannot delete active challenge tasks'); // TODO after challenges are implemented
|
||||
it('remove a task from user.tasksOrder'); // TODO
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import {
|
||||
generateUser,
|
||||
translate as t,
|
||||
} from '../../../../helpers/api-integration.helper';
|
||||
import Q from 'q';
|
||||
|
||||
@@ -41,5 +40,5 @@ describe('GET /tasks', () => {
|
||||
});
|
||||
|
||||
// TODO complete after task scoring is done
|
||||
it('returns completed todos sorted by creation date if req.query.includeCompletedTodos is specified')
|
||||
it('returns completed todos sorted by creation date if req.query.includeCompletedTodos is specified');
|
||||
});
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -6,14 +6,14 @@ import {
|
||||
describe('POST /tasks', () => {
|
||||
let user;
|
||||
|
||||
before(() => {
|
||||
before(async () => {
|
||||
return generateUser().then((generatedUser) => {
|
||||
user = generatedUser;
|
||||
});
|
||||
});
|
||||
|
||||
context('validates params', () => {
|
||||
it('returns an error if req.body.type is absent', () => {
|
||||
it('returns an error if req.body.type is absent', async () => {
|
||||
return expect(user.post('/tasks', {
|
||||
notType: 'habit',
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
@@ -23,7 +23,7 @@ describe('POST /tasks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error if req.body.type is not valid', () => {
|
||||
it('returns an error if req.body.type is not valid', async () => {
|
||||
return expect(user.post('/tasks', {
|
||||
type: 'habitF',
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
@@ -33,7 +33,7 @@ describe('POST /tasks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error if req.body.text is absent', () => {
|
||||
it('returns an error if req.body.text is absent', async () => {
|
||||
return expect(user.post('/tasks', {
|
||||
type: 'habit',
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
@@ -43,19 +43,19 @@ describe('POST /tasks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('automatically sets "task.userId" to user\'s uuid', () => {
|
||||
return user.post('/tasks', {
|
||||
it('automatically sets "task.userId" to user\'s uuid', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test habit',
|
||||
type: 'habit',
|
||||
}).then((task) => {
|
||||
expect(task.userId).to.equal(user._id);
|
||||
});
|
||||
|
||||
expect(task.userId).to.equal(user._id);
|
||||
});
|
||||
|
||||
it(`ignores setting userId, history, createdAt,
|
||||
updatedAt, challenge, completed, streak,
|
||||
dateCompleted fields`, () => {
|
||||
return user.post('/tasks', {
|
||||
dateCompleted fields`, async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
userId: 123,
|
||||
@@ -66,7 +66,8 @@ describe('POST /tasks', () => {
|
||||
completed: true,
|
||||
streak: 25,
|
||||
dateCompleted: 'never',
|
||||
}).then((task) => {
|
||||
});
|
||||
|
||||
expect(task.userId).to.equal(user._id);
|
||||
expect(task.history).to.eql([]);
|
||||
expect(task.createdAt).not.to.equal('yesterday');
|
||||
@@ -76,28 +77,28 @@ describe('POST /tasks', () => {
|
||||
expect(task.streak).to.equal(0);
|
||||
expect(task.streak).not.to.equal('never');
|
||||
});
|
||||
});
|
||||
|
||||
it('ignores invalid fields', () => {
|
||||
return user.post('/tasks', {
|
||||
it('ignores invalid fields', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
notValid: true,
|
||||
}).then((task) => {
|
||||
expect(task).not.to.have.property('notValid');
|
||||
});
|
||||
|
||||
expect(task).not.to.have.property('notValid');
|
||||
});
|
||||
});
|
||||
|
||||
context('habits', () => {
|
||||
it('creates a habit', () => {
|
||||
return user.post('/tasks', {
|
||||
it('creates a habit', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test habit',
|
||||
type: 'habit',
|
||||
up: false,
|
||||
down: true,
|
||||
notes: 1976,
|
||||
}).then((task) => {
|
||||
});
|
||||
|
||||
expect(task.userId).to.equal(user._id);
|
||||
expect(task.text).to.eql('test habit');
|
||||
expect(task.notes).to.eql('1976');
|
||||
@@ -105,54 +106,66 @@ describe('POST /tasks', () => {
|
||||
expect(task.up).to.eql(false);
|
||||
expect(task.down).to.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults to setting up and down to true', () => {
|
||||
return user.post('/tasks', {
|
||||
it('defaults to setting up and down to true', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test habit',
|
||||
type: 'habit',
|
||||
notes: 1976,
|
||||
}).then((task) => {
|
||||
});
|
||||
|
||||
expect(task.up).to.eql(true);
|
||||
expect(task.down).to.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
it('cannot create checklists', () => {
|
||||
return user.post('/tasks', {
|
||||
it('cannot create checklists', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test habit',
|
||||
type: 'habit',
|
||||
checklist: [
|
||||
{_id: 123, completed: false, text: 'checklist'},
|
||||
],
|
||||
}).then((task) => {
|
||||
expect(task).not.to.have.property('checklist');
|
||||
});
|
||||
|
||||
expect(task).not.to.have.property('checklist');
|
||||
});
|
||||
});
|
||||
|
||||
context('todos', () => {
|
||||
it('creates a todo', () => {
|
||||
return user.post('/tasks', {
|
||||
it('creates a todo', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test todo',
|
||||
type: 'todo',
|
||||
notes: 1976,
|
||||
}).then((task) => {
|
||||
});
|
||||
|
||||
expect(task.userId).to.equal(user._id);
|
||||
expect(task.text).to.eql('test todo');
|
||||
expect(task.notes).to.eql('1976');
|
||||
expect(task.type).to.eql('todo');
|
||||
});
|
||||
|
||||
it('updates user.tasksOrder.todos when a new todo is created', async () => {
|
||||
let originalTodosOrderLen = (await user.get('/user')).tasksOrder.todos.length;
|
||||
let task = await user.post('/tasks', {
|
||||
type: 'todo',
|
||||
text: 'a todo',
|
||||
});
|
||||
|
||||
it('can create checklists', () => {
|
||||
return user.post('/tasks', {
|
||||
let updatedUser = await user.get('/user');
|
||||
expect(updatedUser.tasksOrder.todos[0]).to.eql(task._id);
|
||||
expect(updatedUser.tasksOrder.todos.length).to.eql(originalTodosOrderLen + 1);
|
||||
});
|
||||
|
||||
it('can create checklists', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test todo',
|
||||
type: 'todo',
|
||||
checklist: [
|
||||
{completed: false, text: 'checklist'},
|
||||
],
|
||||
}).then((task) => {
|
||||
});
|
||||
|
||||
expect(task.checklist).to.be.an('array');
|
||||
expect(task.checklist.length).to.eql(1);
|
||||
expect(task.checklist[0]).to.be.an('object');
|
||||
@@ -161,20 +174,20 @@ describe('POST /tasks', () => {
|
||||
expect(task.checklist[0]._id).to.be.a('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('dailys', () => {
|
||||
it('creates a daily', () => {
|
||||
it('creates a daily', async () => {
|
||||
let now = new Date();
|
||||
|
||||
return user.post('/tasks', {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
notes: 1976,
|
||||
frequency: 'daily',
|
||||
everyX: 5,
|
||||
startDate: now,
|
||||
}).then((task) => {
|
||||
});
|
||||
|
||||
expect(task.userId).to.equal(user._id);
|
||||
expect(task.text).to.eql('test daily');
|
||||
expect(task.notes).to.eql('1976');
|
||||
@@ -183,13 +196,25 @@ describe('POST /tasks', () => {
|
||||
expect(task.everyX).to.eql(5);
|
||||
expect(new Date(task.startDate)).to.eql(now);
|
||||
});
|
||||
|
||||
it('updates user.tasksOrder.dailys when a new daily is created', async () => {
|
||||
let originalDailysOrderLen = (await user.get('/user')).tasksOrder.dailys.length;
|
||||
let task = await user.post('/tasks', {
|
||||
type: 'daily',
|
||||
text: 'a daily',
|
||||
});
|
||||
|
||||
it('defaults to a weekly frequency, with every day set', () => {
|
||||
return user.post('/tasks', {
|
||||
let updatedUser = await user.get('/user');
|
||||
expect(updatedUser.tasksOrder.dailys[0]).to.eql(task._id);
|
||||
expect(updatedUser.tasksOrder.dailys.length).to.eql(originalDailysOrderLen + 1);
|
||||
});
|
||||
|
||||
it('defaults to a weekly frequency, with every day set', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
}).then((task) => {
|
||||
});
|
||||
|
||||
expect(task.frequency).to.eql('weekly');
|
||||
expect(task.everyX).to.eql(1);
|
||||
expect(task.repeat).to.eql({
|
||||
@@ -202,10 +227,9 @@ describe('POST /tasks', () => {
|
||||
su: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('allows repeat field to be configured', () => {
|
||||
return user.post('/tasks', {
|
||||
it('allows repeat field to be configured', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
repeat: {
|
||||
@@ -213,7 +237,8 @@ describe('POST /tasks', () => {
|
||||
w: false,
|
||||
su: false,
|
||||
},
|
||||
}).then((task) => {
|
||||
});
|
||||
|
||||
expect(task.repeat).to.eql({
|
||||
m: false,
|
||||
t: true,
|
||||
@@ -224,27 +249,27 @@ describe('POST /tasks', () => {
|
||||
su: false,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('defaults startDate to today', () => {
|
||||
it('defaults startDate to today', async () => {
|
||||
let today = (new Date()).getDay();
|
||||
|
||||
return user.post('/tasks', {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
}).then((task) => {
|
||||
expect((new Date(task.startDate)).getDay()).to.eql(today);
|
||||
});
|
||||
});
|
||||
|
||||
it('can create checklists', () => {
|
||||
return user.post('/tasks', {
|
||||
expect((new Date(task.startDate)).getDay()).to.eql(today);
|
||||
});
|
||||
|
||||
it('can create checklists', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test daily',
|
||||
type: 'daily',
|
||||
checklist: [
|
||||
{completed: false, text: 'checklist'},
|
||||
],
|
||||
}).then((task) => {
|
||||
});
|
||||
|
||||
expect(task.checklist).to.be.an('array');
|
||||
expect(task.checklist.length).to.eql(1);
|
||||
expect(task.checklist[0]).to.be.an('object');
|
||||
@@ -253,53 +278,64 @@ describe('POST /tasks', () => {
|
||||
expect(task.checklist[0]._id).to.be.a('string');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
context('rewards', () => {
|
||||
it('creates a reward', () => {
|
||||
return user.post('/tasks', {
|
||||
it('creates a reward', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test reward',
|
||||
type: 'reward',
|
||||
notes: 1976,
|
||||
value: 10,
|
||||
}).then((task) => {
|
||||
});
|
||||
|
||||
expect(task.userId).to.equal(user._id);
|
||||
expect(task.text).to.eql('test reward');
|
||||
expect(task.notes).to.eql('1976');
|
||||
expect(task.type).to.eql('reward');
|
||||
expect(task.value).to.eql(10);
|
||||
});
|
||||
|
||||
it('updates user.tasksOrder.rewards when a new reward is created', async () => {
|
||||
let originalRewardsOrderLen = (await user.get('/user')).tasksOrder.rewards.length;
|
||||
let task = await user.post('/tasks', {
|
||||
type: 'reward',
|
||||
text: 'a reward',
|
||||
});
|
||||
|
||||
it('defaults to a 0 value', () => {
|
||||
return user.post('/tasks', {
|
||||
let updatedUser = await user.get('/user');
|
||||
expect(updatedUser.tasksOrder.rewards[0]).to.eql(task._id);
|
||||
expect(updatedUser.tasksOrder.rewards.length).to.eql(originalRewardsOrderLen + 1);
|
||||
});
|
||||
|
||||
it('defaults to a 0 value', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test reward',
|
||||
type: 'reward',
|
||||
}).then((task) => {
|
||||
});
|
||||
|
||||
expect(task.value).to.eql(0);
|
||||
});
|
||||
});
|
||||
|
||||
it('requires value to be coerced into a number', () => {
|
||||
return user.post('/tasks', {
|
||||
it('requires value to be coerced into a number', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test reward',
|
||||
type: 'reward',
|
||||
value: "10",
|
||||
}).then((task) => {
|
||||
expect(task.value).to.eql(10);
|
||||
});
|
||||
value: '10',
|
||||
});
|
||||
|
||||
it('cannot create checklists', () => {
|
||||
return user.post('/tasks', {
|
||||
expect(task.value).to.eql(10);
|
||||
});
|
||||
|
||||
it('cannot create checklists', async () => {
|
||||
let task = await user.post('/tasks', {
|
||||
text: 'test reward',
|
||||
type: 'reward',
|
||||
checklist: [
|
||||
{_id: 123, completed: false, text: 'checklist'},
|
||||
],
|
||||
}).then((task) => {
|
||||
});
|
||||
|
||||
expect(task).not.to.have.property('checklist');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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', {
|
||||
@@ -242,7 +242,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
||||
text: 'test plus habit',
|
||||
type: 'habit',
|
||||
down: false,
|
||||
})
|
||||
});
|
||||
}).then((task) => {
|
||||
plusHabit = task;
|
||||
user.post('/tasks', {
|
||||
@@ -250,7 +250,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
||||
type: 'habit',
|
||||
up: false,
|
||||
down: false,
|
||||
})
|
||||
});
|
||||
}).then((task) => {
|
||||
neitherHabit = task;
|
||||
});
|
||||
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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,16 +117,16 @@ 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);
|
||||
expect(savedTodo2.checklist[0].text).to.equal("789");
|
||||
expect(savedTodo2.checklist[0].text).to.equal('789');
|
||||
expect(savedTodo2.checklist[0].completed).to.equal(false);
|
||||
});
|
||||
});
|
||||
@@ -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,16 +178,16 @@ 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);
|
||||
expect(savedDaily2.checklist[0].text).to.equal("789");
|
||||
expect(savedDaily2.checklist[0].text).to.equal('789');
|
||||
expect(savedDaily2.checklist[0].completed).to.equal(false);
|
||||
});
|
||||
});
|
||||
@@ -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,
|
||||
});
|
||||
@@ -281,7 +278,7 @@ describe('PUT /tasks/:id', () => {
|
||||
|
||||
it('requires value to be coerced into a number', () => {
|
||||
return user.put(`/tasks/${reward._id}`, {
|
||||
value: "100",
|
||||
value: '100',
|
||||
}).then((task) => {
|
||||
expect(task.value).to.eql(100);
|
||||
});
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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'),
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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,
|
||||
username,
|
||||
email: uniqueEmail,
|
||||
password: password,
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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,79 +62,79 @@ 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();
|
||||
});
|
||||
});
|
||||
|
||||
it('sends english item name for gear if itemKey is provided', () => {
|
||||
data.itemKey = 'headAccessory_special_foxEars'
|
||||
data.itemKey = 'headAccessory_special_foxEars';
|
||||
|
||||
amplitudeNock
|
||||
.filteringPath(/httpapi.*itemName.*Fox%20Ears.*/g, '');
|
||||
|
||||
return analyticsService.track(eventType, data)
|
||||
.then((res) => {
|
||||
.then(() => {
|
||||
amplitudeNock.done();
|
||||
});
|
||||
});
|
||||
|
||||
it('sends english item name for egg if itemKey is provided', () => {
|
||||
data.itemKey = 'Wolf'
|
||||
data.itemKey = 'Wolf';
|
||||
|
||||
amplitudeNock
|
||||
.filteringPath(/httpapi.*itemName.*Wolf%20Egg.*/g, '');
|
||||
|
||||
return analyticsService.track(eventType, data)
|
||||
.then((res) => {
|
||||
.then(() => {
|
||||
amplitudeNock.done();
|
||||
});
|
||||
});
|
||||
|
||||
it('sends english item name for food if itemKey is provided', () => {
|
||||
data.itemKey = 'Cake_Skeleton'
|
||||
data.itemKey = 'Cake_Skeleton';
|
||||
|
||||
amplitudeNock
|
||||
.filteringPath(/httpapi.*itemName.*Bare%20Bones%20Cake.*/g, '');
|
||||
|
||||
return analyticsService.track(eventType, data)
|
||||
.then((res) => {
|
||||
.then(() => {
|
||||
amplitudeNock.done();
|
||||
});
|
||||
});
|
||||
|
||||
it('sends english item name for hatching potion if itemKey is provided', () => {
|
||||
data.itemKey = 'Golden'
|
||||
data.itemKey = 'Golden';
|
||||
|
||||
amplitudeNock
|
||||
.filteringPath(/httpapi.*itemName.*Golden%20Hatching%20Potion.*/g, '');
|
||||
|
||||
return analyticsService.track(eventType, data)
|
||||
.then((res) => {
|
||||
.then(() => {
|
||||
amplitudeNock.done();
|
||||
});
|
||||
});
|
||||
|
||||
it('sends english item name for quest if itemKey is provided', () => {
|
||||
data.itemKey = 'atom1'
|
||||
data.itemKey = 'atom1';
|
||||
|
||||
amplitudeNock
|
||||
.filteringPath(/httpapi.*itemName.*Attack%20of%20the%20Mundane%2C%20Part%201%3A%20Dish%20Disaster!.*/g, '');
|
||||
|
||||
return analyticsService.track(eventType, data)
|
||||
.then((res) => {
|
||||
.then(() => {
|
||||
amplitudeNock.done();
|
||||
});
|
||||
});
|
||||
|
||||
it('sends english item name for purchased spell if itemKey is provided', () => {
|
||||
data.itemKey = 'seafoam'
|
||||
data.itemKey = 'seafoam';
|
||||
|
||||
amplitudeNock
|
||||
.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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/* eslint-disable global-require */
|
||||
import request from 'request';
|
||||
import nconf from 'nconf';
|
||||
import nodemailer from 'nodemailer';
|
||||
@@ -14,21 +15,21 @@ function getUser () {
|
||||
},
|
||||
facebook: {
|
||||
emails: [{
|
||||
value: 'email@facebook'
|
||||
value: 'email@facebook',
|
||||
}],
|
||||
displayName: 'fb display name',
|
||||
}
|
||||
},
|
||||
},
|
||||
profile: {
|
||||
name: 'profile name',
|
||||
},
|
||||
preferences: {
|
||||
emailNotifications: {
|
||||
unsubscribeFromAll: false
|
||||
unsubscribeFromAll: false,
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
describe('emails', () => {
|
||||
let pathToEmailLib = '../../../../../website/src/libs/api-v3/email';
|
||||
@@ -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'),
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}));
|
||||
});
|
||||
|
||||
@@ -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'),
|
||||
}
|
||||
}
|
||||
},
|
||||
},
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,7 +34,7 @@ describe('i18n', () => {
|
||||
describe('localePath', () => {
|
||||
it('is an absolute path to common/locales/', () => {
|
||||
expect(localePath).to.match(/.*\/common\/locales\//);
|
||||
expect(localePath)
|
||||
expect(localePath);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
/* eslint-disable global-require */
|
||||
import {
|
||||
generateRes,
|
||||
generateReq,
|
||||
generateNext,
|
||||
} from '../../../../helpers/api-unit.helper';
|
||||
import analyticsService from '../../../../../website/src/libs/api-v3/analyticsService'
|
||||
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);
|
||||
|
||||
@@ -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' },
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,9 +3,9 @@ import {
|
||||
generateReq,
|
||||
generateNext,
|
||||
} 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;
|
||||
|
||||
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});
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import express from 'express';
|
||||
import _ from 'lodash';
|
||||
|
||||
const CONTROLLERS_PATH = path.join(__dirname, '/../../controllers/api-v3/');
|
||||
let router = express.Router(); // eslint-disable-line new-cap
|
||||
let router = express.Router(); // eslint-disable-line babel/new-cap
|
||||
|
||||
fs
|
||||
.readdirSync(CONTROLLERS_PATH)
|
||||
|
||||
Reference in New Issue
Block a user