EditingAMessageTests.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* eslint-disable
  2. camelcase,
  3. max-len,
  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 ChatClient = require('./helpers/ChatClient')
  15. const ChatApp = require('./helpers/ChatApp')
  16. describe('Editing a message', function () {
  17. before(function (done) {
  18. this.project_id = ObjectId().toString()
  19. this.user_id = ObjectId().toString()
  20. this.thread_id = ObjectId().toString()
  21. return ChatApp.ensureRunning(done)
  22. })
  23. return describe('in a thread', function () {
  24. before(function (done) {
  25. this.content = 'thread message'
  26. this.new_content = 'updated thread message'
  27. return ChatClient.sendMessage(
  28. this.project_id,
  29. this.thread_id,
  30. this.user_id,
  31. this.content,
  32. (error, response, message) => {
  33. this.message = message
  34. expect(error).to.be.null
  35. expect(response.statusCode).to.equal(201)
  36. expect(this.message.id).to.exist
  37. expect(this.message.content).to.equal(this.content)
  38. return ChatClient.editMessage(
  39. this.project_id,
  40. this.thread_id,
  41. this.message.id,
  42. this.new_content,
  43. (error, response, new_message) => {
  44. this.new_message = new_message
  45. expect(error).to.be.null
  46. expect(response.statusCode).to.equal(204)
  47. return done()
  48. }
  49. )
  50. }
  51. )
  52. })
  53. return it('should then list the updated message in the threads', function (done) {
  54. return ChatClient.getThreads(
  55. this.project_id,
  56. (error, response, threads) => {
  57. expect(error).to.be.null
  58. expect(response.statusCode).to.equal(200)
  59. expect(threads[this.thread_id].messages.length).to.equal(1)
  60. expect(threads[this.thread_id].messages[0].content).to.equal(
  61. this.new_content
  62. )
  63. return done()
  64. }
  65. )
  66. })
  67. })
  68. })