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('Deleting a message', async function () {
|
2023-10-17 08:48:51 -04:00
|
|
|
const projectId = new ObjectId().toString()
|
|
|
|
const userId = new ObjectId().toString()
|
|
|
|
const threadId = new ObjectId().toString()
|
2022-01-10 04:50:25 -05:00
|
|
|
|
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 () {
|
|
|
|
before(async function () {
|
2022-01-10 04:50:25 -05:00
|
|
|
const { response } = await ChatClient.sendMessage(
|
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
userId,
|
2022-01-10 04:29:32 -05:00
|
|
|
'first message'
|
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
|
|
|
const { response: response2, body: message } =
|
2022-01-10 04:29:32 -05:00
|
|
|
await ChatClient.sendMessage(
|
2022-01-10 04:50:25 -05:00
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
userId,
|
2022-01-10 04:29:32 -05:00
|
|
|
'deleted message'
|
|
|
|
)
|
|
|
|
expect(response2.statusCode).to.equal(201)
|
|
|
|
const { response: response3 } = await ChatClient.deleteMessage(
|
2022-01-10 04:50:25 -05:00
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
message.id
|
2022-01-10 04:29:32 -05:00
|
|
|
)
|
|
|
|
expect(response3.statusCode).to.equal(204)
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
it('should then remove the message from 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)
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|