ChatControllerTests.coffee 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. should = require('chai').should()
  2. SandboxedModule = require('sandboxed-module')
  3. assert = require('assert')
  4. path = require('path')
  5. sinon = require('sinon')
  6. modulePath = path.join __dirname, "../../../../app/js/Features/Chat/ChatController"
  7. expect = require("chai").expect
  8. describe "ChatController", ->
  9. beforeEach ->
  10. @settings = {}
  11. @ChatHandler =
  12. sendMessage:sinon.stub()
  13. getMessages:sinon.stub()
  14. @ChatController = SandboxedModule.require modulePath, requires:
  15. "settings-sharelatex":@settings
  16. "logger-sharelatex": log:->
  17. "./ChatHandler":@ChatHandler
  18. @query =
  19. before:"some time"
  20. describe "sendMessage", ->
  21. it "should tell the chat handler about the message", (done)->
  22. @ChatHandler.sendMessage.callsArgWith(3)
  23. @ChatController.sendMessage @project_id, @user_id, @messageContent, (err)=>
  24. @ChatHandler.sendMessage.calledWith(@project_id, @user_id, @messageContent).should.equal true
  25. done()
  26. describe "getMessages", ->
  27. it "should tell the chat handler about the request", (done)->
  28. @ChatHandler.getMessages.callsArgWith(2)
  29. @ChatController.getMessages @project_id, @query, (err)=>
  30. @ChatHandler.getMessages.calledWith(@project_id, @query).should.equal true
  31. done()