2022-12-13 12:37:49 +00:00
|
|
|
import { ObjectId } from '../../../app/js/mongodb.js'
|
|
|
|
import { expect } from 'chai'
|
2017-01-24 14:44:32 +00:00
|
|
|
|
2022-12-13 12:37:49 +00:00
|
|
|
import * as ChatClient from './helpers/ChatClient.js'
|
|
|
|
import * as ChatApp from './helpers/ChatApp.js'
|
2017-01-24 14:44:32 +00:00
|
|
|
|
2022-01-10 09:29:32 +00:00
|
|
|
describe('Editing a message', async function () {
|
2022-03-31 07:54:33 +00:00
|
|
|
let projectId, userId, threadId
|
2022-01-10 09:29:32 +00:00
|
|
|
before(async function () {
|
|
|
|
await ChatApp.ensureRunning()
|
2018-12-20 19:14:11 +00:00
|
|
|
})
|
2017-01-24 14:44:32 +00:00
|
|
|
|
2022-01-10 09:29:32 +00:00
|
|
|
describe('in a thread', async function () {
|
2022-01-10 09:50:25 +00:00
|
|
|
const content = 'thread message'
|
|
|
|
const newContent = 'updated thread message'
|
2022-03-31 07:54:33 +00:00
|
|
|
let messageId
|
|
|
|
beforeEach(async function () {
|
2023-10-17 12:48:51 +00:00
|
|
|
projectId = new ObjectId().toString()
|
|
|
|
userId = new ObjectId().toString()
|
|
|
|
threadId = new ObjectId().toString()
|
2022-03-31 07:54:33 +00:00
|
|
|
|
2022-01-10 09:29:32 +00:00
|
|
|
const { response, body: message } = await ChatClient.sendMessage(
|
2022-01-10 09:50:25 +00:00
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
userId,
|
|
|
|
content
|
2018-12-20 19:14:11 +00:00
|
|
|
)
|
2022-01-10 09:29:32 +00:00
|
|
|
expect(response.statusCode).to.equal(201)
|
2022-01-10 09:50:25 +00:00
|
|
|
expect(message.id).to.exist
|
|
|
|
expect(message.content).to.equal(content)
|
2022-03-31 07:54:33 +00:00
|
|
|
messageId = message.id
|
2022-01-10 09:29:32 +00:00
|
|
|
})
|
|
|
|
|
2022-03-31 07:54:33 +00: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,
|
2023-10-17 12:48:51 +00:00
|
|
|
new ObjectId(),
|
2022-03-31 07:54:33 +00:00
|
|
|
newContent
|
|
|
|
)
|
2022-03-31 09:23:22 +00:00
|
|
|
expect(response.statusCode).to.equal(404)
|
2022-03-31 07:54:33 +00: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 19:14:11 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|