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-03-31 03:54:33 -04:00
|
|
|
let projectId, userId, threadId
|
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-03-31 03:54:33 -04:00
|
|
|
let messageId
|
|
|
|
beforeEach(async function () {
|
|
|
|
projectId = ObjectId().toString()
|
|
|
|
userId = ObjectId().toString()
|
|
|
|
threadId = ObjectId().toString()
|
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
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)
|
2022-03-31 03:54:33 -04:00
|
|
|
messageId = message.id
|
2022-01-10 04:29:32 -05:00
|
|
|
})
|
|
|
|
|
2022-03-31 03:54:33 -04:00
|
|
|
describe('without user', function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
const { response } = await ChatClient.editMessage(
|
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
messageId,
|
|
|
|
newContent
|
|
|
|
)
|
|
|
|
expect(response.statusCode).to.equal(204)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should then list the updated message in the threads', async function () {
|
|
|
|
const { response, body: threads } = await ChatClient.getThreads(
|
|
|
|
projectId
|
|
|
|
)
|
|
|
|
expect(response.statusCode).to.equal(200)
|
|
|
|
expect(threads[threadId].messages.length).to.equal(1)
|
|
|
|
expect(threads[threadId].messages[0].content).to.equal(newContent)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with the same user', function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
const { response } = await ChatClient.editMessageWithUser(
|
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
messageId,
|
|
|
|
userId,
|
|
|
|
newContent
|
|
|
|
)
|
|
|
|
expect(response.statusCode).to.equal(204)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should then list the updated message in the threads', async function () {
|
|
|
|
const { response, body: threads } = await ChatClient.getThreads(
|
|
|
|
projectId
|
|
|
|
)
|
|
|
|
expect(response.statusCode).to.equal(200)
|
|
|
|
expect(threads[threadId].messages.length).to.equal(1)
|
|
|
|
expect(threads[threadId].messages[0].content).to.equal(newContent)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('with another user', function () {
|
|
|
|
beforeEach(async function () {
|
|
|
|
const { response } = await ChatClient.editMessageWithUser(
|
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
messageId,
|
|
|
|
ObjectId(),
|
|
|
|
newContent
|
|
|
|
)
|
2022-03-31 05:23:22 -04:00
|
|
|
expect(response.statusCode).to.equal(404)
|
2022-03-31 03:54:33 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should then list the old message in the threads', async function () {
|
|
|
|
const { response, body: threads } = await ChatClient.getThreads(
|
|
|
|
projectId
|
|
|
|
)
|
|
|
|
expect(response.statusCode).to.equal(200)
|
|
|
|
expect(threads[threadId].messages.length).to.equal(1)
|
|
|
|
expect(threads[threadId].messages[0].content).to.equal(content)
|
|
|
|
})
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|