EditorRealTimeControllerTests.coffee 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. @room_id = "room-id"
  15. @message = "message-to-editor"
  16. @payload = ["argument one", 42]
  17. describe "emitToRoom", ->
  18. beforeEach ->
  19. @EditorRealTimeController.emitToRoom(@room_id, @message, @payload...)
  20. it "should publish the message to redis", ->
  21. @rclient.publish
  22. .calledWith("editor-events", JSON.stringify(
  23. room_id: @room_id,
  24. message: @message
  25. payload: @payload
  26. ))
  27. .should.equal true
  28. describe "emitToAll", ->
  29. beforeEach ->
  30. @EditorRealTimeController.emitToRoom = sinon.stub()
  31. @EditorRealTimeController.emitToAll @message, @payload...
  32. it "should emit to the room 'all'", ->
  33. @EditorRealTimeController.emitToRoom
  34. .calledWith("all", @message, @payload...)
  35. .should.equal true