tests(api): Add async to every it, before and beforeEach in v2 tests

This commit is contained in:
Blade Barringer
2016-01-01 10:32:28 -06:00
parent 23aaf78167
commit 69c5192f70
28 changed files with 186 additions and 186 deletions
+12 -12
View File
@@ -10,13 +10,13 @@ import { find } from 'lodash';
describe('DELETE /user', () => {
let user;
beforeEach(() => {
beforeEach(async () => {
return generateUser().then((usr) => {
user = usr;
});
});
it('deletes the user', () => {
it('deletes the user', async () => {
return expect(user.del('/user').then((fetchedUser) => {
return checkExistence('users', user._id);
})).to.eventually.eql(false);
@@ -29,7 +29,7 @@ describe('DELETE /user', () => {
context('last member of a party', () => {
let party;
beforeEach(() => {
beforeEach(async () => {
return generateGroup(user, {
type: 'party',
privacy: 'private'
@@ -38,7 +38,7 @@ describe('DELETE /user', () => {
});
});
it('deletes party when user is the only member', () => {
it('deletes party when user is the only member', async () => {
return expect(user.del('/user').then((result) => {
return checkExistence('groups', party._id);
})).to.eventually.eql(false);
@@ -48,7 +48,7 @@ describe('DELETE /user', () => {
context('last member of a private guild', () => {
let guild;
beforeEach(() => {
beforeEach(async () => {
return generateGroup(user, {
type: 'guild',
privacy: 'private'
@@ -57,7 +57,7 @@ describe('DELETE /user', () => {
});
});
it('deletes guild when user is the only member', () => {
it('deletes guild when user is the only member', async () => {
return expect(user.del('/user').then((result) => {
return checkExistence('groups', guild._id);
})).to.eventually.eql(false);
@@ -67,7 +67,7 @@ describe('DELETE /user', () => {
context('groups user is leader of', () => {
let group, oldLeader, newLeader;
beforeEach(() => {
beforeEach(async () => {
return createAndPopulateGroup({
groupDetails: {
type: 'guild',
@@ -81,7 +81,7 @@ describe('DELETE /user', () => {
});
});
it('chooses new group leader for any group user was the leader of', () => {
it('chooses new group leader for any group user was the leader of', async () => {
return oldLeader.del('/user').then((res) => {
return newLeader.get(`/groups/${group._id}`);
}).then((guild) => {
@@ -94,7 +94,7 @@ describe('DELETE /user', () => {
context('groups user is a part of', () => {
let group1, group2, userToDelete, otherUser;
beforeEach(() => {
beforeEach(async () => {
return generateUser({
balance: 10,
}).then((user) => {
@@ -122,7 +122,7 @@ describe('DELETE /user', () => {
});
});
it('removes user from all groups user was a part of', () => {
it('removes user from all groups user was a part of', async () => {
return userToDelete.del('/user').then((res) => {
return otherUser.get(`/groups/${group1._id}`);
}).then((fetchedGroup1) => {
@@ -145,7 +145,7 @@ describe('DELETE /user', () => {
context('pending invitation to group', () => {
let group, userToDelete, otherUser;
beforeEach(() => {
beforeEach(async () => {
return createAndPopulateGroup({
groupDetails: {
type: 'guild',
@@ -160,7 +160,7 @@ describe('DELETE /user', () => {
});
});
it('removes invitations from groups', () => {
it('removes invitations from groups', async () => {
return userToDelete.del('/user').then((res) => {
return otherUser.get(`/groups/${group._id}`);
}).then((fetchedGroup) => {
+4 -4
View File
@@ -5,24 +5,24 @@ import {
describe('GET /user', () => {
let user;
before(async () => {
before(async async () => {
let usr = await generateUser();
user = await usr.get('/user');
});
it('gets the user object', () => {
it('gets the user object', async () => {
expect(user._id).to.eql(user._id);
expect(user.auth.local.username).to.eql(user.auth.local.username);
expect(user.todos).to.eql(user.todos);
expect(user.items).to.eql(user.items);
});
it('does not include password information', () => {
it('does not include password information', async () => {
expect(user.auth.local.hashed_password).to.not.exist
expect(user.auth.local.salt).to.not.exist
});
it('does not include api token', () => {
it('does not include api token', async () => {
expect(user.apiToken).to.not.exist
});
});
+2 -2
View File
@@ -5,13 +5,13 @@ import {
describe('GET /user/tags', () => {
let user;
beforeEach(() => {
beforeEach(async () => {
return generateUser().then((usr) => {
user = usr;
});
});
it('gets the user\'s tags', () => {
it('gets the user\'s tags', async () => {
return expect(user.get('/user/tags'))
.to.eventually.eql(user.tags);
});
+3 -3
View File
@@ -6,18 +6,18 @@ import {
describe('GET /user/tags/id', () => {
let user;
beforeEach(() => {
beforeEach(async () => {
return generateUser().then((usr) => {
user = usr;
});
});
it('gets a user\'s tag by id', () => {
it('gets a user\'s tag by id', async () => {
return expect(user.get('/user/tags/' + user.tags[0].id))
.to.eventually.eql(user.tags[0]);
});
it('fails for non-existent tags', () => {
it('fails for non-existent tags', async () => {
return expect(user.get('/user/tags/not-an-id'))
.to.eventually.be.rejected.and.eql({
code: 404,
+4 -4
View File
@@ -8,14 +8,14 @@ import { each } from 'lodash';
describe('PUT /user', () => {
let user;
beforeEach(() => {
beforeEach(async () => {
return generateUser().then((usr) => {
user = usr;
});
});
context('allowed operations', () => {
it('updates the user', () => {
it('updates the user', async () => {
return user.put('/user', {
'profile.name' : 'Frodo',
'preferences.costume': true,
@@ -40,7 +40,7 @@ describe('PUT /user', () => {
};
each(protectedOperations, (data, testName) => {
it(`does not allow updating ${testName}`, () => {
it(`does not allow updating ${testName}`, async () => {
let errorText = [];
each(data, (value, operation) => {
errorText.push(t('messageUserOperationProtected', { operation: operation }));
@@ -59,7 +59,7 @@ describe('PUT /user', () => {
};
each(protectedOperations, (data, testName) => {
it(`does not allow updating ${testName}`, () => {
it(`does not allow updating ${testName}`, async () => {
let errorText = [];
each(data, (value, operation) => {
errorText.push(t('messageUserOperationProtected', { operation: operation }));
@@ -6,7 +6,7 @@ import { each } from 'lodash';
describe('GET /user/anonymized', () => {
let user;
before(() => {
before(async () => {
return generateUser({
'inbox.messages' : {
'the-message-id' : {
@@ -47,24 +47,24 @@ describe('GET /user/anonymized', () => {
});
});
it('retains user id', () => {
it('retains user id', async () => {
expect(user._id).to.exist;
});
it('removes credentials and financial information', () => {
it('removes credentials and financial information', async () => {
expect(user.apiToken).to.not.exist;
expect(user.auth.local).to.not.exist;
expect(user.auth.facebook).to.not.exist;
expect(user.purchased.plan).to.not.exist;
});
it('removes profile information', () => {
it('removes profile information', async () => {
expect(user.profile).to.not.exist;
expect(user.contributor).to.not.exist;
expect(user.achievements.challenges).to.not.exist;
});
it('removes social information', () => {
it('removes social information', async () => {
expect(user.newMessages).to.not.exist;
expect(user.invitations).to.not.exist;
expect(user.items.special.nyeReceived).to.not.exist;
@@ -75,7 +75,7 @@ describe('GET /user/anonymized', () => {
});
});
it('anonymizes task info', () => {
it('anonymizes task info', async () => {
each(['habits', 'todos', 'dailys', 'rewards'], (tasks) => {
each(user[tasks], (task) => {
expect(task.text).to.eql('task text');
@@ -88,14 +88,14 @@ describe('GET /user/anonymized', () => {
});
});
it('anonymizes tags', () => {
it('anonymizes tags', async () => {
each(user.tags, (tag) => {
expect(tag.name).to.eql('tag');
expect(tag.challenge).to.eql('challenge');
});
});
it('removes webhooks', () => {
it('removes webhooks', async () => {
expect(user.webhooks).to.not.exist;
});
});
@@ -8,14 +8,14 @@ import { each } from 'lodash';
describe('POST /user/batch-update', () => {
let user;
beforeEach(() => {
beforeEach(async () => {
return generateUser().then((usr) => {
user = usr;
});
});
context('allowed operations', () => {
it('makes batch operations', () => {
it('makes batch operations', async () => {
let task;
return user.get('/user/tasks').then((tasks) => {
@@ -45,7 +45,7 @@ describe('POST /user/batch-update', () => {
each(protectedOperations, (operation, description) => {
it(`it sends back a 500 error for ${description} operation`, () => {
it(`it sends back a 500 error for ${description} operation`, async () => {
return expect(user.post('/user/batch-update', [
{ op: operation },
])).to.eventually.be.rejected.and.eql({
@@ -57,7 +57,7 @@ describe('POST /user/batch-update', () => {
});
context('unknown operations', () => {
it('sends back a 500 error', () => {
it('sends back a 500 error', async () => {
return expect(user.post('/user/batch-update', [
{op: 'aNotRealOperation'},
])).to.eventually.be.rejected.and.eql({
@@ -5,13 +5,13 @@ import {
describe('POST /user/pushDevice', () => {
let user;
beforeEach(() => {
beforeEach(async () => {
return generateUser().then((_user) => {
user = _user;
});
});
it('registers a device id', () => {
it('registers a device id', async () => {
return user.post('/user/pushDevice', {
regId: '123123',
type: 'android',
@@ -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}`);
+2 -2
View File
@@ -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);
+4 -4
View File
@@ -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 -7
View File
@@ -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 -6
View File
@@ -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}`, {