EditorHttpControllerTests.coffee 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. "./EditorController": @EditorController = {}
  12. @project_id = "mock-project-id"
  13. @doc_id = "mock-doc-id"
  14. @parent_folder_id = "mock-folder-id"
  15. @req = {}
  16. @res =
  17. send: sinon.stub()
  18. json: sinon.stub()
  19. describe "restoreDoc", ->
  20. beforeEach ->
  21. @req.params =
  22. Project_id: @project_id
  23. doc_id: @doc_id
  24. @req.body =
  25. name: @name = "doc-name"
  26. @ProjectEntityHandler.restoreDoc = sinon.stub().callsArgWith(3, null,
  27. @doc = { "mock": "doc", _id: @new_doc_id = "new-doc-id" }
  28. @folder_id = "mock-folder-id"
  29. )
  30. @EditorRealTimeController.emitToRoom = sinon.stub()
  31. @EditorHttpController.restoreDoc @req, @res
  32. it "should restore the doc", ->
  33. @ProjectEntityHandler.restoreDoc
  34. .calledWith(@project_id, @doc_id, @name)
  35. .should.equal true
  36. it "should the real-time clients about the new doc", ->
  37. @EditorRealTimeController.emitToRoom
  38. .calledWith(@project_id, 'reciveNewDoc', @folder_id, @doc)
  39. .should.equal true
  40. it "should return the new doc id", ->
  41. @res.json
  42. .calledWith(doc_id: @new_doc_id)
  43. .should.equal true
  44. describe "addDoc", ->
  45. beforeEach ->
  46. @doc = { "mock": "doc" }
  47. @req.params =
  48. Project_id: @project_id
  49. @req.body =
  50. name: @name = "doc-name"
  51. parent_folder_id: @parent_folder_id
  52. @EditorController.addDoc = sinon.stub().callsArgWith(4, null, @doc)
  53. @EditorHttpController.addDoc @req, @res
  54. it "should call EditorController.addDoc", ->
  55. @EditorController.addDoc
  56. .calledWith(@project_id, @parent_folder_id, @name, [])
  57. .should.equal true
  58. it "should send the doc back as JSON", ->
  59. @res.json
  60. .calledWith(@doc)
  61. .should.equal true