2022-12-13 07:37:49 -05:00
|
|
|
import { ObjectId } from '../../../app/js/mongodb.js'
|
|
|
|
import { expect } from 'chai'
|
2017-01-24 09:44:32 -05:00
|
|
|
|
2022-12-13 07:37:49 -05:00
|
|
|
import * as ChatClient from './helpers/ChatClient.js'
|
|
|
|
import * as ChatApp from './helpers/ChatApp.js'
|
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 () {
|
2023-10-17 08:48:51 -04:00
|
|
|
projectId = new ObjectId().toString()
|
|
|
|
userId = new ObjectId().toString()
|
|
|
|
threadId = new ObjectId().toString()
|
2022-03-31 03:54:33 -04:00
|
|
|
|
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 () {
|
2024-03-25 06:51:40 -04:00
|
|
|
const { response, body: threads } =
|
|
|
|
await ChatClient.getThreads(projectId)
|
2022-03-31 03:54:33 -04:00
|
|
|
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 () {
|
2024-03-25 06:51:40 -04:00
|
|
|
const { response, body: threads } =
|
|
|
|
await ChatClient.getThreads(projectId)
|
2022-03-31 03:54:33 -04:00
|
|
|
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 08:48:51 -04:00
|
|
|
new ObjectId(),
|
2022-03-31 03:54:33 -04:00
|
|
|
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 () {
|
2024-03-25 06:51:40 -04:00
|
|
|
const { response, body: threads } =
|
|
|
|
await ChatClient.getThreads(projectId)
|
2022-03-31 03:54:33 -04:00
|
|
|
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
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|