2014-02-12 05:23:40 -05:00
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
sinon = require('sinon')
|
|
|
|
require('chai').should()
|
|
|
|
modulePath = require('path').join __dirname, '../../../../app/js/Features/Editor/EditorRealTimeController'
|
|
|
|
|
|
|
|
describe "EditorRealTimeController", ->
|
|
|
|
beforeEach ->
|
2017-05-04 10:22:54 -04:00
|
|
|
@rclient =
|
|
|
|
publish: sinon.stub()
|
2014-02-12 05:23:40 -05:00
|
|
|
@EditorRealTimeController = SandboxedModule.require modulePath, requires:
|
2018-06-01 10:16:27 -04:00
|
|
|
"../../infrastructure/RedisWrapper":
|
2017-05-04 10:22:54 -04:00
|
|
|
client: () => @rclient
|
2014-02-12 05:23:40 -05:00
|
|
|
"../../infrastructure/Server" : io: @io = {}
|
2016-03-09 07:51:19 -05:00
|
|
|
"settings-sharelatex":{redis:{}}
|
2018-06-01 10:16:27 -04:00
|
|
|
|
2014-02-12 05:23:40 -05:00
|
|
|
@room_id = "room-id"
|
|
|
|
@message = "message-to-editor"
|
|
|
|
@payload = ["argument one", 42]
|
|
|
|
|
|
|
|
describe "emitToRoom", ->
|
|
|
|
beforeEach ->
|
|
|
|
@EditorRealTimeController.emitToRoom(@room_id, @message, @payload...)
|
|
|
|
|
|
|
|
it "should publish the message to redis", ->
|
2017-05-04 10:22:54 -04:00
|
|
|
@rclient.publish
|
2014-02-12 05:23:40 -05:00
|
|
|
.calledWith("editor-events", JSON.stringify(
|
|
|
|
room_id: @room_id,
|
|
|
|
message: @message
|
|
|
|
payload: @payload
|
|
|
|
))
|
|
|
|
.should.equal true
|
|
|
|
|
|
|
|
describe "emitToAll", ->
|
|
|
|
beforeEach ->
|
|
|
|
@EditorRealTimeController.emitToRoom = sinon.stub()
|
|
|
|
@EditorRealTimeController.emitToAll @message, @payload...
|
|
|
|
|
|
|
|
it "should emit to the room 'all'", ->
|
|
|
|
@EditorRealTimeController.emitToRoom
|
|
|
|
.calledWith("all", @message, @payload...)
|
|
|
|
.should.equal true
|