EditingAMessageTests.js 1.6 KB

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