ChatControllerTests.coffee 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. @EditorRealTimeController =
  15. emitToRoom:sinon.stub().callsArgWith(3)
  16. @ChatController = SandboxedModule.require modulePath, requires:
  17. "settings-sharelatex":@settings
  18. "logger-sharelatex": log:->
  19. "./ChatHandler":@ChatHandler
  20. "../Editor/EditorRealTimeController":@EditorRealTimeController
  21. @query =
  22. before:"some time"
  23. describe "sendMessage", ->
  24. it "should tell the chat handler about the message", (done)->
  25. @ChatHandler.sendMessage.callsArgWith(3)
  26. @ChatController.sendMessage @project_id, @user_id, @messageContent, (err)=>
  27. @ChatHandler.sendMessage.calledWith(@project_id, @user_id, @messageContent).should.equal true
  28. done()
  29. it "should tell the editor real time controller about the update with the data from the chat handler", (done)->
  30. @chatMessage =
  31. content:"hello world"
  32. @ChatHandler.sendMessage.callsArgWith(3, null, @chatMessage)
  33. @ChatController.sendMessage @project_id, @user_id, @messageContent, (err)=>
  34. @EditorRealTimeController.emitToRoom.calledWith(@project_id, "new-chat-message", @chatMessage).should.equal true
  35. done()
  36. describe "getMessages", ->
  37. it "should tell the chat handler about the request", (done)->
  38. @ChatHandler.getMessages.callsArgWith(2)
  39. @ChatController.getMessages @project_id, @query, (err)=>
  40. @ChatHandler.getMessages.calledWith(@project_id, @query).should.equal true
  41. done()
  42. it "should return the messages", (done)->
  43. messages = [{content:"hello"}]
  44. @ChatHandler.getMessages.callsArgWith(2, null, messages)
  45. @ChatController.getMessages @project_id, @query, (err, passedMessages)=>
  46. passedMessages.should.deep.equal messages
  47. done()