2022-12-13 07:37:49 -05:00
|
|
|
import { ObjectId } from '../../../app/js/mongodb.js'
|
|
|
|
import { expect } from 'chai'
|
2017-01-04 08:51:08 -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-04 08:51:08 -05:00
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
describe('Resolving a thread', async function () {
|
2022-01-10 04:50:25 -05:00
|
|
|
const projectId = ObjectId().toString()
|
|
|
|
const userId = ObjectId().toString()
|
2022-01-10 04:29:32 -05:00
|
|
|
before(async function () {
|
|
|
|
await ChatApp.ensureRunning()
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
2018-01-29 07:01:26 -05:00
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
describe('with a resolved thread', async function () {
|
2022-01-10 04:50:25 -05:00
|
|
|
const threadId = ObjectId().toString()
|
|
|
|
const content = 'resolved message'
|
2022-01-10 04:29:32 -05:00
|
|
|
before(async function () {
|
|
|
|
const { response } = 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)
|
|
|
|
const { response: response2 } = await ChatClient.resolveThread(
|
2022-01-10 04:50:25 -05:00
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
userId
|
2022-01-10 04:29:32 -05:00
|
|
|
)
|
|
|
|
expect(response2.statusCode).to.equal(204)
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
2017-01-04 08:51:08 -05:00
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
it('should then list the thread as resolved', 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].resolved).to.equal(true)
|
|
|
|
expect(threads[threadId].resolved_by_user_id).to.equal(userId)
|
|
|
|
const resolvedAt = new Date(threads[threadId].resolved_at)
|
2022-01-10 04:29:32 -05:00
|
|
|
expect(new Date() - resolvedAt).to.be.below(1000)
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
describe('when a thread is not resolved', async function () {
|
2022-01-10 04:50:25 -05:00
|
|
|
const threadId = ObjectId().toString()
|
|
|
|
const content = 'open message'
|
2022-01-10 04:29:32 -05:00
|
|
|
before(async function () {
|
|
|
|
const { response } = 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)
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
it('should not list the thread as resolved', 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].resolved).to.be.undefined
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-01-10 04:29:32 -05:00
|
|
|
describe('when a thread is resolved then reopened', async function () {
|
2022-01-10 04:50:25 -05:00
|
|
|
const threadId = ObjectId().toString()
|
|
|
|
const content = 'resolved message'
|
2022-01-10 04:29:32 -05:00
|
|
|
before(async function () {
|
|
|
|
const { response } = 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)
|
|
|
|
const { response: response2 } = await ChatClient.resolveThread(
|
2022-01-10 04:50:25 -05:00
|
|
|
projectId,
|
|
|
|
threadId,
|
|
|
|
userId
|
2022-01-10 04:29:32 -05:00
|
|
|
)
|
|
|
|
expect(response2.statusCode).to.equal(204)
|
|
|
|
const { response: response3 } = await ChatClient.reopenThread(
|
2022-01-10 04:50:25 -05:00
|
|
|
projectId,
|
|
|
|
threadId
|
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 not list the thread as resolved', 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].resolved).to.be.undefined
|
2018-12-20 14:14:11 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|