DeletingAMessageTests.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* eslint-disable
  2. max-len,
  3. */
  4. // TODO: This file was created by bulk-decaffeinate.
  5. // Fix any style issues and re-enable lint.
  6. /*
  7. * decaffeinate suggestions:
  8. * DS102: Remove unnecessary code created because of implicit returns
  9. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  10. */
  11. const { ObjectId } = require('../../../app/js/mongodb')
  12. const { expect } = require('chai')
  13. const ChatClient = require('./helpers/ChatClient')
  14. const ChatApp = require('./helpers/ChatApp')
  15. describe('Deleting a message', function () {
  16. before(function (done) {
  17. this.project_id = ObjectId().toString()
  18. this.user_id = ObjectId().toString()
  19. this.thread_id = ObjectId().toString()
  20. return ChatApp.ensureRunning(done)
  21. })
  22. return describe('in a thread', function () {
  23. before(function (done) {
  24. return ChatClient.sendMessage(
  25. this.project_id,
  26. this.thread_id,
  27. this.user_id,
  28. 'first message',
  29. (error, response, message) => {
  30. this.message = message
  31. expect(error).to.be.null
  32. expect(response.statusCode).to.equal(201)
  33. return ChatClient.sendMessage(
  34. this.project_id,
  35. this.thread_id,
  36. this.user_id,
  37. 'deleted message',
  38. (error, response, message1) => {
  39. this.message = message1
  40. expect(error).to.be.null
  41. expect(response.statusCode).to.equal(201)
  42. return ChatClient.deleteMessage(
  43. this.project_id,
  44. this.thread_id,
  45. this.message.id,
  46. (error, response, body) => {
  47. expect(error).to.be.null
  48. expect(response.statusCode).to.equal(204)
  49. return done()
  50. }
  51. )
  52. }
  53. )
  54. }
  55. )
  56. })
  57. return it('should then remove the message from the threads', function (done) {
  58. return ChatClient.getThreads(
  59. this.project_id,
  60. (error, response, threads) => {
  61. expect(error).to.be.null
  62. expect(response.statusCode).to.equal(200)
  63. expect(threads[this.thread_id].messages.length).to.equal(1)
  64. return done()
  65. }
  66. )
  67. })
  68. })
  69. })