tests(api): Add async to every it, before and beforeEach in v2 tests
This commit is contained in:
@@ -6,14 +6,14 @@ import {
|
||||
describe('DELETE /user/tasks/:id', () => {
|
||||
let user, task;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
return generateUser().then((_user) => {
|
||||
user = _user;
|
||||
task = user.todos[0];
|
||||
});
|
||||
});
|
||||
|
||||
it('deletes a task', () => {
|
||||
it('deletes a task', async () => {
|
||||
return expect(user.del(`/user/tasks/${task.id}`)
|
||||
.then((res) => {
|
||||
return user.get(`/user/tasks/${task.id}`);
|
||||
@@ -23,7 +23,7 @@ describe('DELETE /user/tasks/:id', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error if the task does not exist', () => {
|
||||
it('returns an error if the task does not exist', async () => {
|
||||
return expect(user.del('/user/tasks/task-that-does-not-exist'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
@@ -31,7 +31,7 @@ describe('DELETE /user/tasks/:id', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not delete another user\'s task', () => {
|
||||
it('does not delete another user\'s task', async () => {
|
||||
return expect(generateUser().then((otherUser) => {
|
||||
let otherUsersTask = otherUser.todos[0];
|
||||
return user.del(`/user/tasks/${otherUsersTask.id}`);
|
||||
|
||||
@@ -6,7 +6,7 @@ import {
|
||||
describe('GET /user/tasks/', () => {
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
return generateUser({
|
||||
dailys: [
|
||||
{text: 'daily', type: 'daily'},
|
||||
@@ -19,7 +19,7 @@ describe('GET /user/tasks/', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('gets all tasks', () => {
|
||||
it('gets all tasks', async () => {
|
||||
return user.get(`/user/tasks/`).then((tasks) => {
|
||||
expect(tasks).to.be.an('array');
|
||||
expect(tasks.length).to.be.greaterThan(3);
|
||||
|
||||
@@ -6,14 +6,14 @@ import {
|
||||
describe('GET /user/tasks/:id', () => {
|
||||
let user, task;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
return generateUser().then((_user) => {
|
||||
user = _user;
|
||||
task = user.todos[0];
|
||||
});
|
||||
});
|
||||
|
||||
it('gets a task', () => {
|
||||
it('gets a task', async () => {
|
||||
return user.get(`/user/tasks/${task.id}`).then((foundTask) => {
|
||||
expect(foundTask.id).to.eql(task.id);
|
||||
expect(foundTask.text).to.eql(task.text);
|
||||
@@ -23,7 +23,7 @@ describe('GET /user/tasks/:id', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error if the task does not exist', () => {
|
||||
it('returns an error if the task does not exist', async () => {
|
||||
return expect(user.get('/user/tasks/task-that-does-not-exist'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
@@ -31,7 +31,7 @@ describe('GET /user/tasks/:id', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not get another user\'s task', () => {
|
||||
it('does not get another user\'s task', async () => {
|
||||
return expect(generateUser().then((otherUser) => {
|
||||
let otherUsersTask = otherUser.todos[0];
|
||||
|
||||
|
||||
@@ -7,24 +7,24 @@ describe('POST /user/tasks', () => {
|
||||
|
||||
let user;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
return generateUser().then((_user) => {
|
||||
user = _user;
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a task', () => {
|
||||
it('creates a task', async () => {
|
||||
return user.post('/user/tasks').then((task) => {
|
||||
expect(task.id).to.exist;
|
||||
});
|
||||
});
|
||||
|
||||
it('creates a habit by default', () => {
|
||||
it('creates a habit by default', async () => {
|
||||
return expect(user.post('/user/tasks'))
|
||||
.to.eventually.have.property('type', 'habit');
|
||||
});
|
||||
|
||||
it('creates a task with specified values', () => {
|
||||
it('creates a task with specified values', async () => {
|
||||
return user.post('/user/tasks', {
|
||||
type: 'daily',
|
||||
text: 'My task',
|
||||
@@ -38,7 +38,7 @@ describe('POST /user/tasks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not create a task with an id that already exists', () => {
|
||||
it('does not create a task with an id that already exists', async () => {
|
||||
let todo = user.todos[0];
|
||||
|
||||
return expect(user.post('/user/tasks', {
|
||||
@@ -49,7 +49,7 @@ describe('POST /user/tasks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
xit('TODO: no error is thrown - throws a 500 validation error if invalid type is posted', () => {
|
||||
xit('TODO: no error is thrown - throws a 500 validation error if invalid type is posted', async () => {
|
||||
return expect(user.post('/user/tasks', {
|
||||
type: 'not-valid',
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
@@ -58,7 +58,7 @@ describe('POST /user/tasks', () => {
|
||||
});
|
||||
});
|
||||
|
||||
xit('TODO: no error is thrown - throws a 500 validation error if invalid data is posted', () => {
|
||||
xit('TODO: no error is thrown - throws a 500 validation error if invalid data is posted', async () => {
|
||||
return expect(user.post('/user/tasks', {
|
||||
frequency: 'not-valid',
|
||||
})).to.eventually.be.rejected.and.eql({
|
||||
|
||||
@@ -6,14 +6,14 @@ import {
|
||||
describe('PUT /user/tasks/:id', () => {
|
||||
let user, task;
|
||||
|
||||
beforeEach(() => {
|
||||
beforeEach(async () => {
|
||||
return generateUser().then((_user) => {
|
||||
user = _user;
|
||||
task = user.todos[0];
|
||||
});
|
||||
});
|
||||
|
||||
it('does not update the id of the task', () => {
|
||||
it('does not update the id of the task', async () => {
|
||||
return user.put(`/user/tasks/${task.id}`, {
|
||||
id: 'some-thing',
|
||||
}).then((updatedTask) => {
|
||||
@@ -22,7 +22,7 @@ describe('PUT /user/tasks/:id', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not update the type of the task', () => {
|
||||
it('does not update the type of the task', async () => {
|
||||
return user.put(`/user/tasks/${task.id}`, {
|
||||
type: 'habit',
|
||||
}).then((updatedTask) => {
|
||||
@@ -31,7 +31,7 @@ describe('PUT /user/tasks/:id', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('updates text, attribute, priority, value and notes', () => {
|
||||
it('updates text, attribute, priority, value and notes', async () => {
|
||||
return user.put(`/user/tasks/${task.id}`, {
|
||||
text: 'new text',
|
||||
notes: 'new notes',
|
||||
@@ -47,7 +47,7 @@ describe('PUT /user/tasks/:id', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns an error if the task does not exist', () => {
|
||||
it('returns an error if the task does not exist', async () => {
|
||||
return expect(user.put('/user/tasks/task-id-that-does-not-exist'))
|
||||
.to.eventually.be.rejected.and.eql({
|
||||
code: 404,
|
||||
@@ -55,7 +55,7 @@ describe('PUT /user/tasks/:id', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('does not update another user\'s task', () => {
|
||||
it('does not update another user\'s task', async () => {
|
||||
return expect(generateUser().then((otherUser) => {
|
||||
let otherUsersTask = otherUser.todos[0];
|
||||
return user.put(`/user/tasks/${otherUsersTask._id}`, {
|
||||
|
||||
Reference in New Issue
Block a user