EditorHttpControllerTests.coffee 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. SandboxedModule = require('sandboxed-module')
  2. sinon = require('sinon')
  3. require('chai').should()
  4. modulePath = require('path').join __dirname, '../../../../app/js/Features/Editor/EditorHttpController'
  5. describe "EditorHttpController", ->
  6. beforeEach ->
  7. @EditorHttpController = SandboxedModule.require modulePath, requires:
  8. '../Project/ProjectEntityHandler' : @ProjectEntityHandler = {}
  9. "./EditorRealTimeController": @EditorRealTimeController = {}
  10. "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
  11. @project_id = "mock-project-id"
  12. @doc_id = "mock-doc-id"
  13. @req = {}
  14. @res =
  15. send: sinon.stub()
  16. json: sinon.stub()
  17. describe "restoreDoc", ->
  18. beforeEach ->
  19. @req.params =
  20. Project_id: @project_id
  21. doc_id: @doc_id
  22. @req.body =
  23. name: @name = "doc-name"
  24. @ProjectEntityHandler.restoreDoc = sinon.stub().callsArgWith(3, null,
  25. @doc = { "mock": "doc", _id: @new_doc_id = "new-doc-id" }
  26. @folder_id = "mock-folder-id"
  27. )
  28. @EditorRealTimeController.emitToRoom = sinon.stub()
  29. @EditorHttpController.restoreDoc @req, @res
  30. it "should restore the doc", ->
  31. @ProjectEntityHandler.restoreDoc
  32. .calledWith(@project_id, @doc_id, @name)
  33. .should.equal true
  34. it "should the real-time clients about the new doc", ->
  35. @EditorRealTimeController.emitToRoom
  36. .calledWith(@project_id, 'reciveNewDoc', @folder_id, @doc)
  37. .should.equal true
  38. it "should return the new doc id", ->
  39. @res.json
  40. .calledWith(doc_id: @new_doc_id)
  41. .should.equal true