EditorRealTimeControllerTests.coffee 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. SandboxedModule = require('sandboxed-module')
  2. sinon = require('sinon')
  3. require('chai').should()
  4. modulePath = require('path').join __dirname, '../../../../app/js/Features/Editor/EditorRealTimeController'
  5. describe "EditorRealTimeController", ->
  6. beforeEach ->
  7. @rclient =
  8. publish: sinon.stub()
  9. @EditorRealTimeController = SandboxedModule.require modulePath, requires:
  10. "../../infrastructure/RedisWrapper":
  11. client: () => @rclient
  12. "../../infrastructure/Server" : io: @io = {}
  13. "settings-sharelatex":{redis:{}}
  14. "crypto": @crypto = { randomBytes: sinon.stub().withArgs(4).returns(Buffer.from([0x1, 0x2, 0x3, 0x4])) }
  15. "os": @os = {hostname: sinon.stub().returns("somehost")}
  16. @room_id = "room-id"
  17. @message = "message-to-editor"
  18. @payload = ["argument one", 42]
  19. describe "emitToRoom", ->
  20. beforeEach ->
  21. @message_id = "web:somehost:01020304-0"
  22. @EditorRealTimeController.emitToRoom(@room_id, @message, @payload...)
  23. it "should publish the message to redis", ->
  24. @rclient.publish
  25. .calledWith("editor-events", JSON.stringify(
  26. room_id: @room_id,
  27. message: @message
  28. payload: @payload
  29. _id: @message_id
  30. ))
  31. .should.equal true
  32. describe "emitToAll", ->
  33. beforeEach ->
  34. @EditorRealTimeController.emitToRoom = sinon.stub()
  35. @EditorRealTimeController.emitToAll @message, @payload...
  36. it "should emit to the room 'all'", ->
  37. @EditorRealTimeController.emitToRoom
  38. .calledWith("all", @message, @payload...)
  39. .should.equal true