EditorRealTimeControllerTests.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* eslint-disable
  2. max-len,
  3. no-return-assign,
  4. */
  5. // TODO: This file was created by bulk-decaffeinate.
  6. // Fix any style issues and re-enable lint.
  7. /*
  8. * decaffeinate suggestions:
  9. * DS101: Remove unnecessary use of Array.from
  10. * DS102: Remove unnecessary code created because of implicit returns
  11. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  12. */
  13. const SandboxedModule = require('sandboxed-module')
  14. const sinon = require('sinon')
  15. require('chai').should()
  16. const modulePath = require('path').join(
  17. __dirname,
  18. '../../../../app/src/Features/Editor/EditorRealTimeController'
  19. )
  20. describe('EditorRealTimeController', function() {
  21. beforeEach(function() {
  22. this.rclient = { publish: sinon.stub() }
  23. this.EditorRealTimeController = SandboxedModule.require(modulePath, {
  24. globals: {
  25. console: console
  26. },
  27. requires: {
  28. '../../infrastructure/RedisWrapper': {
  29. client: () => this.rclient
  30. },
  31. '../../infrastructure/Server': {
  32. io: (this.io = {})
  33. },
  34. 'settings-sharelatex': { redis: {} },
  35. crypto: (this.crypto = {
  36. randomBytes: sinon
  37. .stub()
  38. .withArgs(4)
  39. .returns(Buffer.from([0x1, 0x2, 0x3, 0x4]))
  40. }),
  41. os: (this.os = { hostname: sinon.stub().returns('somehost') })
  42. }
  43. })
  44. this.room_id = 'room-id'
  45. this.message = 'message-to-editor'
  46. return (this.payload = ['argument one', 42])
  47. })
  48. describe('emitToRoom', function() {
  49. beforeEach(function() {
  50. this.message_id = 'web:somehost:01020304-0'
  51. return this.EditorRealTimeController.emitToRoom(
  52. this.room_id,
  53. this.message,
  54. ...Array.from(this.payload)
  55. )
  56. })
  57. it('should publish the message to redis', function() {
  58. return this.rclient.publish
  59. .calledWith(
  60. 'editor-events',
  61. JSON.stringify({
  62. room_id: this.room_id,
  63. message: this.message,
  64. payload: this.payload,
  65. _id: this.message_id
  66. })
  67. )
  68. .should.equal(true)
  69. })
  70. })
  71. describe('emitToAll', function() {
  72. beforeEach(function() {
  73. this.EditorRealTimeController.emitToRoom = sinon.stub()
  74. return this.EditorRealTimeController.emitToAll(
  75. this.message,
  76. ...Array.from(this.payload)
  77. )
  78. })
  79. it("should emit to the room 'all'", function() {
  80. return this.EditorRealTimeController.emitToRoom
  81. .calledWith('all', this.message, ...Array.from(this.payload))
  82. .should.equal(true)
  83. })
  84. })
  85. })