EditingAMessageTests.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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('Editing a message', function () {
  6. before(function (done) {
  7. this.project_id = ObjectId().toString()
  8. this.user_id = ObjectId().toString()
  9. this.thread_id = ObjectId().toString()
  10. ChatApp.ensureRunning(done)
  11. })
  12. describe('in a thread', function () {
  13. before(function (done) {
  14. this.content = 'thread message'
  15. this.new_content = 'updated thread message'
  16. ChatClient.sendMessage(
  17. this.project_id,
  18. this.thread_id,
  19. this.user_id,
  20. this.content,
  21. (error, response, message) => {
  22. this.message = message
  23. expect(error).to.be.null
  24. expect(response.statusCode).to.equal(201)
  25. expect(this.message.id).to.exist
  26. expect(this.message.content).to.equal(this.content)
  27. ChatClient.editMessage(
  28. this.project_id,
  29. this.thread_id,
  30. this.message.id,
  31. this.new_content,
  32. (error, response, newMessage) => {
  33. this.new_message = newMessage
  34. expect(error).to.be.null
  35. expect(response.statusCode).to.equal(204)
  36. done()
  37. }
  38. )
  39. }
  40. )
  41. })
  42. it('should then list the updated message in the threads', function (done) {
  43. ChatClient.getThreads(this.project_id, (error, response, threads) => {
  44. expect(error).to.be.null
  45. expect(response.statusCode).to.equal(200)
  46. expect(threads[this.thread_id].messages.length).to.equal(1)
  47. expect(threads[this.thread_id].messages[0].content).to.equal(
  48. this.new_content
  49. )
  50. done()
  51. })
  52. })
  53. })
  54. })