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 () {
|
|
|
|
before(async function () {
|
2018-12-20 14:14:11 -05:00
|
|
|
this.project_id = ObjectId().toString()
|
|
|
|
this.user_id = ObjectId().toString()
|
|
|
|
this.thread_id = ObjectId().toString()
|
2022-01-10 04:29:32 -05:00
|
|
|
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 () {
|
|
|
|
before(async function () {
|
2018-12-20 14:14:11 -05:00
|
|
|
this.content = 'thread message'
|
|
|
|
this.new_content = 'updated thread message'
|
2022-01-10 04:29:32 -05:00
|
|
|
const { response, body: message } = await ChatClient.sendMessage(
|
2018-12-20 14:14:11 -05:00
|
|
|
this.project_id,
|
|
|
|
this.thread_id,
|
|
|
|
this.user_id,
|
2022-01-10 04:29:32 -05:00
|
|
|
this.content
|
2018-12-20 14:14:11 -05:00
|
|
|
)
|
2022-01-10 04:29:32 -05:00
|
|
|
this.message = message
|
|
|
|
expect(response.statusCode).to.equal(201)
|
|
|
|
expect(this.message.id).to.exist
|
|
|
|
expect(this.message.content).to.equal(this.content)
|
|
|
|
const { response: response2, body: newMessage } =
|
|
|
|
await ChatClient.editMessage(
|
|
|
|
this.project_id,
|
|
|
|
this.thread_id,
|
|
|
|
this.message.id,
|
2022-01-07 05:41:23 -05:00
|
|
|
this.new_content
|
|
|
|
)
|
2022-01-10 04:29:32 -05:00
|
|
|
this.new_message = newMessage
|
|
|
|
expect(response2.statusCode).to.equal(204)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should then list the updated message in the threads', async function () {
|
|
|
|
const { response, body: threads } = await ChatClient.getThreads(
|
|
|
|
this.project_id
|
|
|
|
)
|
|
|
|
expect(response.statusCode).to.equal(200)
|
|
|
|
expect(threads[this.thread_id].messages.length).to.equal(1)
|
|
|
|
expect(threads[this.thread_id].messages[0].content).to.equal(
|
|
|
|
this.new_content
|
|
|
|
)
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|