diff --git a/test/api/v3/integration/chat/GET-chat.test.js b/test/api/v3/integration/chat/GET-chat.test.js index edaca2ca2d..cb1e0996e6 100644 --- a/test/api/v3/integration/chat/GET-chat.test.js +++ b/test/api/v3/integration/chat/GET-chat.test.js @@ -7,69 +7,55 @@ 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, { - name: 'test group', - type: 'guild', - privacy: 'public', - }, { - chat: [ - 'Hello', - 'Welcome to the Guild', - ], - }); - }) - .then((createdGroup) => { - group = createdGroup; + before(async () => { + let leader = await generateUser({balance: 2}); + + group = await generateGroup(leader, { + name: 'test group', + type: 'guild', + privacy: 'public', + }, { + chat: [ + 'Hello', + 'Welcome to the Guild', + ], }); }); - 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, { - name: 'test group', - type: 'guild', - privacy: 'private', - }, { - chat: [ - 'Hello', - 'Welcome to the Guild', - ], - }); - }) - .then((createdGroup) => { - group = createdGroup; + before(async () => { + let leader = await generateUser({balance: 2}); + + group = await generateGroup(leader, { + name: 'test group', + type: 'guild', + privacy: 'private', + }, { + chat: [ + 'Hello', + 'Welcome to the Guild', + ], }); }); - 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'), diff --git a/test/api/v3/integration/chat/POST-chat.flag.test.js b/test/api/v3/integration/chat/POST-chat.flag.test.js index 3a0d494272..b71d462e5a 100644 --- a/test/api/v3/integration/chat/POST-chat.flag.test.js +++ b/test/api/v3/integration/chat/POST-chat.flag.test.js @@ -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;