ResolvingAThreadTests.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import { ObjectId } from '../../../app/js/mongodb.js'
  2. import { expect } from 'chai'
  3. import * as ChatClient from './helpers/ChatClient.js'
  4. import * as ChatApp from './helpers/ChatApp.js'
  5. describe('Resolving a thread', async function () {
  6. const projectId = ObjectId().toString()
  7. const userId = ObjectId().toString()
  8. before(async function () {
  9. await ChatApp.ensureRunning()
  10. })
  11. describe('with a resolved thread', async function () {
  12. const threadId = ObjectId().toString()
  13. const content = 'resolved message'
  14. before(async function () {
  15. const { response } = await ChatClient.sendMessage(
  16. projectId,
  17. threadId,
  18. userId,
  19. content
  20. )
  21. expect(response.statusCode).to.equal(201)
  22. const { response: response2 } = await ChatClient.resolveThread(
  23. projectId,
  24. threadId,
  25. userId
  26. )
  27. expect(response2.statusCode).to.equal(204)
  28. })
  29. it('should then list the thread as resolved', async function () {
  30. const { response, body: threads } = await ChatClient.getThreads(projectId)
  31. expect(response.statusCode).to.equal(200)
  32. expect(threads[threadId].resolved).to.equal(true)
  33. expect(threads[threadId].resolved_by_user_id).to.equal(userId)
  34. const resolvedAt = new Date(threads[threadId].resolved_at)
  35. expect(new Date() - resolvedAt).to.be.below(1000)
  36. })
  37. })
  38. describe('when a thread is not resolved', async function () {
  39. const threadId = ObjectId().toString()
  40. const content = 'open message'
  41. before(async function () {
  42. const { response } = await ChatClient.sendMessage(
  43. projectId,
  44. threadId,
  45. userId,
  46. content
  47. )
  48. expect(response.statusCode).to.equal(201)
  49. })
  50. it('should not list the thread as resolved', async function () {
  51. const { response, body: threads } = await ChatClient.getThreads(projectId)
  52. expect(response.statusCode).to.equal(200)
  53. expect(threads[threadId].resolved).to.be.undefined
  54. })
  55. })
  56. describe('when a thread is resolved then reopened', async function () {
  57. const threadId = ObjectId().toString()
  58. const content = 'resolved message'
  59. before(async function () {
  60. const { response } = await ChatClient.sendMessage(
  61. projectId,
  62. threadId,
  63. userId,
  64. content
  65. )
  66. expect(response.statusCode).to.equal(201)
  67. const { response: response2 } = await ChatClient.resolveThread(
  68. projectId,
  69. threadId,
  70. userId
  71. )
  72. expect(response2.statusCode).to.equal(204)
  73. const { response: response3 } = await ChatClient.reopenThread(
  74. projectId,
  75. threadId
  76. )
  77. expect(response3.statusCode).to.equal(204)
  78. })
  79. it('should not list the thread as resolved', async function () {
  80. const { response, body: threads } = await ChatClient.getThreads(projectId)
  81. expect(response.statusCode).to.equal(200)
  82. expect(threads[threadId].resolved).to.be.undefined
  83. })
  84. })
  85. })