GettingMessagesTests.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /* eslint-disable
  2. max-len,
  3. no-unused-vars,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS102: Remove unnecessary code created because of implicit returns
  10. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  11. */
  12. const { ObjectId } = require('../../../app/js/mongodb')
  13. const { expect } = require('chai')
  14. const async = require('async')
  15. const crypto = require('crypto')
  16. const ChatClient = require('./helpers/ChatClient')
  17. const ChatApp = require('./helpers/ChatApp')
  18. describe('Getting messages', function () {
  19. before(function (done) {
  20. this.user_id1 = ObjectId().toString()
  21. this.user_id2 = ObjectId().toString()
  22. this.content1 = 'foo bar'
  23. this.content2 = 'hello world'
  24. return ChatApp.ensureRunning(done)
  25. })
  26. describe('globally', function () {
  27. before(function (done) {
  28. this.project_id = ObjectId().toString()
  29. return async.series(
  30. [
  31. cb =>
  32. ChatClient.sendGlobalMessage(
  33. this.project_id,
  34. this.user_id1,
  35. this.content1,
  36. cb
  37. ),
  38. cb =>
  39. ChatClient.sendGlobalMessage(
  40. this.project_id,
  41. this.user_id2,
  42. this.content2,
  43. cb
  44. ),
  45. ],
  46. done
  47. )
  48. })
  49. return it('should contain the messages and populated users when getting the messages', function (done) {
  50. return ChatClient.getGlobalMessages(
  51. this.project_id,
  52. (error, response, messages) => {
  53. if (error) return done(error)
  54. expect(messages.length).to.equal(2)
  55. messages.reverse()
  56. expect(messages[0].content).to.equal(this.content1)
  57. expect(messages[0].user_id).to.equal(this.user_id1)
  58. expect(messages[1].content).to.equal(this.content2)
  59. expect(messages[1].user_id).to.equal(this.user_id2)
  60. return done()
  61. }
  62. )
  63. })
  64. })
  65. return describe('from all the threads', function () {
  66. before(function (done) {
  67. this.project_id = ObjectId().toString()
  68. this.thread_id1 = ObjectId().toString()
  69. this.thread_id2 = ObjectId().toString()
  70. return async.series(
  71. [
  72. cb =>
  73. ChatClient.sendMessage(
  74. this.project_id,
  75. this.thread_id1,
  76. this.user_id1,
  77. 'one',
  78. cb
  79. ),
  80. cb =>
  81. ChatClient.sendMessage(
  82. this.project_id,
  83. this.thread_id2,
  84. this.user_id2,
  85. 'two',
  86. cb
  87. ),
  88. cb =>
  89. ChatClient.sendMessage(
  90. this.project_id,
  91. this.thread_id1,
  92. this.user_id1,
  93. 'three',
  94. cb
  95. ),
  96. cb =>
  97. ChatClient.sendMessage(
  98. this.project_id,
  99. this.thread_id2,
  100. this.user_id2,
  101. 'four',
  102. cb
  103. ),
  104. ],
  105. done
  106. )
  107. })
  108. return it('should contain a dictionary of threads with messages with populated users', function (done) {
  109. return ChatClient.getThreads(
  110. this.project_id,
  111. (error, response, threads) => {
  112. if (error) return done(error)
  113. expect(Object.keys(threads).length).to.equal(2)
  114. const thread1 = threads[this.thread_id1]
  115. expect(thread1.messages.length).to.equal(2)
  116. const thread2 = threads[this.thread_id2]
  117. expect(thread2.messages.length).to.equal(2)
  118. expect(thread1.messages[0].content).to.equal('one')
  119. expect(thread1.messages[0].user_id).to.equal(this.user_id1)
  120. expect(thread1.messages[1].content).to.equal('three')
  121. expect(thread1.messages[1].user_id).to.equal(this.user_id1)
  122. expect(thread2.messages[0].content).to.equal('two')
  123. expect(thread2.messages[0].user_id).to.equal(this.user_id2)
  124. expect(thread2.messages[1].content).to.equal('four')
  125. expect(thread2.messages[1].user_id).to.equal(this.user_id2)
  126. return done()
  127. }
  128. )
  129. })
  130. })
  131. })