2014-07-04 08:05:55 -04:00
|
|
|
should = require('chai').should()
|
|
|
|
SandboxedModule = require('sandboxed-module')
|
|
|
|
assert = require('assert')
|
|
|
|
path = require('path')
|
|
|
|
sinon = require('sinon')
|
|
|
|
modulePath = path.join __dirname, "../../../../app/js/Features/Chat/ChatController"
|
|
|
|
expect = require("chai").expect
|
|
|
|
|
|
|
|
describe "ChatController", ->
|
|
|
|
|
|
|
|
beforeEach ->
|
|
|
|
|
|
|
|
@settings = {}
|
|
|
|
@ChatHandler =
|
|
|
|
sendMessage:sinon.stub()
|
|
|
|
getMessages:sinon.stub()
|
|
|
|
|
2014-07-04 08:20:30 -04:00
|
|
|
@EditorRealTimeController =
|
|
|
|
emitToRoom:sinon.stub().callsArgWith(3)
|
2014-07-04 08:05:55 -04:00
|
|
|
@ChatController = SandboxedModule.require modulePath, requires:
|
|
|
|
"settings-sharelatex":@settings
|
|
|
|
"logger-sharelatex": log:->
|
|
|
|
"./ChatHandler":@ChatHandler
|
2014-07-04 08:20:30 -04:00
|
|
|
"../Editor/EditorRealTimeController":@EditorRealTimeController
|
2014-07-04 08:05:55 -04:00
|
|
|
@query =
|
|
|
|
before:"some time"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
describe "sendMessage", ->
|
|
|
|
|
|
|
|
it "should tell the chat handler about the message", (done)->
|
|
|
|
@ChatHandler.sendMessage.callsArgWith(3)
|
|
|
|
@ChatController.sendMessage @project_id, @user_id, @messageContent, (err)=>
|
|
|
|
@ChatHandler.sendMessage.calledWith(@project_id, @user_id, @messageContent).should.equal true
|
|
|
|
done()
|
|
|
|
|
2014-07-04 08:20:30 -04:00
|
|
|
it "should tell the editor real time controller about the update with the data from the chat handler", (done)->
|
|
|
|
@chatMessage =
|
|
|
|
content:"hello world"
|
|
|
|
@ChatHandler.sendMessage.callsArgWith(3, null, @chatMessage)
|
|
|
|
@ChatController.sendMessage @project_id, @user_id, @messageContent, (err)=>
|
|
|
|
@EditorRealTimeController.emitToRoom.calledWith(@project_id, "new-chat-message", @chatMessage).should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
|
2014-07-04 08:05:55 -04:00
|
|
|
describe "getMessages", ->
|
|
|
|
|
|
|
|
it "should tell the chat handler about the request", (done)->
|
|
|
|
|
|
|
|
@ChatHandler.getMessages.callsArgWith(2)
|
|
|
|
@ChatController.getMessages @project_id, @query, (err)=>
|
|
|
|
@ChatHandler.getMessages.calledWith(@project_id, @query).should.equal true
|
|
|
|
done()
|
|
|
|
|