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

View File

@@ -7,19 +7,17 @@ import {
describe('GET /groups/:groupId/chat', () => {
let user;
before(() => {
return generateUser().then((generatedUser) => {
user = generatedUser;
});
before(async () => {
user = await generateUser();
});
context('public Guild', () => {
let group;
before(() => {
return generateUser({balance: 2})
.then((generatedLeader) => {
return generateGroup(generatedLeader, {
before(async () => {
let leader = await generateUser({balance: 2});
group = await generateGroup(leader, {
name: 'test group',
type: 'guild',
privacy: 'public',
@@ -29,27 +27,22 @@ describe('GET /groups/:groupId/chat', () => {
'Welcome to the Guild',
],
});
})
.then((createdGroup) => {
group = createdGroup;
});
});
it('returns Guild chat', () => {
return user.get(`/groups/${group._id}/chat`)
.then((getChat) => {
expect(getChat).to.eql(group.chat);
});
it('returns Guild chat', async () => {
let chat = await user.get(`/groups/${group._id}/chat`);
expect(chat).to.eql(group.chat);
});
});
context('private Guild', () => {
let group;
before(() => {
return generateUser({balance: 2})
.then((generatedLeader) => {
return generateGroup(generatedLeader, {
before(async () => {
let leader = await generateUser({balance: 2});
group = await generateGroup(leader, {
name: 'test group',
type: 'guild',
privacy: 'private',
@@ -59,17 +52,10 @@ describe('GET /groups/:groupId/chat', () => {
'Welcome to the Guild',
],
});
})
.then((createdGroup) => {
group = createdGroup;
});
});
it('returns error if user is not member of requested private group', () => {
return expect(
user.get(`/groups/${group._id}/chat`)
)
.to.eventually.be.rejected.and.eql({
it('returns error if user is not member of requested private group', async () => {
await expect(user.get(`/groups/${group._id}/chat`)).to.eventually.be.rejected.and.eql({
code: 404,
error: 'NotFound',
message: t('groupNotFound'),

View File

@@ -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;