2020-08-19 08:00:01 -04:00
|
|
|
const { ObjectId } = require('../../../app/js/mongodb')
|
2018-12-20 14:14:11 -05:00
|
|
|
const { expect } = require('chai')
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2018-12-20 14:14:11 -05:00
|
|
|
const ChatClient = require('./helpers/ChatClient')
|
|
|
|
const ChatApp = require('./helpers/ChatApp')
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
describe('Editing a message', async function () {
|
2022-01-10 04:50:25 -05:00
|
|
|
const projectId = ObjectId().toString()
|
|
|
|
const userId = ObjectId().toString()
|
|
|
|
const threadId = ObjectId().toString()
|
2022-01-10 04:29:32 -05:00
|
|
|
before(async function () {
|
|
|
|
await ChatApp.ensureRunning()
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
describe('in a thread', async function () {
|
2022-01-10 04:50:25 -05:00
|
|
|
const content = 'thread message'
|
|
|
|
const newContent = 'updated thread message'
|
2022-01-10 04:29:32 -05:00
|
|
|
before(async function () {
|
|
|
|
const { response, body: message } = await ChatClient.sendMessage(
|
2022-01-10 04:50:25 -05:00
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
userId,
|
|
|
|
content
|
2018-12-20 14:14:11 -05:00
|
|
|
)
|
2022-01-10 04:29:32 -05:00
|
|
|
expect(response.statusCode).to.equal(201)
|
2022-01-10 04:50:25 -05:00
|
|
|
expect(message.id).to.exist
|
|
|
|
expect(message.content).to.equal(content)
|
|
|
|
const { response: response2 } = await ChatClient.editMessage(
|
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
message.id,
|
|
|
|
newContent
|
|
|
|
)
|
2022-01-10 04:29:32 -05:00
|
|
|
expect(response2.statusCode).to.equal(204)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should then list the updated message in the threads', async function () {
|
2022-01-10 04:50:25 -05:00
|
|
|
const { response, body: threads } = await ChatClient.getThreads(projectId)
|
2022-01-10 04:29:32 -05:00
|
|
|
expect(response.statusCode).to.equal(200)
|
2022-01-10 04:50:25 -05:00
|
|
|
expect(threads[threadId].messages.length).to.equal(1)
|
|
|
|
expect(threads[threadId].messages[0].content).to.equal(newContent)
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|