EditingAMessageTests.js 1.4 KB

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