ResolvingAThreadTests.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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', function () {
  6. before(function (done) {
  7. this.project_id = ObjectId().toString()
  8. this.user_id = ObjectId().toString()
  9. ChatApp.ensureRunning(done)
  10. })
  11. describe('with a resolved thread', function () {
  12. before(function (done) {
  13. this.thread_id = ObjectId().toString()
  14. this.content = 'resolved message'
  15. ChatClient.sendMessage(
  16. this.project_id,
  17. this.thread_id,
  18. this.user_id,
  19. this.content,
  20. (error, response, body) => {
  21. expect(error).to.be.null
  22. expect(response.statusCode).to.equal(201)
  23. ChatClient.resolveThread(
  24. this.project_id,
  25. this.thread_id,
  26. this.user_id,
  27. (error, response, body) => {
  28. expect(error).to.be.null
  29. expect(response.statusCode).to.equal(204)
  30. done()
  31. }
  32. )
  33. }
  34. )
  35. })
  36. it('should then list the thread as resolved', function (done) {
  37. ChatClient.getThreads(this.project_id, (error, response, threads) => {
  38. expect(error).to.be.null
  39. expect(response.statusCode).to.equal(200)
  40. expect(threads[this.thread_id].resolved).to.equal(true)
  41. expect(threads[this.thread_id].resolved_by_user_id).to.equal(
  42. this.user_id
  43. )
  44. const resolvedAt = new Date(threads[this.thread_id].resolved_at)
  45. expect(new Date() - resolvedAt).to.be.below(1000)
  46. done()
  47. })
  48. })
  49. })
  50. describe('when a thread is not resolved', function () {
  51. before(function (done) {
  52. this.thread_id = ObjectId().toString()
  53. this.content = 'open message'
  54. ChatClient.sendMessage(
  55. this.project_id,
  56. this.thread_id,
  57. this.user_id,
  58. this.content,
  59. (error, response, body) => {
  60. expect(error).to.be.null
  61. expect(response.statusCode).to.equal(201)
  62. done()
  63. }
  64. )
  65. })
  66. it('should not list the thread as resolved', function (done) {
  67. ChatClient.getThreads(this.project_id, (error, response, threads) => {
  68. expect(error).to.be.null
  69. expect(response.statusCode).to.equal(200)
  70. expect(threads[this.thread_id].resolved).to.be.undefined
  71. done()
  72. })
  73. })
  74. })
  75. describe('when a thread is resolved then reopened', function () {
  76. before(function (done) {
  77. this.thread_id = ObjectId().toString()
  78. this.content = 'resolved message'
  79. ChatClient.sendMessage(
  80. this.project_id,
  81. this.thread_id,
  82. this.user_id,
  83. this.content,
  84. (error, response, body) => {
  85. expect(error).to.be.null
  86. expect(response.statusCode).to.equal(201)
  87. ChatClient.resolveThread(
  88. this.project_id,
  89. this.thread_id,
  90. this.user_id,
  91. (error, response, body) => {
  92. expect(error).to.be.null
  93. expect(response.statusCode).to.equal(204)
  94. ChatClient.reopenThread(
  95. this.project_id,
  96. this.thread_id,
  97. (error, response, body) => {
  98. expect(error).to.be.null
  99. expect(response.statusCode).to.equal(204)
  100. done()
  101. }
  102. )
  103. }
  104. )
  105. }
  106. )
  107. })
  108. it('should not list the thread as resolved', function (done) {
  109. ChatClient.getThreads(this.project_id, (error, response, threads) => {
  110. expect(error).to.be.null
  111. expect(response.statusCode).to.equal(200)
  112. expect(threads[this.thread_id].resolved).to.be.undefined
  113. done()
  114. })
  115. })
  116. })
  117. })