DeletingAMessageTests.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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('Deleting 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. before(async function () {
  14. const { response } = await ChatClient.sendMessage(
  15. projectId,
  16. threadId,
  17. userId,
  18. 'first message'
  19. )
  20. expect(response.statusCode).to.equal(201)
  21. const { response: response2, body: message } =
  22. await ChatClient.sendMessage(
  23. projectId,
  24. threadId,
  25. userId,
  26. 'deleted message'
  27. )
  28. expect(response2.statusCode).to.equal(201)
  29. const { response: response3 } = await ChatClient.deleteMessage(
  30. projectId,
  31. threadId,
  32. message.id
  33. )
  34. expect(response3.statusCode).to.equal(204)
  35. })
  36. it('should then remove the message from the threads', async function () {
  37. const { response, body: threads } = await ChatClient.getThreads(projectId)
  38. expect(response.statusCode).to.equal(200)
  39. expect(threads[threadId].messages.length).to.equal(1)
  40. })
  41. })
  42. })