mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +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'})
|
return user.post('/tags', {name: 'Tag 1'})
|
||||||
.then((tag) => {
|
.then((tag) => {
|
||||||
createdTag = tag;
|
createdTag = tag;
|
||||||
return user.get(`/tags/${createdTag._id}`)
|
return user.get(`/tags/${createdTag._id}`);
|
||||||
})
|
})
|
||||||
.then((tag) => {
|
.then((tag) => {
|
||||||
expect(tag).to.deep.equal(createdTag);
|
expect(tag).to.deep.equal(createdTag);
|
||||||
|
|||||||
@@ -12,13 +12,11 @@ describe('PUT /tags/:tagId', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('updates a tag given it\'s id', () => {
|
it('updates a tag given it\'s id', () => {
|
||||||
let length;
|
|
||||||
|
|
||||||
return user.post('/tags', {name: 'Tag 1'})
|
return user.post('/tags', {name: 'Tag 1'})
|
||||||
.then((createdTag) => {
|
.then((createdTag) => {
|
||||||
return user.put(`/tags/${createdTag._id}`, {
|
return user.put(`/tags/${createdTag._id}`, {
|
||||||
name: 'Tag updated',
|
name: 'Tag updated',
|
||||||
ignored: true
|
ignored: true,
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then((updatedTag) => {
|
.then((updatedTag) => {
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ describe('DELETE /tasks/:id', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('deletes a user\'s task', () => {
|
it('deletes a user\'s task', () => {
|
||||||
return user.del('/tasks/' + task._id)
|
return user.del(`/tasks/${task._id}`)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return expect(user.get('/tasks/' + task._id)).to.eventually.be.rejected.and.eql({
|
return expect(user.get(`/tasks/${task._id}`)).to.eventually.be.rejected.and.eql({
|
||||||
code: 404,
|
code: 404,
|
||||||
error: 'NotFound',
|
error: 'NotFound',
|
||||||
message: t('taskNotFound'),
|
message: t('taskNotFound'),
|
||||||
@@ -54,7 +54,7 @@ describe('DELETE /tasks/:id', () => {
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
.then((task2) => {
|
.then((task2) => {
|
||||||
return expect(user.del('/tasks/' + task2._id)).to.eventually.be.rejected.and.eql({
|
return expect(user.del(`/tasks/${task2._id}`)).to.eventually.be.rejected.and.eql({
|
||||||
code: 404,
|
code: 404,
|
||||||
error: 'NotFound',
|
error: 'NotFound',
|
||||||
message: t('taskNotFound'),
|
message: t('taskNotFound'),
|
||||||
@@ -63,5 +63,6 @@ describe('DELETE /tasks/:id', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('cannot delete active challenge tasks'); // TODO after challenges are implemented
|
it('cannot delete active challenge tasks'); // TODO after challenges are implemented
|
||||||
|
it('remove a task from user.tasksOrder'); // TODO
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
generateUser,
|
generateUser,
|
||||||
translate as t,
|
|
||||||
} from '../../../../helpers/api-integration.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
import Q from 'q';
|
import Q from 'q';
|
||||||
|
|
||||||
@@ -41,5 +40,5 @@ describe('GET /tasks', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// TODO complete after task scoring is done
|
// 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', () => {
|
it('gets specified task', () => {
|
||||||
return user.get('/tasks/' + task._id)
|
return user.get(`/tasks/${task._id}`)
|
||||||
.then((getTask) => {
|
.then((getTask) => {
|
||||||
expect(getTask).to.eql(task);
|
expect(getTask).to.eql(task);
|
||||||
});
|
});
|
||||||
@@ -38,7 +38,9 @@ describe('GET /tasks/:id', () => {
|
|||||||
|
|
||||||
context('task cannot be accessed', () => {
|
context('task cannot be accessed', () => {
|
||||||
it('cannot get a non-existant task', () => {
|
it('cannot get a non-existant task', () => {
|
||||||
return expect(user.get('/tasks/' + generateUUID())).to.eventually.be.rejected.and.eql({
|
let dummyId = generateUUID();
|
||||||
|
|
||||||
|
return expect(user.get(`/tasks/${dummyId}`)).to.eventually.be.rejected.and.eql({
|
||||||
code: 404,
|
code: 404,
|
||||||
error: 'NotFound',
|
error: 'NotFound',
|
||||||
message: t('taskNotFound'),
|
message: t('taskNotFound'),
|
||||||
@@ -57,7 +59,7 @@ describe('GET /tasks/:id', () => {
|
|||||||
type: 'habit',
|
type: 'habit',
|
||||||
});
|
});
|
||||||
}).then((task) => {
|
}).then((task) => {
|
||||||
return expect(anotherUser.get('/tasks/' + task._id)).to.eventually.be.rejected.and.eql({
|
return expect(anotherUser.get(`/tasks/${task._id}`)).to.eventually.be.rejected.and.eql({
|
||||||
code: 404,
|
code: 404,
|
||||||
error: 'NotFound',
|
error: 'NotFound',
|
||||||
message: t('taskNotFound'),
|
message: t('taskNotFound'),
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import {
|
|||||||
describe('POST /tasks', () => {
|
describe('POST /tasks', () => {
|
||||||
let user;
|
let user;
|
||||||
|
|
||||||
before(() => {
|
before(async () => {
|
||||||
return generateUser().then((generatedUser) => {
|
return generateUser().then((generatedUser) => {
|
||||||
user = generatedUser;
|
user = generatedUser;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('validates params', () => {
|
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', {
|
return expect(user.post('/tasks', {
|
||||||
notType: 'habit',
|
notType: 'habit',
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).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', {
|
return expect(user.post('/tasks', {
|
||||||
type: 'habitF',
|
type: 'habitF',
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).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', {
|
return expect(user.post('/tasks', {
|
||||||
type: 'habit',
|
type: 'habit',
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
@@ -43,19 +43,19 @@ describe('POST /tasks', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('automatically sets "task.userId" to user\'s uuid', () => {
|
it('automatically sets "task.userId" to user\'s uuid', async () => {
|
||||||
return user.post('/tasks', {
|
let task = await user.post('/tasks', {
|
||||||
text: 'test habit',
|
text: 'test habit',
|
||||||
type: '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,
|
it(`ignores setting userId, history, createdAt,
|
||||||
updatedAt, challenge, completed, streak,
|
updatedAt, challenge, completed, streak,
|
||||||
dateCompleted fields`, () => {
|
dateCompleted fields`, async () => {
|
||||||
return user.post('/tasks', {
|
let task = await user.post('/tasks', {
|
||||||
text: 'test daily',
|
text: 'test daily',
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
userId: 123,
|
userId: 123,
|
||||||
@@ -66,7 +66,8 @@ describe('POST /tasks', () => {
|
|||||||
completed: true,
|
completed: true,
|
||||||
streak: 25,
|
streak: 25,
|
||||||
dateCompleted: 'never',
|
dateCompleted: 'never',
|
||||||
}).then((task) => {
|
});
|
||||||
|
|
||||||
expect(task.userId).to.equal(user._id);
|
expect(task.userId).to.equal(user._id);
|
||||||
expect(task.history).to.eql([]);
|
expect(task.history).to.eql([]);
|
||||||
expect(task.createdAt).not.to.equal('yesterday');
|
expect(task.createdAt).not.to.equal('yesterday');
|
||||||
@@ -76,28 +77,28 @@ describe('POST /tasks', () => {
|
|||||||
expect(task.streak).to.equal(0);
|
expect(task.streak).to.equal(0);
|
||||||
expect(task.streak).not.to.equal('never');
|
expect(task.streak).not.to.equal('never');
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('ignores invalid fields', () => {
|
it('ignores invalid fields', async () => {
|
||||||
return user.post('/tasks', {
|
let task = await user.post('/tasks', {
|
||||||
text: 'test daily',
|
text: 'test daily',
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
notValid: true,
|
notValid: true,
|
||||||
}).then((task) => {
|
|
||||||
expect(task).not.to.have.property('notValid');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
expect(task).not.to.have.property('notValid');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('habits', () => {
|
context('habits', () => {
|
||||||
it('creates a habit', () => {
|
it('creates a habit', async () => {
|
||||||
return user.post('/tasks', {
|
let task = await user.post('/tasks', {
|
||||||
text: 'test habit',
|
text: 'test habit',
|
||||||
type: 'habit',
|
type: 'habit',
|
||||||
up: false,
|
up: false,
|
||||||
down: true,
|
down: true,
|
||||||
notes: 1976,
|
notes: 1976,
|
||||||
}).then((task) => {
|
});
|
||||||
|
|
||||||
expect(task.userId).to.equal(user._id);
|
expect(task.userId).to.equal(user._id);
|
||||||
expect(task.text).to.eql('test habit');
|
expect(task.text).to.eql('test habit');
|
||||||
expect(task.notes).to.eql('1976');
|
expect(task.notes).to.eql('1976');
|
||||||
@@ -105,54 +106,66 @@ describe('POST /tasks', () => {
|
|||||||
expect(task.up).to.eql(false);
|
expect(task.up).to.eql(false);
|
||||||
expect(task.down).to.eql(true);
|
expect(task.down).to.eql(true);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('defaults to setting up and down to true', () => {
|
it('defaults to setting up and down to true', async () => {
|
||||||
return user.post('/tasks', {
|
let task = await user.post('/tasks', {
|
||||||
text: 'test habit',
|
text: 'test habit',
|
||||||
type: 'habit',
|
type: 'habit',
|
||||||
notes: 1976,
|
notes: 1976,
|
||||||
}).then((task) => {
|
});
|
||||||
|
|
||||||
expect(task.up).to.eql(true);
|
expect(task.up).to.eql(true);
|
||||||
expect(task.down).to.eql(true);
|
expect(task.down).to.eql(true);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('cannot create checklists', () => {
|
it('cannot create checklists', async () => {
|
||||||
return user.post('/tasks', {
|
let task = await user.post('/tasks', {
|
||||||
text: 'test habit',
|
text: 'test habit',
|
||||||
type: 'habit',
|
type: 'habit',
|
||||||
checklist: [
|
checklist: [
|
||||||
{_id: 123, completed: false, text: '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', () => {
|
context('todos', () => {
|
||||||
it('creates a todo', () => {
|
it('creates a todo', async () => {
|
||||||
return user.post('/tasks', {
|
let task = await user.post('/tasks', {
|
||||||
text: 'test todo',
|
text: 'test todo',
|
||||||
type: 'todo',
|
type: 'todo',
|
||||||
notes: 1976,
|
notes: 1976,
|
||||||
}).then((task) => {
|
});
|
||||||
|
|
||||||
expect(task.userId).to.equal(user._id);
|
expect(task.userId).to.equal(user._id);
|
||||||
expect(task.text).to.eql('test todo');
|
expect(task.text).to.eql('test todo');
|
||||||
expect(task.notes).to.eql('1976');
|
expect(task.notes).to.eql('1976');
|
||||||
expect(task.type).to.eql('todo');
|
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', () => {
|
let updatedUser = await user.get('/user');
|
||||||
return user.post('/tasks', {
|
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',
|
text: 'test todo',
|
||||||
type: 'todo',
|
type: 'todo',
|
||||||
checklist: [
|
checklist: [
|
||||||
{completed: false, text: 'checklist'},
|
{completed: false, text: 'checklist'},
|
||||||
],
|
],
|
||||||
}).then((task) => {
|
});
|
||||||
|
|
||||||
expect(task.checklist).to.be.an('array');
|
expect(task.checklist).to.be.an('array');
|
||||||
expect(task.checklist.length).to.eql(1);
|
expect(task.checklist.length).to.eql(1);
|
||||||
expect(task.checklist[0]).to.be.an('object');
|
expect(task.checklist[0]).to.be.an('object');
|
||||||
@@ -161,20 +174,20 @@ describe('POST /tasks', () => {
|
|||||||
expect(task.checklist[0]._id).to.be.a('string');
|
expect(task.checklist[0]._id).to.be.a('string');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
context('dailys', () => {
|
context('dailys', () => {
|
||||||
it('creates a daily', () => {
|
it('creates a daily', async () => {
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
|
|
||||||
return user.post('/tasks', {
|
let task = await user.post('/tasks', {
|
||||||
text: 'test daily',
|
text: 'test daily',
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
notes: 1976,
|
notes: 1976,
|
||||||
frequency: 'daily',
|
frequency: 'daily',
|
||||||
everyX: 5,
|
everyX: 5,
|
||||||
startDate: now,
|
startDate: now,
|
||||||
}).then((task) => {
|
});
|
||||||
|
|
||||||
expect(task.userId).to.equal(user._id);
|
expect(task.userId).to.equal(user._id);
|
||||||
expect(task.text).to.eql('test daily');
|
expect(task.text).to.eql('test daily');
|
||||||
expect(task.notes).to.eql('1976');
|
expect(task.notes).to.eql('1976');
|
||||||
@@ -183,13 +196,25 @@ describe('POST /tasks', () => {
|
|||||||
expect(task.everyX).to.eql(5);
|
expect(task.everyX).to.eql(5);
|
||||||
expect(new Date(task.startDate)).to.eql(now);
|
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', () => {
|
let updatedUser = await user.get('/user');
|
||||||
return user.post('/tasks', {
|
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',
|
text: 'test daily',
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
}).then((task) => {
|
});
|
||||||
|
|
||||||
expect(task.frequency).to.eql('weekly');
|
expect(task.frequency).to.eql('weekly');
|
||||||
expect(task.everyX).to.eql(1);
|
expect(task.everyX).to.eql(1);
|
||||||
expect(task.repeat).to.eql({
|
expect(task.repeat).to.eql({
|
||||||
@@ -202,10 +227,9 @@ describe('POST /tasks', () => {
|
|||||||
su: true,
|
su: true,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('allows repeat field to be configured', () => {
|
it('allows repeat field to be configured', async () => {
|
||||||
return user.post('/tasks', {
|
let task = await user.post('/tasks', {
|
||||||
text: 'test daily',
|
text: 'test daily',
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
repeat: {
|
repeat: {
|
||||||
@@ -213,7 +237,8 @@ describe('POST /tasks', () => {
|
|||||||
w: false,
|
w: false,
|
||||||
su: false,
|
su: false,
|
||||||
},
|
},
|
||||||
}).then((task) => {
|
});
|
||||||
|
|
||||||
expect(task.repeat).to.eql({
|
expect(task.repeat).to.eql({
|
||||||
m: false,
|
m: false,
|
||||||
t: true,
|
t: true,
|
||||||
@@ -224,27 +249,27 @@ describe('POST /tasks', () => {
|
|||||||
su: false,
|
su: false,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('defaults startDate to today', () => {
|
it('defaults startDate to today', async () => {
|
||||||
let today = (new Date()).getDay();
|
let today = (new Date()).getDay();
|
||||||
|
|
||||||
return user.post('/tasks', {
|
let task = await user.post('/tasks', {
|
||||||
text: 'test daily',
|
text: 'test daily',
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
}).then((task) => {
|
|
||||||
expect((new Date(task.startDate)).getDay()).to.eql(today);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can create checklists', () => {
|
expect((new Date(task.startDate)).getDay()).to.eql(today);
|
||||||
return user.post('/tasks', {
|
});
|
||||||
|
|
||||||
|
it('can create checklists', async () => {
|
||||||
|
let task = await user.post('/tasks', {
|
||||||
text: 'test daily',
|
text: 'test daily',
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
checklist: [
|
checklist: [
|
||||||
{completed: false, text: 'checklist'},
|
{completed: false, text: 'checklist'},
|
||||||
],
|
],
|
||||||
}).then((task) => {
|
});
|
||||||
|
|
||||||
expect(task.checklist).to.be.an('array');
|
expect(task.checklist).to.be.an('array');
|
||||||
expect(task.checklist.length).to.eql(1);
|
expect(task.checklist.length).to.eql(1);
|
||||||
expect(task.checklist[0]).to.be.an('object');
|
expect(task.checklist[0]).to.be.an('object');
|
||||||
@@ -253,53 +278,64 @@ describe('POST /tasks', () => {
|
|||||||
expect(task.checklist[0]._id).to.be.a('string');
|
expect(task.checklist[0]._id).to.be.a('string');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
context('rewards', () => {
|
context('rewards', () => {
|
||||||
it('creates a reward', () => {
|
it('creates a reward', async () => {
|
||||||
return user.post('/tasks', {
|
let task = await user.post('/tasks', {
|
||||||
text: 'test reward',
|
text: 'test reward',
|
||||||
type: 'reward',
|
type: 'reward',
|
||||||
notes: 1976,
|
notes: 1976,
|
||||||
value: 10,
|
value: 10,
|
||||||
}).then((task) => {
|
});
|
||||||
|
|
||||||
expect(task.userId).to.equal(user._id);
|
expect(task.userId).to.equal(user._id);
|
||||||
expect(task.text).to.eql('test reward');
|
expect(task.text).to.eql('test reward');
|
||||||
expect(task.notes).to.eql('1976');
|
expect(task.notes).to.eql('1976');
|
||||||
expect(task.type).to.eql('reward');
|
expect(task.type).to.eql('reward');
|
||||||
expect(task.value).to.eql(10);
|
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', () => {
|
let updatedUser = await user.get('/user');
|
||||||
return user.post('/tasks', {
|
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',
|
text: 'test reward',
|
||||||
type: 'reward',
|
type: 'reward',
|
||||||
}).then((task) => {
|
});
|
||||||
|
|
||||||
expect(task.value).to.eql(0);
|
expect(task.value).to.eql(0);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
it('requires value to be coerced into a number', () => {
|
it('requires value to be coerced into a number', async () => {
|
||||||
return user.post('/tasks', {
|
let task = await user.post('/tasks', {
|
||||||
text: 'test reward',
|
text: 'test reward',
|
||||||
type: 'reward',
|
type: 'reward',
|
||||||
value: "10",
|
value: '10',
|
||||||
}).then((task) => {
|
|
||||||
expect(task.value).to.eql(10);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('cannot create checklists', () => {
|
expect(task.value).to.eql(10);
|
||||||
return user.post('/tasks', {
|
});
|
||||||
|
|
||||||
|
it('cannot create checklists', async () => {
|
||||||
|
let task = await user.post('/tasks', {
|
||||||
text: 'test reward',
|
text: 'test reward',
|
||||||
type: 'reward',
|
type: 'reward',
|
||||||
checklist: [
|
checklist: [
|
||||||
{_id: 123, completed: false, text: 'checklist'},
|
{_id: 123, completed: false, text: 'checklist'},
|
||||||
],
|
],
|
||||||
}).then((task) => {
|
});
|
||||||
|
|
||||||
expect(task).not.to.have.property('checklist');
|
expect(task).not.to.have.property('checklist');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|||||||
@@ -47,29 +47,29 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('completes todo when direction is up', () => {
|
it('completes todo when direction is up', () => {
|
||||||
return user.post(`/tasks/${todo._id}/score/up`)
|
return user.post(`/tasks/${todo._id}/score/up`)
|
||||||
.then((res) => user.get(`/tasks/${todo._id}`))
|
.then(() => user.get(`/tasks/${todo._id}`))
|
||||||
.then((task) => expect(task.completed).to.equal(true));
|
.then((task) => expect(task.completed).to.equal(true));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('moves completed todos out of user.tasksOrder.todos', () => {
|
it('moves completed todos out of user.tasksOrder.todos', () => {
|
||||||
return user.get('/user')
|
return user.get('/user')
|
||||||
.then(user => {
|
.then(usr => {
|
||||||
expect(user.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1)
|
expect(usr.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1);
|
||||||
}).then(() => user.post(`/tasks/${todo._id}/score/up`))
|
}).then(() => user.post(`/tasks/${todo._id}/score/up`))
|
||||||
.then(() => user.get(`/tasks/${todo._id}`))
|
.then(() => user.get(`/tasks/${todo._id}`))
|
||||||
.then((updatedTask) => {
|
.then((updatedTask) => {
|
||||||
expect(updatedTask.completed).to.equal(true);
|
expect(updatedTask.completed).to.equal(true);
|
||||||
return user.get('/user');
|
return user.get('/user');
|
||||||
})
|
})
|
||||||
.then((user) => {
|
.then((usr) => {
|
||||||
expect(user.tasksOrder.todos.indexOf(todo._id)).to.equal(-1)
|
expect(usr.tasksOrder.todos.indexOf(todo._id)).to.equal(-1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('moves un-completed todos back into user.tasksOrder.todos', () => {
|
it('moves un-completed todos back into user.tasksOrder.todos', () => {
|
||||||
return user.get('/user')
|
return user.get('/user')
|
||||||
.then(user => {
|
.then(usr => {
|
||||||
expect(user.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1)
|
expect(usr.tasksOrder.todos.indexOf(todo._id)).to.not.equal(-1);
|
||||||
}).then(() => user.post(`/tasks/${todo._id}/score/up`))
|
}).then(() => user.post(`/tasks/${todo._id}/score/up`))
|
||||||
.then(() => user.post(`/tasks/${todo._id}/score/down`))
|
.then(() => user.post(`/tasks/${todo._id}/score/down`))
|
||||||
.then(() => user.get(`/tasks/${todo._id}`))
|
.then(() => user.get(`/tasks/${todo._id}`))
|
||||||
@@ -77,16 +77,16 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
expect(updatedTask.completed).to.equal(false);
|
expect(updatedTask.completed).to.equal(false);
|
||||||
return user.get('/user');
|
return user.get('/user');
|
||||||
})
|
})
|
||||||
.then((user) => {
|
.then((usr) => {
|
||||||
let l = user.tasksOrder.todos.length;
|
let l = usr.tasksOrder.todos.length;
|
||||||
expect(user.tasksOrder.todos.indexOf(todo._id)).not.to.equal(-1);
|
expect(usr.tasksOrder.todos.indexOf(todo._id)).not.to.equal(-1);
|
||||||
expect(user.tasksOrder.todos.indexOf(todo._id)).to.equal(l - 1); // Check that it was pushed at the bottom
|
expect(usr.tasksOrder.todos.indexOf(todo._id)).to.equal(l - 1); // Check that it was pushed at the bottom
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uncompletes todo when direction is down', () => {
|
it('uncompletes todo when direction is down', () => {
|
||||||
return user.post(`/tasks/${todo._id}/score/down`)
|
return user.post(`/tasks/${todo._id}/score/down`)
|
||||||
.then((res) => user.get(`/tasks/${todo._id}`))
|
.then(() => user.get(`/tasks/${todo._id}`))
|
||||||
.then((updatedTask) => {
|
.then((updatedTask) => {
|
||||||
expect(updatedTask.completed).to.equal(false);
|
expect(updatedTask.completed).to.equal(false);
|
||||||
});
|
});
|
||||||
@@ -98,7 +98,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('increases user\'s mp when direction is up', () => {
|
it('increases user\'s mp when direction is up', () => {
|
||||||
return user.post(`/tasks/${todo._id}/score/up`)
|
return user.post(`/tasks/${todo._id}/score/up`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp);
|
expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp);
|
||||||
});
|
});
|
||||||
@@ -106,7 +106,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('decreases user\'s mp when direction is down', () => {
|
it('decreases user\'s mp when direction is down', () => {
|
||||||
return user.post(`/tasks/${todo._id}/score/down`)
|
return user.post(`/tasks/${todo._id}/score/down`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
|
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
|
||||||
});
|
});
|
||||||
@@ -114,7 +114,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('increases user\'s exp when direction is up', () => {
|
it('increases user\'s exp when direction is up', () => {
|
||||||
return user.post(`/tasks/${todo._id}/score/up`)
|
return user.post(`/tasks/${todo._id}/score/up`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp);
|
expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp);
|
||||||
});
|
});
|
||||||
@@ -122,7 +122,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('decreases user\'s exp when direction is down', () => {
|
it('decreases user\'s exp when direction is down', () => {
|
||||||
return user.post(`/tasks/${todo._id}/score/down`)
|
return user.post(`/tasks/${todo._id}/score/down`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.exp).to.be.lessThan(user.stats.exp);
|
expect(updatedUser.stats.exp).to.be.lessThan(user.stats.exp);
|
||||||
});
|
});
|
||||||
@@ -130,7 +130,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('increases user\'s gold when direction is up', () => {
|
it('increases user\'s gold when direction is up', () => {
|
||||||
return user.post(`/tasks/${todo._id}/score/up`)
|
return user.post(`/tasks/${todo._id}/score/up`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
|
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
|
||||||
});
|
});
|
||||||
@@ -138,7 +138,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('decreases user\'s gold when direction is down', () => {
|
it('decreases user\'s gold when direction is down', () => {
|
||||||
return user.post(`/tasks/${todo._id}/score/down`)
|
return user.post(`/tasks/${todo._id}/score/down`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.gp).to.be.lessThan(user.stats.gp);
|
expect(updatedUser.stats.gp).to.be.lessThan(user.stats.gp);
|
||||||
});
|
});
|
||||||
@@ -159,13 +159,13 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('completes daily when direction is up', () => {
|
it('completes daily when direction is up', () => {
|
||||||
return user.post(`/tasks/${daily._id}/score/up`)
|
return user.post(`/tasks/${daily._id}/score/up`)
|
||||||
.then((res) => user.get(`/tasks/${daily._id}`))
|
.then(() => user.get(`/tasks/${daily._id}`))
|
||||||
.then((task) => expect(task.completed).to.equal(true));
|
.then((task) => expect(task.completed).to.equal(true));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uncompletes daily when direction is down', () => {
|
it('uncompletes daily when direction is down', () => {
|
||||||
return user.post(`/tasks/${daily._id}/score/down`)
|
return user.post(`/tasks/${daily._id}/score/down`)
|
||||||
.then((res) => user.get(`/tasks/${daily._id}`))
|
.then(() => user.get(`/tasks/${daily._id}`))
|
||||||
.then((task) => expect(task.completed).to.equal(false));
|
.then((task) => expect(task.completed).to.equal(false));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -175,7 +175,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('increases user\'s mp when direction is up', () => {
|
it('increases user\'s mp when direction is up', () => {
|
||||||
return user.post(`/tasks/${daily._id}/score/up`)
|
return user.post(`/tasks/${daily._id}/score/up`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp);
|
expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp);
|
||||||
});
|
});
|
||||||
@@ -183,7 +183,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('decreases user\'s mp when direction is down', () => {
|
it('decreases user\'s mp when direction is down', () => {
|
||||||
return user.post(`/tasks/${daily._id}/score/down`)
|
return user.post(`/tasks/${daily._id}/score/down`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
|
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
|
||||||
});
|
});
|
||||||
@@ -191,7 +191,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('increases user\'s exp when direction is up', () => {
|
it('increases user\'s exp when direction is up', () => {
|
||||||
return user.post(`/tasks/${daily._id}/score/up`)
|
return user.post(`/tasks/${daily._id}/score/up`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp);
|
expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp);
|
||||||
});
|
});
|
||||||
@@ -199,7 +199,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('decreases user\'s exp when direction is down', () => {
|
it('decreases user\'s exp when direction is down', () => {
|
||||||
return user.post(`/tasks/${daily._id}/score/down`)
|
return user.post(`/tasks/${daily._id}/score/down`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.exp).to.be.lessThan(user.stats.exp);
|
expect(updatedUser.stats.exp).to.be.lessThan(user.stats.exp);
|
||||||
});
|
});
|
||||||
@@ -207,7 +207,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('increases user\'s gold when direction is up', () => {
|
it('increases user\'s gold when direction is up', () => {
|
||||||
return user.post(`/tasks/${daily._id}/score/up`)
|
return user.post(`/tasks/${daily._id}/score/up`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
|
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
|
||||||
});
|
});
|
||||||
@@ -215,7 +215,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('decreases user\'s gold when direction is down', () => {
|
it('decreases user\'s gold when direction is down', () => {
|
||||||
return user.post(`/tasks/${daily._id}/score/down`)
|
return user.post(`/tasks/${daily._id}/score/down`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.gp).to.be.lessThan(user.stats.gp);
|
expect(updatedUser.stats.gp).to.be.lessThan(user.stats.gp);
|
||||||
});
|
});
|
||||||
@@ -223,7 +223,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
context('habits', () => {
|
context('habits', () => {
|
||||||
let habit, minusHabit, plusHabit, neitherHabit;
|
let habit, minusHabit, plusHabit, neitherHabit; // eslint-disable-line no-unused-vars
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
return user.post('/tasks', {
|
return user.post('/tasks', {
|
||||||
@@ -242,7 +242,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
text: 'test plus habit',
|
text: 'test plus habit',
|
||||||
type: 'habit',
|
type: 'habit',
|
||||||
down: false,
|
down: false,
|
||||||
})
|
});
|
||||||
}).then((task) => {
|
}).then((task) => {
|
||||||
plusHabit = task;
|
plusHabit = task;
|
||||||
user.post('/tasks', {
|
user.post('/tasks', {
|
||||||
@@ -250,7 +250,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
type: 'habit',
|
type: 'habit',
|
||||||
up: false,
|
up: false,
|
||||||
down: false,
|
down: false,
|
||||||
})
|
});
|
||||||
}).then((task) => {
|
}).then((task) => {
|
||||||
neitherHabit = task;
|
neitherHabit = task;
|
||||||
});
|
});
|
||||||
@@ -262,7 +262,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('increases user\'s mp when direction is up', () => {
|
it('increases user\'s mp when direction is up', () => {
|
||||||
return user.post(`/tasks/${habit._id}/score/up`)
|
return user.post(`/tasks/${habit._id}/score/up`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp);
|
expect(updatedUser.stats.mp).to.be.greaterThan(user.stats.mp);
|
||||||
});
|
});
|
||||||
@@ -270,7 +270,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('decreases user\'s mp when direction is down', () => {
|
it('decreases user\'s mp when direction is down', () => {
|
||||||
return user.post(`/tasks/${habit._id}/score/down`)
|
return user.post(`/tasks/${habit._id}/score/down`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
|
expect(updatedUser.stats.mp).to.be.lessThan(user.stats.mp);
|
||||||
});
|
});
|
||||||
@@ -278,7 +278,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('increases user\'s exp when direction is up', () => {
|
it('increases user\'s exp when direction is up', () => {
|
||||||
return user.post(`/tasks/${habit._id}/score/up`)
|
return user.post(`/tasks/${habit._id}/score/up`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp);
|
expect(updatedUser.stats.exp).to.be.greaterThan(user.stats.exp);
|
||||||
});
|
});
|
||||||
@@ -286,7 +286,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('increases user\'s gold when direction is up', () => {
|
it('increases user\'s gold when direction is up', () => {
|
||||||
return user.post(`/tasks/${habit._id}/score/up`)
|
return user.post(`/tasks/${habit._id}/score/up`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
|
expect(updatedUser.stats.gp).to.be.greaterThan(user.stats.gp);
|
||||||
});
|
});
|
||||||
@@ -308,7 +308,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('purchases reward', () => {
|
it('purchases reward', () => {
|
||||||
return user.post(`/tasks/${reward._id}/score/up`)
|
return user.post(`/tasks/${reward._id}/score/up`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(user.stats.gp).to.equal(updatedUser.stats.gp + 5);
|
expect(user.stats.gp).to.equal(updatedUser.stats.gp + 5);
|
||||||
});
|
});
|
||||||
@@ -316,7 +316,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('does not change user\'s mp', () => {
|
it('does not change user\'s mp', () => {
|
||||||
return user.post(`/tasks/${reward._id}/score/up`)
|
return user.post(`/tasks/${reward._id}/score/up`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(user.stats.mp).to.equal(updatedUser.stats.mp);
|
expect(user.stats.mp).to.equal(updatedUser.stats.mp);
|
||||||
});
|
});
|
||||||
@@ -324,7 +324,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('does not change user\'s exp', () => {
|
it('does not change user\'s exp', () => {
|
||||||
return user.post(`/tasks/${reward._id}/score/up`)
|
return user.post(`/tasks/${reward._id}/score/up`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(user.stats.exp).to.equal(updatedUser.stats.exp);
|
expect(user.stats.exp).to.equal(updatedUser.stats.exp);
|
||||||
});
|
});
|
||||||
@@ -332,7 +332,7 @@ describe('POST /tasks/:id/score/:direction', () => {
|
|||||||
|
|
||||||
it('does not allow a down direction', () => {
|
it('does not allow a down direction', () => {
|
||||||
return user.post(`/tasks/${reward._id}/score/up`)
|
return user.post(`/tasks/${reward._id}/score/up`)
|
||||||
.then((res) => user.get(`/user`))
|
.then(() => user.get(`/user`))
|
||||||
.then((updatedUser) => {
|
.then((updatedUser) => {
|
||||||
expect(user.stats.mp).to.equal(updatedUser.stats.mp);
|
expect(user.stats.mp).to.equal(updatedUser.stats.mp);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
generateUser,
|
generateUser,
|
||||||
translate as t,
|
|
||||||
} from '../../../../helpers/api-integration.helper';
|
} from '../../../../helpers/api-integration.helper';
|
||||||
import { v4 as generateUUID } from 'uuid';
|
import { v4 as generateUUID } from 'uuid';
|
||||||
|
|
||||||
@@ -28,7 +27,7 @@ describe('PUT /tasks/:id', () => {
|
|||||||
it(`ignores setting _id, type, userId, history, createdAt,
|
it(`ignores setting _id, type, userId, history, createdAt,
|
||||||
updatedAt, challenge, completed, streak,
|
updatedAt, challenge, completed, streak,
|
||||||
dateCompleted fields`, () => {
|
dateCompleted fields`, () => {
|
||||||
user.put('/tasks/' + task._id, {
|
user.put(`/tasks/${task._id}`, {
|
||||||
_id: 123,
|
_id: 123,
|
||||||
type: 'daily',
|
type: 'daily',
|
||||||
userId: 123,
|
userId: 123,
|
||||||
@@ -54,7 +53,7 @@ describe('PUT /tasks/:id', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('ignores invalid fields', () => {
|
it('ignores invalid fields', () => {
|
||||||
user.put('/tasks/' + task._id, {
|
user.put(`/tasks/${task._id}`, {
|
||||||
notValid: true,
|
notValid: true,
|
||||||
}).then((savedTask) => {
|
}).then((savedTask) => {
|
||||||
expect(savedTask.notValid).to.be.a('undefined');
|
expect(savedTask.notValid).to.be.a('undefined');
|
||||||
@@ -118,16 +117,16 @@ describe('PUT /tasks/:id', () => {
|
|||||||
checklist: [
|
checklist: [
|
||||||
{text: 123, completed: false},
|
{text: 123, completed: false},
|
||||||
{text: 456, completed: true},
|
{text: 456, completed: true},
|
||||||
]
|
],
|
||||||
}).then((savedTodo) => {
|
}).then(() => {
|
||||||
return user.put(`/tasks/${todo._id}`, {
|
return user.put(`/tasks/${todo._id}`, {
|
||||||
checklist: [
|
checklist: [
|
||||||
{text: 789, completed: false},
|
{text: 789, completed: false},
|
||||||
]
|
],
|
||||||
});
|
});
|
||||||
}).then((savedTodo2) => {
|
}).then((savedTodo2) => {
|
||||||
expect(savedTodo2.checklist.length).to.equal(1);
|
expect(savedTodo2.checklist.length).to.equal(1);
|
||||||
expect(savedTodo2.checklist[0].text).to.equal("789");
|
expect(savedTodo2.checklist[0].text).to.equal('789');
|
||||||
expect(savedTodo2.checklist[0].completed).to.equal(false);
|
expect(savedTodo2.checklist[0].completed).to.equal(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -136,9 +135,9 @@ describe('PUT /tasks/:id', () => {
|
|||||||
let finalUUID = generateUUID();
|
let finalUUID = generateUUID();
|
||||||
return user.put(`/tasks/${todo._id}`, {
|
return user.put(`/tasks/${todo._id}`, {
|
||||||
tags: [generateUUID(), generateUUID()],
|
tags: [generateUUID(), generateUUID()],
|
||||||
}).then((savedTodo) => {
|
}).then(() => {
|
||||||
return user.put(`/tasks/${todo._id}`, {
|
return user.put(`/tasks/${todo._id}`, {
|
||||||
tags: [finalUUID]
|
tags: [finalUUID],
|
||||||
});
|
});
|
||||||
}).then((savedTodo2) => {
|
}).then((savedTodo2) => {
|
||||||
expect(savedTodo2.tags.length).to.equal(1);
|
expect(savedTodo2.tags.length).to.equal(1);
|
||||||
@@ -161,8 +160,6 @@ describe('PUT /tasks/:id', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('updates a daily', () => {
|
it('updates a daily', () => {
|
||||||
let now = new Date();
|
|
||||||
|
|
||||||
return user.put(`/tasks/${daily._id}`, {
|
return user.put(`/tasks/${daily._id}`, {
|
||||||
text: 'some new text',
|
text: 'some new text',
|
||||||
notes: 'some new notes',
|
notes: 'some new notes',
|
||||||
@@ -181,16 +178,16 @@ describe('PUT /tasks/:id', () => {
|
|||||||
checklist: [
|
checklist: [
|
||||||
{text: 123, completed: false},
|
{text: 123, completed: false},
|
||||||
{text: 456, completed: true},
|
{text: 456, completed: true},
|
||||||
]
|
],
|
||||||
}).then((savedDaily) => {
|
}).then(() => {
|
||||||
return user.put(`/tasks/${daily._id}`, {
|
return user.put(`/tasks/${daily._id}`, {
|
||||||
checklist: [
|
checklist: [
|
||||||
{text: 789, completed: false},
|
{text: 789, completed: false},
|
||||||
]
|
],
|
||||||
});
|
});
|
||||||
}).then((savedDaily2) => {
|
}).then((savedDaily2) => {
|
||||||
expect(savedDaily2.checklist.length).to.equal(1);
|
expect(savedDaily2.checklist.length).to.equal(1);
|
||||||
expect(savedDaily2.checklist[0].text).to.equal("789");
|
expect(savedDaily2.checklist[0].text).to.equal('789');
|
||||||
expect(savedDaily2.checklist[0].completed).to.equal(false);
|
expect(savedDaily2.checklist[0].completed).to.equal(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -199,9 +196,9 @@ describe('PUT /tasks/:id', () => {
|
|||||||
let finalUUID = generateUUID();
|
let finalUUID = generateUUID();
|
||||||
return user.put(`/tasks/${daily._id}`, {
|
return user.put(`/tasks/${daily._id}`, {
|
||||||
tags: [generateUUID(), generateUUID()],
|
tags: [generateUUID(), generateUUID()],
|
||||||
}).then((savedDaily) => {
|
}).then(() => {
|
||||||
return user.put(`/tasks/${daily._id}`, {
|
return user.put(`/tasks/${daily._id}`, {
|
||||||
tags: [finalUUID]
|
tags: [finalUUID],
|
||||||
});
|
});
|
||||||
}).then((savedDaily2) => {
|
}).then((savedDaily2) => {
|
||||||
expect(savedDaily2.tags.length).to.equal(1);
|
expect(savedDaily2.tags.length).to.equal(1);
|
||||||
@@ -212,12 +209,12 @@ describe('PUT /tasks/:id', () => {
|
|||||||
it('updates repeat, even if frequency is set to daily', () => {
|
it('updates repeat, even if frequency is set to daily', () => {
|
||||||
return user.put(`/tasks/${daily._id}`, {
|
return user.put(`/tasks/${daily._id}`, {
|
||||||
frequency: 'daily',
|
frequency: 'daily',
|
||||||
}).then((savedDaily) => {
|
}).then(() => {
|
||||||
return user.put(`/tasks/${daily._id}`, {
|
return user.put(`/tasks/${daily._id}`, {
|
||||||
repeat: {
|
repeat: {
|
||||||
m: false,
|
m: false,
|
||||||
su: false
|
su: false,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}).then((savedDaily2) => {
|
}).then((savedDaily2) => {
|
||||||
expect(savedDaily2.repeat).to.eql({
|
expect(savedDaily2.repeat).to.eql({
|
||||||
@@ -235,7 +232,7 @@ describe('PUT /tasks/:id', () => {
|
|||||||
it('updates everyX, even if frequency is set to weekly', () => {
|
it('updates everyX, even if frequency is set to weekly', () => {
|
||||||
return user.put(`/tasks/${daily._id}`, {
|
return user.put(`/tasks/${daily._id}`, {
|
||||||
frequency: 'weekly',
|
frequency: 'weekly',
|
||||||
}).then((savedDaily) => {
|
}).then(() => {
|
||||||
return user.put(`/tasks/${daily._id}`, {
|
return user.put(`/tasks/${daily._id}`, {
|
||||||
everyX: 5,
|
everyX: 5,
|
||||||
});
|
});
|
||||||
@@ -281,7 +278,7 @@ describe('PUT /tasks/:id', () => {
|
|||||||
|
|
||||||
it('requires value to be coerced into a number', () => {
|
it('requires value to be coerced into a number', () => {
|
||||||
return user.put(`/tasks/${reward._id}`, {
|
return user.put(`/tasks/${reward._id}`, {
|
||||||
value: "100",
|
value: '100',
|
||||||
}).then((task) => {
|
}).then((task) => {
|
||||||
expect(task.value).to.eql(100);
|
expect(task.value).to.eql(100);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -46,15 +46,13 @@ describe('DELETE /tasks/:taskId/checklist/:itemId', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('does not work with rewards', () => {
|
it('does not work with rewards', async () => {
|
||||||
let reward;
|
let reward = await user.post('/tasks', {
|
||||||
return expect(user.post('/tasks', {
|
|
||||||
type: 'reward',
|
type: 'reward',
|
||||||
text: 'reward with checklist',
|
text: 'reward with checklist',
|
||||||
}).then(createdTask => {
|
});
|
||||||
reward = createdTask;
|
|
||||||
return user.del(`/tasks/${reward._id}/checklist/${generateUUID()}`);
|
await expect(user.del(`/tasks/${reward._id}/checklist/${generateUUID()}`)).to.eventually.be.rejected.and.eql({
|
||||||
}).then(checklistItem => {})).to.eventually.be.rejected.and.eql({
|
|
||||||
code: 400,
|
code: 400,
|
||||||
error: 'BadRequest',
|
error: 'BadRequest',
|
||||||
message: t('checklistOnlyDailyTodo'),
|
message: t('checklistOnlyDailyTodo'),
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ describe('POST /tasks/:taskId/checklist/', () => {
|
|||||||
|
|
||||||
it('fails on task not found', () => {
|
it('fails on task not found', () => {
|
||||||
return expect(user.post(`/tasks/${generateUUID()}/checklist`, {
|
return expect(user.post(`/tasks/${generateUUID()}/checklist`, {
|
||||||
text: 'Checklist Item 1'
|
text: 'Checklist Item 1',
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
code: 404,
|
code: 404,
|
||||||
error: 'NotFound',
|
error: 'NotFound',
|
||||||
|
|||||||
@@ -45,15 +45,13 @@ describe('POST /tasks/:taskId/checklist/:itemId/score', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails on rewards', () => {
|
it('fails on rewards', async () => {
|
||||||
let reward;
|
let reward = await user.post('/tasks', {
|
||||||
return expect(user.post('/tasks', {
|
|
||||||
type: 'reward',
|
type: 'reward',
|
||||||
text: 'reward with checklist',
|
text: 'reward with checklist',
|
||||||
}).then(createdTask => {
|
});
|
||||||
reward = createdTask;
|
|
||||||
return user.post(`/tasks/${reward._id}/checklist/${generateUUID()}/score`);
|
await expect(user.post(`/tasks/${reward._id}/checklist/${generateUUID()}/score`)).to.eventually.be.rejected.and.eql({
|
||||||
}).then(checklistItem => {})).to.eventually.be.rejected.and.eql({
|
|
||||||
code: 400,
|
code: 400,
|
||||||
error: 'BadRequest',
|
error: 'BadRequest',
|
||||||
message: t('checklistOnlyDailyTodo'),
|
message: t('checklistOnlyDailyTodo'),
|
||||||
|
|||||||
@@ -32,30 +32,26 @@ describe('PUT /tasks/:taskId/checklist/:itemId', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails on habits', () => {
|
it('fails on habits', async () => {
|
||||||
let habit;
|
let habit = await user.post('/tasks', {
|
||||||
return expect(user.post('/tasks', {
|
|
||||||
type: 'habit',
|
type: 'habit',
|
||||||
text: 'habit with checklist',
|
text: 'habit with checklist',
|
||||||
}).then(createdTask => {
|
});
|
||||||
habit = createdTask;
|
|
||||||
return user.put(`/tasks/${habit._id}/checklist/${generateUUID()}`);
|
await expect(user.put(`/tasks/${habit._id}/checklist/${generateUUID()}`)).to.eventually.be.rejected.and.eql({
|
||||||
})).to.eventually.be.rejected.and.eql({
|
|
||||||
code: 400,
|
code: 400,
|
||||||
error: 'BadRequest',
|
error: 'BadRequest',
|
||||||
message: t('checklistOnlyDailyTodo'),
|
message: t('checklistOnlyDailyTodo'),
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('fails on rewards', () => {
|
it('fails on rewards', async () => {
|
||||||
let reward;
|
let reward = await user.post('/tasks', {
|
||||||
return expect(user.post('/tasks', {
|
|
||||||
type: 'reward',
|
type: 'reward',
|
||||||
text: 'reward with checklist',
|
text: 'reward with checklist',
|
||||||
}).then(createdTask => {
|
});
|
||||||
reward = createdTask;
|
|
||||||
return user.put(`/tasks/${reward._id}/checklist/${generateUUID()}`);
|
await expect(user.put(`/tasks/${reward._id}/checklist/${generateUUID()}`)).to.eventually.be.rejected.and.eql({
|
||||||
}).then(checklistItem => {})).to.eventually.be.rejected.and.eql({
|
|
||||||
code: 400,
|
code: 400,
|
||||||
error: 'BadRequest',
|
error: 'BadRequest',
|
||||||
message: t('checklistOnlyDailyTodo'),
|
message: t('checklistOnlyDailyTodo'),
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ describe('DELETE /tasks/:taskId/tags/:tagId', () => {
|
|||||||
}).then(createdTag => {
|
}).then(createdTag => {
|
||||||
tag = createdTag;
|
tag = createdTag;
|
||||||
return user.post(`/tasks/${task._id}/tags/${tag._id}`);
|
return user.post(`/tasks/${task._id}/tags/${tag._id}`);
|
||||||
}).then(savedTask => {
|
}).then(() => {
|
||||||
return user.del(`/tasks/${task._id}/tags/${tag._id}`);
|
return user.del(`/tasks/${task._id}/tags/${tag._id}`);
|
||||||
}).then(() => user.get(`/tasks/${task._id}`))
|
}).then(() => user.get(`/tasks/${task._id}`))
|
||||||
.then(updatedTask => {
|
.then(updatedTask => {
|
||||||
@@ -35,8 +35,6 @@ describe('DELETE /tasks/:taskId/tags/:tagId', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('only deletes existing tags', () => {
|
it('only deletes existing tags', () => {
|
||||||
let task;
|
|
||||||
|
|
||||||
return expect(user.post('/tasks', {
|
return expect(user.post('/tasks', {
|
||||||
type: 'habit',
|
type: 'habit',
|
||||||
text: 'Task with tag',
|
text: 'Task with tag',
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ describe('POST /user/auth/local/register', () => {
|
|||||||
username,
|
username,
|
||||||
email,
|
email,
|
||||||
password,
|
password,
|
||||||
confirmPassword: confirmPassword,
|
confirmPassword,
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
code: 400,
|
code: 400,
|
||||||
error: 'BadRequest',
|
error: 'BadRequest',
|
||||||
@@ -104,8 +104,8 @@ describe('POST /user/auth/local/register', () => {
|
|||||||
|
|
||||||
return expect(api.post('/user/auth/local/register', {
|
return expect(api.post('/user/auth/local/register', {
|
||||||
username,
|
username,
|
||||||
email: email,
|
email,
|
||||||
confirmPassword: confirmPassword,
|
confirmPassword,
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
code: 400,
|
code: 400,
|
||||||
error: 'BadRequest',
|
error: 'BadRequest',
|
||||||
@@ -123,7 +123,7 @@ describe('POST /user/auth/local/register', () => {
|
|||||||
return generateUser({
|
return generateUser({
|
||||||
'auth.local.username': username,
|
'auth.local.username': username,
|
||||||
'auth.local.lowerCaseUsername': username,
|
'auth.local.lowerCaseUsername': username,
|
||||||
'auth.local.email': email
|
'auth.local.email': email,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -133,9 +133,9 @@ describe('POST /user/auth/local/register', () => {
|
|||||||
let password = 'password';
|
let password = 'password';
|
||||||
|
|
||||||
return expect(api.post('/user/auth/local/register', {
|
return expect(api.post('/user/auth/local/register', {
|
||||||
username: username,
|
username,
|
||||||
email: uniqueEmail,
|
email: uniqueEmail,
|
||||||
password: password,
|
password,
|
||||||
confirmPassword: password,
|
confirmPassword: password,
|
||||||
})).to.eventually.be.rejected.and.eql({
|
})).to.eventually.be.rejected.and.eql({
|
||||||
code: 401,
|
code: 401,
|
||||||
@@ -181,7 +181,7 @@ describe('POST /user/auth/local/register', () => {
|
|||||||
}).then((user) => {
|
}).then((user) => {
|
||||||
expect(user.flags.tour).to.not.be.empty;
|
expect(user.flags.tour).to.not.be.empty;
|
||||||
|
|
||||||
each(user.flags.tour, (value, attribute) => {
|
each(user.flags.tour, (value) => {
|
||||||
expect(value).to.eql(-2);
|
expect(value).to.eql(-2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -232,7 +232,7 @@ describe('POST /user/auth/local/register', () => {
|
|||||||
}).then((user) => {
|
}).then((user) => {
|
||||||
expect(user.flags.tour).to.not.be.empty;
|
expect(user.flags.tour).to.not.be.empty;
|
||||||
|
|
||||||
each(user.flags.tutorial.common, (value, attribute) => {
|
each(user.flags.tutorial.common, (value) => {
|
||||||
expect(value).to.eql(true);
|
expect(value).to.eql(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -23,14 +23,14 @@ describe('analyticsService', () => {
|
|||||||
category: 'behavior',
|
category: 'behavior',
|
||||||
uuid: 'unique-user-id',
|
uuid: 'unique-user-id',
|
||||||
resting: true,
|
resting: true,
|
||||||
cronCount: 5
|
cronCount: 5,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
context('Amplitude', () => {
|
context('Amplitude', () => {
|
||||||
it('calls out to amplitude', () => {
|
it('calls out to amplitude', () => {
|
||||||
return analyticsService.track(eventType, data)
|
return analyticsService.track(eventType, data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -42,7 +42,7 @@ describe('analyticsService', () => {
|
|||||||
.filteringPath(/httpapi.*user_id.*no-user-id-was-provided.*/g, '');
|
.filteringPath(/httpapi.*user_id.*no-user-id-was-provided.*/g, '');
|
||||||
|
|
||||||
return analyticsService.track(eventType, data)
|
return analyticsService.track(eventType, data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -52,7 +52,7 @@ describe('analyticsService', () => {
|
|||||||
.filteringPath(/httpapi.*platform.*server.*/g, '');
|
.filteringPath(/httpapi.*platform.*server.*/g, '');
|
||||||
|
|
||||||
return analyticsService.track(eventType, data)
|
return analyticsService.track(eventType, data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -62,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, '');
|
.filteringPath(/httpapi.*event_properties%22%3A%7B%22category%22%3A%22behavior%22%2C%22resting%22%3Atrue%2C%22cronCount%22%3A5%7D%2C%22.*/g, '');
|
||||||
|
|
||||||
return analyticsService.track(eventType, data)
|
return analyticsService.track(eventType, data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends english item name for gear if itemKey is provided', () => {
|
it('sends english item name for gear if itemKey is provided', () => {
|
||||||
data.itemKey = 'headAccessory_special_foxEars'
|
data.itemKey = 'headAccessory_special_foxEars';
|
||||||
|
|
||||||
amplitudeNock
|
amplitudeNock
|
||||||
.filteringPath(/httpapi.*itemName.*Fox%20Ears.*/g, '');
|
.filteringPath(/httpapi.*itemName.*Fox%20Ears.*/g, '');
|
||||||
|
|
||||||
return analyticsService.track(eventType, data)
|
return analyticsService.track(eventType, data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends english item name for egg if itemKey is provided', () => {
|
it('sends english item name for egg if itemKey is provided', () => {
|
||||||
data.itemKey = 'Wolf'
|
data.itemKey = 'Wolf';
|
||||||
|
|
||||||
amplitudeNock
|
amplitudeNock
|
||||||
.filteringPath(/httpapi.*itemName.*Wolf%20Egg.*/g, '');
|
.filteringPath(/httpapi.*itemName.*Wolf%20Egg.*/g, '');
|
||||||
|
|
||||||
return analyticsService.track(eventType, data)
|
return analyticsService.track(eventType, data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends english item name for food if itemKey is provided', () => {
|
it('sends english item name for food if itemKey is provided', () => {
|
||||||
data.itemKey = 'Cake_Skeleton'
|
data.itemKey = 'Cake_Skeleton';
|
||||||
|
|
||||||
amplitudeNock
|
amplitudeNock
|
||||||
.filteringPath(/httpapi.*itemName.*Bare%20Bones%20Cake.*/g, '');
|
.filteringPath(/httpapi.*itemName.*Bare%20Bones%20Cake.*/g, '');
|
||||||
|
|
||||||
return analyticsService.track(eventType, data)
|
return analyticsService.track(eventType, data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends english item name for hatching potion if itemKey is provided', () => {
|
it('sends english item name for hatching potion if itemKey is provided', () => {
|
||||||
data.itemKey = 'Golden'
|
data.itemKey = 'Golden';
|
||||||
|
|
||||||
amplitudeNock
|
amplitudeNock
|
||||||
.filteringPath(/httpapi.*itemName.*Golden%20Hatching%20Potion.*/g, '');
|
.filteringPath(/httpapi.*itemName.*Golden%20Hatching%20Potion.*/g, '');
|
||||||
|
|
||||||
return analyticsService.track(eventType, data)
|
return analyticsService.track(eventType, data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends english item name for quest if itemKey is provided', () => {
|
it('sends english item name for quest if itemKey is provided', () => {
|
||||||
data.itemKey = 'atom1'
|
data.itemKey = 'atom1';
|
||||||
|
|
||||||
amplitudeNock
|
amplitudeNock
|
||||||
.filteringPath(/httpapi.*itemName.*Attack%20of%20the%20Mundane%2C%20Part%201%3A%20Dish%20Disaster!.*/g, '');
|
.filteringPath(/httpapi.*itemName.*Attack%20of%20the%20Mundane%2C%20Part%201%3A%20Dish%20Disaster!.*/g, '');
|
||||||
|
|
||||||
return analyticsService.track(eventType, data)
|
return analyticsService.track(eventType, data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('sends english item name for purchased spell if itemKey is provided', () => {
|
it('sends english item name for purchased spell if itemKey is provided', () => {
|
||||||
data.itemKey = 'seafoam'
|
data.itemKey = 'seafoam';
|
||||||
|
|
||||||
amplitudeNock
|
amplitudeNock
|
||||||
.filteringPath(/httpapi.*itemName.*Seafoam.*/g, '');
|
.filteringPath(/httpapi.*itemName.*Seafoam.*/g, '');
|
||||||
|
|
||||||
return analyticsService.track(eventType, data)
|
return analyticsService.track(eventType, data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -142,14 +142,14 @@ describe('analyticsService', () => {
|
|||||||
it('sends user data if provided', () => {
|
it('sends user data if provided', () => {
|
||||||
let stats = { class: 'wizard', exp: 5, gp: 23, hp: 10, lvl: 4, mp: 30 };
|
let stats = { class: 'wizard', exp: 5, gp: 23, hp: 10, lvl: 4, mp: 30 };
|
||||||
let user = {
|
let user = {
|
||||||
stats: stats,
|
stats,
|
||||||
contributor: { level: 1 },
|
contributor: { level: 1 },
|
||||||
purchased: { plan: { planId: 'foo-plan' } },
|
purchased: { plan: { planId: 'foo-plan' } },
|
||||||
flags: {tour: {intro: -2}},
|
flags: {tour: {intro: -2}},
|
||||||
habits: [{_id: 'habit'}],
|
habits: [{_id: 'habit'}],
|
||||||
dailys: [{_id: 'daily'}],
|
dailys: [{_id: 'daily'}],
|
||||||
todos: [{_id: 'todo'}],
|
todos: [{_id: 'todo'}],
|
||||||
rewards: [{_id: 'reward'}]
|
rewards: [{_id: 'reward'}],
|
||||||
};
|
};
|
||||||
|
|
||||||
data.user = user;
|
data.user = user;
|
||||||
@@ -158,7 +158,7 @@ describe('analyticsService', () => {
|
|||||||
.filteringPath(/httpapi.*user_properties%22%3A%7B%22Class%22%3A%22wizard%22%2C%22Experience%22%3A5%2C%22Gold%22%3A23%2C%22Health%22%3A10%2C%22Level%22%3A4%2C%22Mana%22%3A30%2C%22tutorialComplete%22%3Atrue%2C%22Number%20Of%20Tasks%22%3A%7B%22habits%22%3A1%2C%22dailys%22%3A1%2C%22todos%22%3A1%2C%22rewards%22%3A1%7D%2C%22contributorLevel%22%3A1%2C%22subscription%22%3A%22foo-plan%22%7D%2C%22.*/g, '');
|
.filteringPath(/httpapi.*user_properties%22%3A%7B%22Class%22%3A%22wizard%22%2C%22Experience%22%3A5%2C%22Gold%22%3A23%2C%22Health%22%3A10%2C%22Level%22%3A4%2C%22Mana%22%3A30%2C%22tutorialComplete%22%3Atrue%2C%22Number%20Of%20Tasks%22%3A%7B%22habits%22%3A1%2C%22dailys%22%3A1%2C%22todos%22%3A1%2C%22rewards%22%3A1%7D%2C%22contributorLevel%22%3A1%2C%22subscription%22%3A%22foo-plan%22%7D%2C%22.*/g, '');
|
||||||
|
|
||||||
return analyticsService.track(eventType, data)
|
return analyticsService.track(eventType, data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -171,7 +171,7 @@ describe('analyticsService', () => {
|
|||||||
.reply(200, {status: 'OK'});
|
.reply(200, {status: 'OK'});
|
||||||
|
|
||||||
return analyticsService.track(eventType, data)
|
return analyticsService.track(eventType, data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
gaNock.done();
|
gaNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -182,7 +182,7 @@ describe('analyticsService', () => {
|
|||||||
.reply(200, {status: 'OK'});
|
.reply(200, {status: 'OK'});
|
||||||
|
|
||||||
return analyticsService.track(eventType, data)
|
return analyticsService.track(eventType, data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
gaNock.done();
|
gaNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -201,14 +201,14 @@ describe('analyticsService', () => {
|
|||||||
purchaseValue: 8,
|
purchaseValue: 8,
|
||||||
purchaseType: 'checkout',
|
purchaseType: 'checkout',
|
||||||
gift: false,
|
gift: false,
|
||||||
quantity: 1
|
quantity: 1,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
context('Amplitude', () => {
|
context('Amplitude', () => {
|
||||||
it('calls out to amplitude', () => {
|
it('calls out to amplitude', () => {
|
||||||
return analyticsService.trackPurchase(data)
|
return analyticsService.trackPurchase(data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -220,7 +220,7 @@ describe('analyticsService', () => {
|
|||||||
.filteringPath(/httpapi.*user_id.*no-user-id-was-provided.*/g, '');
|
.filteringPath(/httpapi.*user_id.*no-user-id-was-provided.*/g, '');
|
||||||
|
|
||||||
return analyticsService.trackPurchase(data)
|
return analyticsService.trackPurchase(data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -230,7 +230,7 @@ describe('analyticsService', () => {
|
|||||||
.filteringPath(/httpapi.*platform.*server.*/g, '');
|
.filteringPath(/httpapi.*platform.*server.*/g, '');
|
||||||
|
|
||||||
return analyticsService.trackPurchase(data)
|
return analyticsService.trackPurchase(data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -240,7 +240,7 @@ describe('analyticsService', () => {
|
|||||||
.filteringPath(/httpapi.*aypal-checkout%22%2C%22paymentMethod%22%3A%22PayPal%22%2C%22itemPurchased%22%3A%22Gems%22%2C%22purchaseType%22%3A%22checkout%22%2C%22gift%22%3Afalse%2C%22quantity%22%3A1%7D%2C%22event_type%22%3A%22purchase%22%2C%22revenue.*/g, '');
|
.filteringPath(/httpapi.*aypal-checkout%22%2C%22paymentMethod%22%3A%22PayPal%22%2C%22itemPurchased%22%3A%22Gems%22%2C%22purchaseType%22%3A%22checkout%22%2C%22gift%22%3Afalse%2C%22quantity%22%3A1%7D%2C%22event_type%22%3A%22purchase%22%2C%22revenue.*/g, '');
|
||||||
|
|
||||||
return analyticsService.trackPurchase(data)
|
return analyticsService.trackPurchase(data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -248,14 +248,14 @@ describe('analyticsService', () => {
|
|||||||
it('sends user data if provided', () => {
|
it('sends user data if provided', () => {
|
||||||
let stats = { class: 'wizard', exp: 5, gp: 23, hp: 10, lvl: 4, mp: 30 };
|
let stats = { class: 'wizard', exp: 5, gp: 23, hp: 10, lvl: 4, mp: 30 };
|
||||||
let user = {
|
let user = {
|
||||||
stats: stats,
|
stats,
|
||||||
contributor: { level: 1 },
|
contributor: { level: 1 },
|
||||||
purchased: { plan: { planId: 'foo-plan' } },
|
purchased: { plan: { planId: 'foo-plan' } },
|
||||||
flags: {tour: {intro: -2}},
|
flags: {tour: {intro: -2}},
|
||||||
habits: [{_id: 'habit'}],
|
habits: [{_id: 'habit'}],
|
||||||
dailys: [{_id: 'daily'}],
|
dailys: [{_id: 'daily'}],
|
||||||
todos: [{_id: 'todo'}],
|
todos: [{_id: 'todo'}],
|
||||||
rewards: [{_id: 'reward'}]
|
rewards: [{_id: 'reward'}],
|
||||||
};
|
};
|
||||||
|
|
||||||
data.user = user;
|
data.user = user;
|
||||||
@@ -264,7 +264,7 @@ describe('analyticsService', () => {
|
|||||||
.filteringPath(/httpapi.*user_properties%22%3A%7B%22Class%22%3A%22wizard%22%2C%22Experience%22%3A5%2C%22Gold%22%3A23%2C%22Health%22%3A10%2C%22Level%22%3A4%2C%22Mana%22%3A30%2C%22tutorialComplete%22%3Atrue%2C%22Number%20Of%20Tasks%22%3A%7B%22habits%22%3A1%2C%22dailys%22%3A1%2C%22todos%22%3A1%2C%22rewards%22%3A1%7D%2C%22contributorLevel%22%3A1%2C%22subscription%22%3A%22foo-plan%22%7D%2C%22.*/g, '');
|
.filteringPath(/httpapi.*user_properties%22%3A%7B%22Class%22%3A%22wizard%22%2C%22Experience%22%3A5%2C%22Gold%22%3A23%2C%22Health%22%3A10%2C%22Level%22%3A4%2C%22Mana%22%3A30%2C%22tutorialComplete%22%3Atrue%2C%22Number%20Of%20Tasks%22%3A%7B%22habits%22%3A1%2C%22dailys%22%3A1%2C%22todos%22%3A1%2C%22rewards%22%3A1%7D%2C%22contributorLevel%22%3A1%2C%22subscription%22%3A%22foo-plan%22%7D%2C%22.*/g, '');
|
||||||
|
|
||||||
return analyticsService.trackPurchase(data)
|
return analyticsService.trackPurchase(data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
amplitudeNock.done();
|
amplitudeNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -277,7 +277,7 @@ describe('analyticsService', () => {
|
|||||||
.reply(200, {status: 'OK'});
|
.reply(200, {status: 'OK'});
|
||||||
|
|
||||||
return analyticsService.trackPurchase(data)
|
return analyticsService.trackPurchase(data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
gaNock.done();
|
gaNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -290,7 +290,7 @@ describe('analyticsService', () => {
|
|||||||
.reply(200, {status: 'OK'});
|
.reply(200, {status: 'OK'});
|
||||||
|
|
||||||
return analyticsService.trackPurchase(data)
|
return analyticsService.trackPurchase(data)
|
||||||
.then((res) => {
|
.then(() => {
|
||||||
gaNock.done();
|
gaNock.done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ describe('Base model plugin', () => {
|
|||||||
|
|
||||||
it('can sanitize input objects', () => {
|
it('can sanitize input objects', () => {
|
||||||
baseModel(schema, {
|
baseModel(schema, {
|
||||||
noSet: ['noUpdateForMe']
|
noSet: ['noUpdateForMe'],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(schema.statics.sanitize).to.exist;
|
expect(schema.statics.sanitize).to.exist;
|
||||||
@@ -45,7 +45,7 @@ describe('Base model plugin', () => {
|
|||||||
|
|
||||||
it('accepts an array of additional fields to sanitize at runtime', () => {
|
it('accepts an array of additional fields to sanitize at runtime', () => {
|
||||||
baseModel(schema, {
|
baseModel(schema, {
|
||||||
noSet: ['noUpdateForMe']
|
noSet: ['noUpdateForMe'],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(schema.statics.sanitize).to.exist;
|
expect(schema.statics.sanitize).to.exist;
|
||||||
@@ -59,7 +59,7 @@ describe('Base model plugin', () => {
|
|||||||
|
|
||||||
it('can make fields private', () => {
|
it('can make fields private', () => {
|
||||||
baseModel(schema, {
|
baseModel(schema, {
|
||||||
private: ['amPrivate']
|
private: ['amPrivate'],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(schema.options.toJSON.transform).to.exist;
|
expect(schema.options.toJSON.transform).to.exist;
|
||||||
@@ -73,7 +73,7 @@ describe('Base model plugin', () => {
|
|||||||
it('accepts a further transform function for toJSON', () => {
|
it('accepts a further transform function for toJSON', () => {
|
||||||
let options = {
|
let options = {
|
||||||
private: ['amPrivate'],
|
private: ['amPrivate'],
|
||||||
toJSONTransform: sandbox.stub().returns(true)
|
toJSONTransform: sandbox.stub().returns(true),
|
||||||
};
|
};
|
||||||
|
|
||||||
baseModel(schema, options);
|
baseModel(schema, options);
|
||||||
@@ -88,7 +88,7 @@ describe('Base model plugin', () => {
|
|||||||
it('accepts a transform function for sanitize', () => {
|
it('accepts a transform function for sanitize', () => {
|
||||||
let options = {
|
let options = {
|
||||||
private: ['amPrivate'],
|
private: ['amPrivate'],
|
||||||
sanitizeTransform: sandbox.stub().returns(true)
|
sanitizeTransform: sandbox.stub().returns(true),
|
||||||
};
|
};
|
||||||
|
|
||||||
baseModel(schema, options);
|
baseModel(schema, options);
|
||||||
|
|||||||
@@ -11,8 +11,9 @@ describe('Build Manifest', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('throws an error in case the page does not exist', () => {
|
it('throws an error in case the page does not exist', () => {
|
||||||
let getManifestFilesFn = () => { getManifestFiles('strange name here') };
|
expect(() => {
|
||||||
expect(getManifestFilesFn).to.throw(Error);
|
getManifestFiles('strange name here');
|
||||||
|
}).to.throw(Error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
/* eslint-disable global-require */
|
||||||
import request from 'request';
|
import request from 'request';
|
||||||
import nconf from 'nconf';
|
import nconf from 'nconf';
|
||||||
import nodemailer from 'nodemailer';
|
import nodemailer from 'nodemailer';
|
||||||
@@ -14,21 +15,21 @@ function getUser () {
|
|||||||
},
|
},
|
||||||
facebook: {
|
facebook: {
|
||||||
emails: [{
|
emails: [{
|
||||||
value: 'email@facebook'
|
value: 'email@facebook',
|
||||||
}],
|
}],
|
||||||
displayName: 'fb display name',
|
displayName: 'fb display name',
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
profile: {
|
profile: {
|
||||||
name: 'profile name',
|
name: 'profile name',
|
||||||
},
|
},
|
||||||
preferences: {
|
preferences: {
|
||||||
emailNotifications: {
|
emailNotifications: {
|
||||||
unsubscribeFromAll: false
|
unsubscribeFromAll: false,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
describe('emails', () => {
|
describe('emails', () => {
|
||||||
let pathToEmailLib = '../../../../../website/src/libs/api-v3/email';
|
let pathToEmailLib = '../../../../../website/src/libs/api-v3/email';
|
||||||
@@ -63,7 +64,7 @@ describe('emails', () => {
|
|||||||
attachEmail.send();
|
attachEmail.send();
|
||||||
expect(sendMailSpy).to.be.calledOnce;
|
expect(sendMailSpy).to.be.calledOnce;
|
||||||
deferred.reject();
|
deferred.reject();
|
||||||
deferred.promise.catch((err) => {
|
deferred.promise.catch(() => {
|
||||||
expect(logger.error).to.be.calledOnce;
|
expect(logger.error).to.be.calledOnce;
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@@ -93,8 +94,8 @@ describe('emails', () => {
|
|||||||
let attachEmail = require(pathToEmailLib);
|
let attachEmail = require(pathToEmailLib);
|
||||||
let getUserInfo = attachEmail.getUserInfo;
|
let getUserInfo = attachEmail.getUserInfo;
|
||||||
let user = getUser();
|
let user = getUser();
|
||||||
delete user.profile['name'];
|
delete user.profile.name;
|
||||||
delete user.auth['local'];
|
delete user.auth.local;
|
||||||
|
|
||||||
let data = getUserInfo(user, ['name', 'email', '_id', 'canSend']);
|
let data = getUserInfo(user, ['name', 'email', '_id', 'canSend']);
|
||||||
|
|
||||||
@@ -108,9 +109,9 @@ describe('emails', () => {
|
|||||||
let attachEmail = require(pathToEmailLib);
|
let attachEmail = require(pathToEmailLib);
|
||||||
let getUserInfo = attachEmail.getUserInfo;
|
let getUserInfo = attachEmail.getUserInfo;
|
||||||
let user = getUser();
|
let user = getUser();
|
||||||
delete user.profile['name'];
|
delete user.profile.name;
|
||||||
delete user.auth.local['email']
|
delete user.auth.local.email;
|
||||||
delete user.auth['facebook'];
|
delete user.auth.facebook;
|
||||||
|
|
||||||
let data = getUserInfo(user, ['name', 'email', '_id', 'canSend']);
|
let data = getUserInfo(user, ['name', 'email', '_id', 'canSend']);
|
||||||
|
|
||||||
@@ -148,8 +149,8 @@ describe('emails', () => {
|
|||||||
to: sinon.match((value) => {
|
to: sinon.match((value) => {
|
||||||
return Array.isArray(value) && value[0].name === mailingInfo.name;
|
return Array.isArray(value) && value[0].name === mailingInfo.name;
|
||||||
}, 'matches mailing info array'),
|
}, 'matches mailing info array'),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -180,8 +181,8 @@ describe('emails', () => {
|
|||||||
data: {
|
data: {
|
||||||
emailType: sinon.match.same(emailType),
|
emailType: sinon.match.same(emailType),
|
||||||
to: sinon.match(val => val[0]._id === mailingInfo._id),
|
to: sinon.match(val => val[0]._id === mailingInfo._id),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -204,13 +205,12 @@ describe('emails', () => {
|
|||||||
return value[0].name === 'BASE_URL';
|
return value[0].name === 'BASE_URL';
|
||||||
}, 'matches variables'),
|
}, 'matches variables'),
|
||||||
personalVariables: sinon.match((value) => {
|
personalVariables: sinon.match((value) => {
|
||||||
return (value[0].rcpt === mailingInfo.email
|
return value[0].rcpt === mailingInfo.email &&
|
||||||
&& value[0].vars[0].name === 'RECIPIENT_NAME'
|
value[0].vars[0].name === 'RECIPIENT_NAME' &&
|
||||||
&& value[0].vars[1].name === 'RECIPIENT_UNSUB_URL'
|
value[0].vars[1].name === 'RECIPIENT_UNSUB_URL';
|
||||||
);
|
|
||||||
}, 'matches personal variables'),
|
}, 'matches personal variables'),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ describe('i18n', () => {
|
|||||||
describe('localePath', () => {
|
describe('localePath', () => {
|
||||||
it('is an absolute path to common/locales/', () => {
|
it('is an absolute path to common/locales/', () => {
|
||||||
expect(localePath).to.match(/.*\/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';
|
import { sendTaskWebhook } from '../../../../../website/src/libs/api-v3/webhook';
|
||||||
|
|
||||||
describe('webhooks', () => {
|
describe('webhooks', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
sandbox.stub(request, 'post');
|
sandbox.stub(request, 'post');
|
||||||
});
|
});
|
||||||
@@ -15,12 +14,12 @@ describe('webhooks', () => {
|
|||||||
let task = {
|
let task = {
|
||||||
details: { _id: 'task-id' },
|
details: { _id: 'task-id' },
|
||||||
delta: 1.4,
|
delta: 1.4,
|
||||||
direction: 'up'
|
direction: 'up',
|
||||||
};
|
};
|
||||||
|
|
||||||
let data = {
|
let data = {
|
||||||
task: task,
|
task,
|
||||||
user: { _id: 'user-id' }
|
user: { _id: 'user-id' },
|
||||||
};
|
};
|
||||||
|
|
||||||
it('does not send if no webhook endpoints exist', () => {
|
it('does not send if no webhook endpoints exist', () => {
|
||||||
@@ -37,8 +36,8 @@ describe('webhooks', () => {
|
|||||||
sort: 0,
|
sort: 0,
|
||||||
id: 'some-id',
|
id: 'some-id',
|
||||||
enabled: false,
|
enabled: false,
|
||||||
url: 'http://example.org/endpoint'
|
url: 'http://example.org/endpoint',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
sendTaskWebhook(webhooks, data);
|
sendTaskWebhook(webhooks, data);
|
||||||
@@ -52,8 +51,8 @@ describe('webhooks', () => {
|
|||||||
sort: 0,
|
sort: 0,
|
||||||
id: 'some-id',
|
id: 'some-id',
|
||||||
enabled: true,
|
enabled: true,
|
||||||
url: 'http://malformedurl/endpoint'
|
url: 'http://malformedurl/endpoint',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
sendTaskWebhook(webhooks, data);
|
sendTaskWebhook(webhooks, data);
|
||||||
@@ -67,8 +66,8 @@ describe('webhooks', () => {
|
|||||||
sort: 0,
|
sort: 0,
|
||||||
id: 'some-id',
|
id: 'some-id',
|
||||||
enabled: true,
|
enabled: true,
|
||||||
url: 'http://example.org/endpoint'
|
url: 'http://example.org/endpoint',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
sendTaskWebhook(webhooks, data);
|
sendTaskWebhook(webhooks, data);
|
||||||
@@ -81,10 +80,10 @@ describe('webhooks', () => {
|
|||||||
task: { _id: 'task-id' },
|
task: { _id: 'task-id' },
|
||||||
delta: 1.4,
|
delta: 1.4,
|
||||||
user: {
|
user: {
|
||||||
_id: 'user-id'
|
_id: 'user-id',
|
||||||
}
|
|
||||||
},
|
},
|
||||||
json: true
|
},
|
||||||
|
json: true,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -94,14 +93,14 @@ describe('webhooks', () => {
|
|||||||
sort: 0,
|
sort: 0,
|
||||||
id: 'some-id',
|
id: 'some-id',
|
||||||
enabled: true,
|
enabled: true,
|
||||||
url: 'http://example.org/endpoint'
|
url: 'http://example.org/endpoint',
|
||||||
},
|
},
|
||||||
'second-webhook': {
|
'second-webhook': {
|
||||||
sort: 1,
|
sort: 1,
|
||||||
id: 'second-webhook',
|
id: 'second-webhook',
|
||||||
enabled: true,
|
enabled: true,
|
||||||
url: 'http://example.com/2/endpoint'
|
url: 'http://example.com/2/endpoint',
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
sendTaskWebhook(webhooks, data);
|
sendTaskWebhook(webhooks, data);
|
||||||
@@ -114,10 +113,10 @@ describe('webhooks', () => {
|
|||||||
task: { _id: 'task-id' },
|
task: { _id: 'task-id' },
|
||||||
delta: 1.4,
|
delta: 1.4,
|
||||||
user: {
|
user: {
|
||||||
_id: 'user-id'
|
_id: 'user-id',
|
||||||
}
|
|
||||||
},
|
},
|
||||||
json: true
|
},
|
||||||
|
json: true,
|
||||||
});
|
});
|
||||||
expect(request.post).to.be.calledWith({
|
expect(request.post).to.be.calledWith({
|
||||||
url: 'http://example.com/2/endpoint',
|
url: 'http://example.com/2/endpoint',
|
||||||
@@ -126,10 +125,10 @@ describe('webhooks', () => {
|
|||||||
task: { _id: 'task-id' },
|
task: { _id: 'task-id' },
|
||||||
delta: 1.4,
|
delta: 1.4,
|
||||||
user: {
|
user: {
|
||||||
_id: 'user-id'
|
_id: 'user-id',
|
||||||
}
|
|
||||||
},
|
},
|
||||||
json: true
|
},
|
||||||
|
json: true,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
|
/* eslint-disable global-require */
|
||||||
import {
|
import {
|
||||||
generateRes,
|
generateRes,
|
||||||
generateReq,
|
generateReq,
|
||||||
generateNext,
|
generateNext,
|
||||||
} from '../../../../helpers/api-unit.helper';
|
} 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';
|
import nconf from 'nconf';
|
||||||
|
|
||||||
describe('analytics middleware', function() {
|
describe('analytics middleware', () => {
|
||||||
let res, req, next;
|
let res, req, next;
|
||||||
let pathToAnalyticsMiddleware = '../../../../../website/src/middlewares/api-v3/analytics';
|
let pathToAnalyticsMiddleware = '../../../../../website/src/middlewares/api-v3/analytics';
|
||||||
|
|
||||||
@@ -23,7 +24,7 @@ describe('analytics middleware', function() {
|
|||||||
delete require.cache[require.resolve(pathToAnalyticsMiddleware)];
|
delete require.cache[require.resolve(pathToAnalyticsMiddleware)];
|
||||||
});
|
});
|
||||||
|
|
||||||
it('attaches analytics object res.locals', function() {
|
it('attaches analytics object res.locals', () => {
|
||||||
let attachAnalytics = require(pathToAnalyticsMiddleware);
|
let attachAnalytics = require(pathToAnalyticsMiddleware);
|
||||||
|
|
||||||
attachAnalytics(req, res, next);
|
attachAnalytics(req, res, next);
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ describe('errorHandler', () => {
|
|||||||
error: 'BadRequest',
|
error: 'BadRequest',
|
||||||
message: 'Invalid request parameters.',
|
message: 'Invalid request parameters.',
|
||||||
errors: [
|
errors: [
|
||||||
{param: error[0].param, value: error[0].value, message: error[0].msg}
|
{ param: error[0].param, value: error[0].value, message: error[0].msg },
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -142,8 +142,8 @@ describe('errorHandler', () => {
|
|||||||
error: 'BadRequest',
|
error: 'BadRequest',
|
||||||
message: 'User validation failed.',
|
message: 'User validation failed.',
|
||||||
errors: [
|
errors: [
|
||||||
{path: 'auth.local.email', message: 'Invalid email.', value: 'not an email'}
|
{ path: 'auth.local.email', message: 'Invalid email.', value: 'not an email' },
|
||||||
]
|
],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,13 @@ import getUserLanguage from '../../../../../website/src/middlewares/api-v3/getUs
|
|||||||
import { i18n } from '../../../../../common';
|
import { i18n } from '../../../../../common';
|
||||||
import Q from 'q';
|
import Q from 'q';
|
||||||
import { model as User } from '../../../../../website/src/models/user';
|
import { model as User } from '../../../../../website/src/models/user';
|
||||||
import { translations } from '../../../../../website/src/libs/api-v3/i18n';
|
|
||||||
import accepts from 'accepts';
|
|
||||||
|
|
||||||
describe('getUserLanguage', () => {
|
describe('getUserLanguage', () => {
|
||||||
let res, req, next;
|
let res, req, next;
|
||||||
|
|
||||||
let checkResT = (req) => {
|
let checkResT = (resToCheck) => {
|
||||||
expect(res.t).to.be.a('function');
|
expect(resToCheck.t).to.be.a('function');
|
||||||
expect(res.t('help')).to.equal(i18n.t('help', req.language));
|
expect(resToCheck.t('help')).to.equal(i18n.t('help', req.language));
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -32,7 +30,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, next);
|
getUserLanguage(req, res, next);
|
||||||
expect(req.language).to.equal('es');
|
expect(req.language).to.equal('es');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('falls back to english if the query parameter language does not exists', () => {
|
it('falls back to english if the query parameter language does not exists', () => {
|
||||||
@@ -42,7 +40,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, next);
|
getUserLanguage(req, res, next);
|
||||||
expect(req.language).to.equal('en');
|
expect(req.language).to.equal('en');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('uses query even if the request includes a user and session', () => {
|
it('uses query even if the request includes a user and session', () => {
|
||||||
@@ -59,12 +57,12 @@ describe('getUserLanguage', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
req.session = {
|
req.session = {
|
||||||
userId: 123
|
userId: 123,
|
||||||
};
|
};
|
||||||
|
|
||||||
getUserLanguage(req, res, next);
|
getUserLanguage(req, res, next);
|
||||||
expect(req.language).to.equal('es');
|
expect(req.language).to.equal('es');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -80,7 +78,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, next);
|
getUserLanguage(req, res, next);
|
||||||
expect(req.language).to.equal('it');
|
expect(req.language).to.equal('it');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('falls back to english if the user preferred language is not avalaible', (done) => {
|
it('falls back to english if the user preferred language is not avalaible', (done) => {
|
||||||
@@ -94,7 +92,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('en');
|
expect(req.language).to.equal('en');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -109,12 +107,12 @@ describe('getUserLanguage', () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
req.session = {
|
req.session = {
|
||||||
userId: 123
|
userId: 123,
|
||||||
};
|
};
|
||||||
|
|
||||||
getUserLanguage(req, res, next);
|
getUserLanguage(req, res, next);
|
||||||
expect(req.language).to.equal('it');
|
expect(req.language).to.equal('it');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -125,18 +123,18 @@ describe('getUserLanguage', () => {
|
|||||||
return Q.resolve({
|
return Q.resolve({
|
||||||
preferences: {
|
preferences: {
|
||||||
language: 'it',
|
language: 'it',
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
req.session = {
|
req.session = {
|
||||||
userId: 123
|
userId: 123,
|
||||||
};
|
};
|
||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('it');
|
expect(req.language).to.equal('it');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -148,7 +146,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('pt');
|
expect(req.language).to.equal('pt');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -158,7 +156,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('he');
|
expect(req.language).to.equal('he');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -168,7 +166,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('he');
|
expect(req.language).to.equal('he');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -178,7 +176,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('fr');
|
expect(req.language).to.equal('fr');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -188,7 +186,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('fr');
|
expect(req.language).to.equal('fr');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -198,7 +196,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('es');
|
expect(req.language).to.equal('es');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -208,7 +206,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('es_419');
|
expect(req.language).to.equal('es_419');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -218,7 +216,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('es_419');
|
expect(req.language).to.equal('es_419');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -228,7 +226,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('zh_TW');
|
expect(req.language).to.equal('zh_TW');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -238,7 +236,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('en');
|
expect(req.language).to.equal('en');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -248,7 +246,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('en');
|
expect(req.language).to.equal('en');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -258,7 +256,7 @@ describe('getUserLanguage', () => {
|
|||||||
|
|
||||||
getUserLanguage(req, res, () => {
|
getUserLanguage(req, res, () => {
|
||||||
expect(req.language).to.equal('en');
|
expect(req.language).to.equal('en');
|
||||||
checkResT(req);
|
checkResT(res);
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import {
|
|||||||
generateReq,
|
generateReq,
|
||||||
generateNext,
|
generateNext,
|
||||||
} from '../../../../helpers/api-unit.helper';
|
} from '../../../../helpers/api-unit.helper';
|
||||||
import responseMiddleware from '../../../../../website/src/middlewares/api-v3/response'
|
import responseMiddleware from '../../../../../website/src/middlewares/api-v3/response';
|
||||||
|
|
||||||
describe('response middleware', function() {
|
describe('response middleware', () => {
|
||||||
let res, req, next;
|
let res, req, next;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -15,13 +15,13 @@ describe('response middleware', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('attaches respond method to res', function() {
|
it('attaches respond method to res', () => {
|
||||||
responseMiddleware(req, res, next);
|
responseMiddleware(req, res, next);
|
||||||
|
|
||||||
expect(res.respond).to.exist;
|
expect(res.respond).to.exist;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be used to respond to requests', function() {
|
it('can be used to respond to requests', () => {
|
||||||
responseMiddleware(req, res, next);
|
responseMiddleware(req, res, next);
|
||||||
res.respond(200, {field: 1});
|
res.respond(200, {field: 1});
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ describe('response middleware', function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('treats status >= 400 as failures', function() {
|
it('treats status >= 400 as failures', () => {
|
||||||
responseMiddleware(req, res, next);
|
responseMiddleware(req, res, next);
|
||||||
res.respond(403, {field: 1});
|
res.respond(403, {field: 1});
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import express from 'express';
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
const CONTROLLERS_PATH = path.join(__dirname, '/../../controllers/api-v3/');
|
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
|
fs
|
||||||
.readdirSync(CONTROLLERS_PATH)
|
.readdirSync(CONTROLLERS_PATH)
|
||||||
|
|||||||
Reference in New Issue
Block a user