ResolvingAThreadTests.js 4.4 KB

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