ResolvingAThreadTests.js 3.2 KB

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