ResolvingAThreadTests.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // TODO: This file was created by bulk-decaffeinate.
  2. // Fix any style issues and re-enable lint.
  3. /*
  4. * decaffeinate suggestions:
  5. * DS102: Remove unnecessary code created because of implicit returns
  6. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  7. */
  8. const { ObjectId } = require('../../../app/js/mongodb')
  9. const { expect } = require('chai')
  10. const ChatClient = require('./helpers/ChatClient')
  11. const ChatApp = require('./helpers/ChatApp')
  12. describe('Resolving a thread', function () {
  13. before(function (done) {
  14. this.project_id = ObjectId().toString()
  15. this.user_id = ObjectId().toString()
  16. return ChatApp.ensureRunning(done)
  17. })
  18. describe('with a resolved thread', function () {
  19. before(function (done) {
  20. this.thread_id = ObjectId().toString()
  21. this.content = 'resolved message'
  22. return ChatClient.sendMessage(
  23. this.project_id,
  24. this.thread_id,
  25. this.user_id,
  26. this.content,
  27. (error, response, body) => {
  28. expect(error).to.be.null
  29. expect(response.statusCode).to.equal(201)
  30. return ChatClient.resolveThread(
  31. this.project_id,
  32. this.thread_id,
  33. this.user_id,
  34. (error, response, body) => {
  35. expect(error).to.be.null
  36. expect(response.statusCode).to.equal(204)
  37. return done()
  38. }
  39. )
  40. }
  41. )
  42. })
  43. return it('should then list the thread as resolved', function (done) {
  44. return ChatClient.getThreads(
  45. this.project_id,
  46. (error, response, threads) => {
  47. expect(error).to.be.null
  48. expect(response.statusCode).to.equal(200)
  49. expect(threads[this.thread_id].resolved).to.equal(true)
  50. expect(threads[this.thread_id].resolved_by_user_id).to.equal(
  51. this.user_id
  52. )
  53. const resolvedAt = new Date(threads[this.thread_id].resolved_at)
  54. expect(new Date() - resolvedAt).to.be.below(1000)
  55. return done()
  56. }
  57. )
  58. })
  59. })
  60. describe('when a thread is not resolved', function () {
  61. before(function (done) {
  62. this.thread_id = ObjectId().toString()
  63. this.content = 'open message'
  64. return ChatClient.sendMessage(
  65. this.project_id,
  66. this.thread_id,
  67. this.user_id,
  68. this.content,
  69. (error, response, body) => {
  70. expect(error).to.be.null
  71. expect(response.statusCode).to.equal(201)
  72. return done()
  73. }
  74. )
  75. })
  76. return it('should not list the thread as resolved', function (done) {
  77. return ChatClient.getThreads(
  78. this.project_id,
  79. (error, response, threads) => {
  80. expect(error).to.be.null
  81. expect(response.statusCode).to.equal(200)
  82. expect(threads[this.thread_id].resolved).to.be.undefined
  83. return done()
  84. }
  85. )
  86. })
  87. })
  88. return describe('when a thread is resolved then reopened', function () {
  89. before(function (done) {
  90. this.thread_id = ObjectId().toString()
  91. this.content = 'resolved message'
  92. return ChatClient.sendMessage(
  93. this.project_id,
  94. this.thread_id,
  95. this.user_id,
  96. this.content,
  97. (error, response, body) => {
  98. expect(error).to.be.null
  99. expect(response.statusCode).to.equal(201)
  100. return ChatClient.resolveThread(
  101. this.project_id,
  102. this.thread_id,
  103. this.user_id,
  104. (error, response, body) => {
  105. expect(error).to.be.null
  106. expect(response.statusCode).to.equal(204)
  107. return ChatClient.reopenThread(
  108. this.project_id,
  109. this.thread_id,
  110. (error, response, body) => {
  111. expect(error).to.be.null
  112. expect(response.statusCode).to.equal(204)
  113. return done()
  114. }
  115. )
  116. }
  117. )
  118. }
  119. )
  120. })
  121. return it('should not list the thread as resolved', function (done) {
  122. return ChatClient.getThreads(
  123. this.project_id,
  124. (error, response, threads) => {
  125. expect(error).to.be.null
  126. expect(response.statusCode).to.equal(200)
  127. expect(threads[this.thread_id].resolved).to.be.undefined
  128. return done()
  129. }
  130. )
  131. })
  132. })
  133. })