lint: Correct linting errors in v3 tests

This commit is contained in:
Blade Barringer
2016-01-03 09:47:27 -06:00
parent 37916271e8
commit f80f41f764
26 changed files with 392 additions and 370 deletions

View File

@@ -25,9 +25,9 @@ describe('DELETE /tasks/:id', () => {
});
it('deletes a user\'s task', () => {
return user.del('/tasks/' + task._id)
return user.del(`/tasks/${task._id}`)
.then(() => {
return expect(user.get('/tasks/' + task._id)).to.eventually.be.rejected.and.eql({
return expect(user.get(`/tasks/${task._id}`)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('taskNotFound'),
@@ -54,7 +54,7 @@ describe('DELETE /tasks/:id', () => {
});
})
.then((task2) => {
return expect(user.del('/tasks/' + task2._id)).to.eventually.be.rejected.and.eql({
return expect(user.del(`/tasks/${task2._id}`)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('taskNotFound'),
@@ -63,5 +63,6 @@ describe('DELETE /tasks/:id', () => {
});
it('cannot delete active challenge tasks'); // TODO after challenges are implemented
it('remove a task from user.tasksOrder'); // TODO
});
});

View File

@@ -1,6 +1,5 @@
import {
generateUser,
translate as t,
} from '../../../../helpers/api-integration.helper';
import Q from 'q';
@@ -41,5 +40,5 @@ describe('GET /tasks', () => {
});
// TODO complete after task scoring is done
it('returns completed todos sorted by creation date if req.query.includeCompletedTodos is specified')
it('returns completed todos sorted by creation date if req.query.includeCompletedTodos is specified');
});

View File

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

View File

@@ -6,14 +6,14 @@ import {
describe('POST /tasks', () => {
let user;
before(() => {
before(async () => {
return generateUser().then((generatedUser) => {
user = generatedUser;
});
});
context('validates params', () => {
it('returns an error if req.body.type is absent', () => {
it('returns an error if req.body.type is absent', async () => {
return expect(user.post('/tasks', {
notType: 'habit',
})).to.eventually.be.rejected.and.eql({
@@ -23,7 +23,7 @@ describe('POST /tasks', () => {
});
});
it('returns an error if req.body.type is not valid', () => {
it('returns an error if req.body.type is not valid', async () => {
return expect(user.post('/tasks', {
type: 'habitF',
})).to.eventually.be.rejected.and.eql({
@@ -33,7 +33,7 @@ describe('POST /tasks', () => {
});
});
it('returns an error if req.body.text is absent', () => {
it('returns an error if req.body.text is absent', async () => {
return expect(user.post('/tasks', {
type: 'habit',
})).to.eventually.be.rejected.and.eql({
@@ -43,19 +43,19 @@ describe('POST /tasks', () => {
});
});
it('automatically sets "task.userId" to user\'s uuid', () => {
return user.post('/tasks', {
it('automatically sets "task.userId" to user\'s uuid', async () => {
let task = await user.post('/tasks', {
text: 'test habit',
type: 'habit',
}).then((task) => {
expect(task.userId).to.equal(user._id);
});
expect(task.userId).to.equal(user._id);
});
it(`ignores setting userId, history, createdAt,
updatedAt, challenge, completed, streak,
dateCompleted fields`, () => {
return user.post('/tasks', {
dateCompleted fields`, async () => {
let task = await user.post('/tasks', {
text: 'test daily',
type: 'daily',
userId: 123,
@@ -66,146 +66,170 @@ describe('POST /tasks', () => {
completed: true,
streak: 25,
dateCompleted: 'never',
}).then((task) => {
expect(task.userId).to.equal(user._id);
expect(task.history).to.eql([]);
expect(task.createdAt).not.to.equal('yesterday');
expect(task.updatedAt).not.to.equal('tomorrow');
expect(task.challenge).not.to.equal('no');
expect(task.completed).to.equal(false);
expect(task.streak).to.equal(0);
expect(task.streak).not.to.equal('never');
});
expect(task.userId).to.equal(user._id);
expect(task.history).to.eql([]);
expect(task.createdAt).not.to.equal('yesterday');
expect(task.updatedAt).not.to.equal('tomorrow');
expect(task.challenge).not.to.equal('no');
expect(task.completed).to.equal(false);
expect(task.streak).to.equal(0);
expect(task.streak).not.to.equal('never');
});
it('ignores invalid fields', () => {
return user.post('/tasks', {
it('ignores invalid fields', async () => {
let task = await user.post('/tasks', {
text: 'test daily',
type: 'daily',
notValid: true,
}).then((task) => {
expect(task).not.to.have.property('notValid');
});
expect(task).not.to.have.property('notValid');
});
});
context('habits', () => {
it('creates a habit', () => {
return user.post('/tasks', {
it('creates a habit', async () => {
let task = await user.post('/tasks', {
text: 'test habit',
type: 'habit',
up: false,
down: true,
notes: 1976,
}).then((task) => {
expect(task.userId).to.equal(user._id);
expect(task.text).to.eql('test habit');
expect(task.notes).to.eql('1976');
expect(task.type).to.eql('habit');
expect(task.up).to.eql(false);
expect(task.down).to.eql(true);
});
expect(task.userId).to.equal(user._id);
expect(task.text).to.eql('test habit');
expect(task.notes).to.eql('1976');
expect(task.type).to.eql('habit');
expect(task.up).to.eql(false);
expect(task.down).to.eql(true);
});
it('defaults to setting up and down to true', () => {
return user.post('/tasks', {
it('defaults to setting up and down to true', async () => {
let task = await user.post('/tasks', {
text: 'test habit',
type: 'habit',
notes: 1976,
}).then((task) => {
expect(task.up).to.eql(true);
expect(task.down).to.eql(true);
});
expect(task.up).to.eql(true);
expect(task.down).to.eql(true);
});
it('cannot create checklists', () => {
return user.post('/tasks', {
it('cannot create checklists', async () => {
let task = await user.post('/tasks', {
text: 'test habit',
type: 'habit',
checklist: [
{_id: 123, completed: false, text: 'checklist'},
],
}).then((task) => {
expect(task).not.to.have.property('checklist');
});
expect(task).not.to.have.property('checklist');
});
});
context('todos', () => {
it('creates a todo', () => {
return user.post('/tasks', {
it('creates a todo', async () => {
let task = await user.post('/tasks', {
text: 'test todo',
type: 'todo',
notes: 1976,
}).then((task) => {
expect(task.userId).to.equal(user._id);
expect(task.text).to.eql('test todo');
expect(task.notes).to.eql('1976');
expect(task.type).to.eql('todo');
});
expect(task.userId).to.equal(user._id);
expect(task.text).to.eql('test todo');
expect(task.notes).to.eql('1976');
expect(task.type).to.eql('todo');
});
it('can create checklists', () => {
return user.post('/tasks', {
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',
});
let updatedUser = await user.get('/user');
expect(updatedUser.tasksOrder.todos[0]).to.eql(task._id);
expect(updatedUser.tasksOrder.todos.length).to.eql(originalTodosOrderLen + 1);
});
it('can create checklists', async () => {
let task = await user.post('/tasks', {
text: 'test todo',
type: 'todo',
checklist: [
{completed: false, text: 'checklist'},
],
}).then((task) => {
expect(task.checklist).to.be.an('array');
expect(task.checklist.length).to.eql(1);
expect(task.checklist[0]).to.be.an('object');
expect(task.checklist[0].text).to.eql('checklist');
expect(task.checklist[0].completed).to.eql(false);
expect(task.checklist[0]._id).to.be.a('string');
});
expect(task.checklist).to.be.an('array');
expect(task.checklist.length).to.eql(1);
expect(task.checklist[0]).to.be.an('object');
expect(task.checklist[0].text).to.eql('checklist');
expect(task.checklist[0].completed).to.eql(false);
expect(task.checklist[0]._id).to.be.a('string');
});
});
context('dailys', () => {
it('creates a daily', () => {
it('creates a daily', async () => {
let now = new Date();
return user.post('/tasks', {
let task = await user.post('/tasks', {
text: 'test daily',
type: 'daily',
notes: 1976,
frequency: 'daily',
everyX: 5,
startDate: now,
}).then((task) => {
expect(task.userId).to.equal(user._id);
expect(task.text).to.eql('test daily');
expect(task.notes).to.eql('1976');
expect(task.type).to.eql('daily');
expect(task.frequency).to.eql('daily');
expect(task.everyX).to.eql(5);
expect(new Date(task.startDate)).to.eql(now);
});
expect(task.userId).to.equal(user._id);
expect(task.text).to.eql('test daily');
expect(task.notes).to.eql('1976');
expect(task.type).to.eql('daily');
expect(task.frequency).to.eql('daily');
expect(task.everyX).to.eql(5);
expect(new Date(task.startDate)).to.eql(now);
});
it('defaults to a weekly frequency, with every day set', () => {
return user.post('/tasks', {
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',
});
let updatedUser = await user.get('/user');
expect(updatedUser.tasksOrder.dailys[0]).to.eql(task._id);
expect(updatedUser.tasksOrder.dailys.length).to.eql(originalDailysOrderLen + 1);
});
it('defaults to a weekly frequency, with every day set', async () => {
let task = await user.post('/tasks', {
text: 'test daily',
type: 'daily',
}).then((task) => {
expect(task.frequency).to.eql('weekly');
expect(task.everyX).to.eql(1);
expect(task.repeat).to.eql({
m: true,
t: true,
w: true,
th: true,
f: true,
s: true,
su: true,
});
});
expect(task.frequency).to.eql('weekly');
expect(task.everyX).to.eql(1);
expect(task.repeat).to.eql({
m: true,
t: true,
w: true,
th: true,
f: true,
s: true,
su: true,
});
});
it('allows repeat field to be configured', () => {
return user.post('/tasks', {
it('allows repeat field to be configured', async () => {
let task = await user.post('/tasks', {
text: 'test daily',
type: 'daily',
repeat: {
@@ -213,93 +237,105 @@ describe('POST /tasks', () => {
w: false,
su: false,
},
}).then((task) => {
expect(task.repeat).to.eql({
m: false,
t: true,
w: false,
th: true,
f: true,
s: true,
su: false,
});
});
expect(task.repeat).to.eql({
m: false,
t: true,
w: false,
th: true,
f: true,
s: true,
su: false,
});
});
it('defaults startDate to today', () => {
it('defaults startDate to today', async () => {
let today = (new Date()).getDay();
return user.post('/tasks', {
let task = await user.post('/tasks', {
text: 'test daily',
type: 'daily',
}).then((task) => {
expect((new Date(task.startDate)).getDay()).to.eql(today);
});
expect((new Date(task.startDate)).getDay()).to.eql(today);
});
it('can create checklists', () => {
return user.post('/tasks', {
it('can create checklists', async () => {
let task = await user.post('/tasks', {
text: 'test daily',
type: 'daily',
checklist: [
{completed: false, text: 'checklist'},
],
}).then((task) => {
expect(task.checklist).to.be.an('array');
expect(task.checklist.length).to.eql(1);
expect(task.checklist[0]).to.be.an('object');
expect(task.checklist[0].text).to.eql('checklist');
expect(task.checklist[0].completed).to.eql(false);
expect(task.checklist[0]._id).to.be.a('string');
});
expect(task.checklist).to.be.an('array');
expect(task.checklist.length).to.eql(1);
expect(task.checklist[0]).to.be.an('object');
expect(task.checklist[0].text).to.eql('checklist');
expect(task.checklist[0].completed).to.eql(false);
expect(task.checklist[0]._id).to.be.a('string');
});
});
context('rewards', () => {
it('creates a reward', () => {
return user.post('/tasks', {
it('creates a reward', async () => {
let task = await user.post('/tasks', {
text: 'test reward',
type: 'reward',
notes: 1976,
value: 10,
}).then((task) => {
expect(task.userId).to.equal(user._id);
expect(task.text).to.eql('test reward');
expect(task.notes).to.eql('1976');
expect(task.type).to.eql('reward');
expect(task.value).to.eql(10);
});
expect(task.userId).to.equal(user._id);
expect(task.text).to.eql('test reward');
expect(task.notes).to.eql('1976');
expect(task.type).to.eql('reward');
expect(task.value).to.eql(10);
});
it('defaults to a 0 value', () => {
return user.post('/tasks', {
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',
});
let updatedUser = await user.get('/user');
expect(updatedUser.tasksOrder.rewards[0]).to.eql(task._id);
expect(updatedUser.tasksOrder.rewards.length).to.eql(originalRewardsOrderLen + 1);
});
it('defaults to a 0 value', async () => {
let task = await user.post('/tasks', {
text: 'test reward',
type: 'reward',
}).then((task) => {
expect(task.value).to.eql(0);
});
expect(task.value).to.eql(0);
});
it('requires value to be coerced into a number', () => {
return user.post('/tasks', {
it('requires value to be coerced into a number', async () => {
let task = await user.post('/tasks', {
text: 'test reward',
type: 'reward',
value: "10",
}).then((task) => {
expect(task.value).to.eql(10);
value: '10',
});
expect(task.value).to.eql(10);
});
it('cannot create checklists', () => {
return user.post('/tasks', {
it('cannot create checklists', async () => {
let task = await user.post('/tasks', {
text: 'test reward',
type: 'reward',
checklist: [
{_id: 123, completed: false, text: 'checklist'},
],
}).then((task) => {
expect(task).not.to.have.property('checklist');
});
expect(task).not.to.have.property('checklist');
});
});
});

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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