tests(api): Convert GET and flag chat posts to use async/await

This commit is contained in:
Blade Barringer
2015-12-31 18:11:03 -06:00
parent 90cd322af5
commit 91e7b9eb32
2 changed files with 49 additions and 75 deletions
@@ -5,31 +5,19 @@ import {
import { find } from 'lodash';
describe('POST /chat/:chatId/flag', () => {
let user;
let group;
let testMessage = 'Test Message';
let user, group;
const TEST_MESSAGE = 'Test Message';
before(() => {
let groupName = 'Test Guild';
let groupType = 'guild';
let groupPrivacy = 'public';
return generateUser({balance: 1}).then((generatedUser) => {
user = generatedUser;
})
.then(() => {
return user.post('/groups', {
name: groupName,
type: groupType,
privacy: groupPrivacy,
});
})
.then((generatedGroup) => {
group = generatedGroup;
before(async () => {
user = await generateUser({balance: 1});
group = await user.post('/groups', {
name: 'Test Guild',
type: 'guild',
privacy: 'public',
});
});
it('Returns an error when chat message is not found', () => {
it('Returns an error when chat message is not found', async () => {
return expect(user.post(`/groups/${group._id}/chat/incorrectMessage/flag`))
.to.eventually.be.rejected.and.eql({
code: 404,
@@ -38,8 +26,8 @@ describe('POST /chat/:chatId/flag', () => {
});
});
it('Returns an error when user tries to flag their own message', () => {
return user.post(`/groups/${group._id}/chat`, { message: testMessage})
it('Returns an error when user tries to flag their own message', async () => {
return user.post(`/groups/${group._id}/chat`, { message: TEST_MESSAGE})
.then((result) => {
return expect(user.post(`/groups/${group._id}/chat/${result.message.id}/flag`))
.to.eventually.be.rejected.and.eql({
@@ -50,11 +38,11 @@ describe('POST /chat/:chatId/flag', () => {
});
});
it('Flags a chat', () => {
it('Flags a chat', async () => {
let message;
return generateUser().then((anotherUser) => {
return anotherUser.post(`/groups/${group._id}/chat`, { message: testMessage});
return anotherUser.post(`/groups/${group._id}/chat`, { message: TEST_MESSAGE});
})
.then((result) => {
message = result.message;
@@ -71,13 +59,13 @@ describe('POST /chat/:chatId/flag', () => {
});
});
it('Flags a chat with a higher flag acount when an admin flags the message', () => {
it('Flags a chat with a higher flag acount when an admin flags the message', async () => {
let secondUser;
let message;
return generateUser({'contributor.admin': true}).then((generatedUser) => {
secondUser = generatedUser;
return user.post(`/groups/${group._id}/chat`, { message: testMessage});
return user.post(`/groups/${group._id}/chat`, { message: TEST_MESSAGE});
})
.then((result) => {
message = result.message;
@@ -95,11 +83,11 @@ describe('POST /chat/:chatId/flag', () => {
});
});
it('Returns an error when user tries to flag a message that is already flagged', () => {
it('Returns an error when user tries to flag a message that is already flagged', async () => {
let message;
return generateUser().then((anotherUser) => {
return anotherUser.post(`/groups/${group._id}/chat`, { message: testMessage});
return anotherUser.post(`/groups/${group._id}/chat`, { message: TEST_MESSAGE});
})
.then((result) => {
message = result.message;