| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- SandboxedModule = require('sandboxed-module')
- sinon = require('sinon')
- require('chai').should()
- modulePath = require('path').join __dirname, '../../../../app/js/Features/Editor/EditorHttpController'
- describe "EditorHttpController", ->
- beforeEach ->
- @EditorHttpController = SandboxedModule.require modulePath, requires:
- '../Project/ProjectEntityHandler' : @ProjectEntityHandler = {}
- "./EditorRealTimeController": @EditorRealTimeController = {}
- "logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
- "./EditorController": @EditorController = {}
- @project_id = "mock-project-id"
- @doc_id = "mock-doc-id"
- @parent_folder_id = "mock-folder-id"
- @req = {}
- @res =
- send: sinon.stub()
- json: sinon.stub()
- describe "restoreDoc", ->
- beforeEach ->
- @req.params =
- Project_id: @project_id
- doc_id: @doc_id
- @req.body =
- name: @name = "doc-name"
- @ProjectEntityHandler.restoreDoc = sinon.stub().callsArgWith(3, null,
- @doc = { "mock": "doc", _id: @new_doc_id = "new-doc-id" }
- @folder_id = "mock-folder-id"
- )
- @EditorRealTimeController.emitToRoom = sinon.stub()
- @EditorHttpController.restoreDoc @req, @res
- it "should restore the doc", ->
- @ProjectEntityHandler.restoreDoc
- .calledWith(@project_id, @doc_id, @name)
- .should.equal true
- it "should the real-time clients about the new doc", ->
- @EditorRealTimeController.emitToRoom
- .calledWith(@project_id, 'reciveNewDoc', @folder_id, @doc)
- .should.equal true
- it "should return the new doc id", ->
- @res.json
- .calledWith(doc_id: @new_doc_id)
- .should.equal true
- describe "addDoc", ->
- beforeEach ->
- @doc = { "mock": "doc" }
- @req.params =
- Project_id: @project_id
- @req.body =
- name: @name = "doc-name"
- parent_folder_id: @parent_folder_id
- @EditorController.addDoc = sinon.stub().callsArgWith(5, null, @doc)
- @EditorHttpController.addDoc @req, @res
- it "should call EditorController.addDoc", ->
- @EditorController.addDoc
- .calledWith(@project_id, @parent_folder_id, @name, [], "editor")
- .should.equal true
- it "should send the doc back as JSON", ->
- @res.json
- .calledWith(@doc)
- .should.equal true
- describe "addFolder", ->
- beforeEach ->
- @folder = { "mock": "folder" }
- @req.params =
- Project_id: @project_id
- @req.body =
- name: @name = "folder-name"
- parent_folder_id: @parent_folder_id
- @EditorController.addFolder = sinon.stub().callsArgWith(4, null, @folder)
- @EditorHttpController.addFolder @req, @res
- it "should call EditorController.addFolder", ->
- @EditorController.addFolder
- .calledWith(@project_id, @parent_folder_id, @name, "editor")
- .should.equal true
- it "should send the folder back as JSON", ->
- @res.json
- .calledWith(@folder)
- .should.equal true
- describe "renameEntity", ->
- beforeEach ->
- @req.params =
- Project_id: @project_id
- entity_id: @entity_id = "entity-id-123"
- entity_type: @entity_type = "entity-type"
- @req.body =
- name: @name = "new-name"
- @EditorController.renameEntity = sinon.stub().callsArg(4)
- @EditorHttpController.renameEntity @req, @res
- it "should call EditorController.renameEntity", ->
- @EditorController.renameEntity
- .calledWith(@project_id, @entity_id, @entity_type, @name)
- .should.equal true
- it "should send back a success response", ->
- @res.send.calledWith(204).should.equal true
- describe "renameEntity with long name", ->
- beforeEach ->
- @req.params =
- Project_id: @project_id
- entity_id: @entity_id = "entity-id-123"
- entity_type: @entity_type = "entity-type"
- @req.body =
- name: @name = "EDMUBEEBKBXUUUZERMNSXFFWIBHGSDAWGMRIQWJBXGWSBVWSIKLFPRBYSJEKMFHTRZBHVKJSRGKTBHMJRXPHORFHAKRNPZGGYIOTEDMUBEEBKBXUUUZERMNSXFFWIBHGSDAWGMRIQWJBXGWSBVWSIKLFPRBYSJEKMFHTRZBHVKJSRGKTBHMJRXPHORFHAKRNPZGGYIOT"
- @EditorController.renameEntity = sinon.stub().callsArg(4)
- @EditorHttpController.renameEntity @req, @res
- it "should send back a bad request status code", ->
- @res.send.calledWith(400).should.equal true
- describe "moveEntity", ->
- beforeEach ->
- @req.params =
- Project_id: @project_id
- entity_id: @entity_id = "entity-id-123"
- entity_type: @entity_type = "entity-type"
- @req.body =
- folder_id: @folder_id = "folder-id-123"
- @EditorController.moveEntity = sinon.stub().callsArg(4)
- @EditorHttpController.moveEntity @req, @res
- it "should call EditorController.moveEntity", ->
- @EditorController.moveEntity
- .calledWith(@project_id, @entity_id, @folder_id, @entity_type)
- .should.equal true
- it "should send back a success response", ->
- @res.send.calledWith(204).should.equal true
- describe "deleteEntity", ->
- beforeEach ->
- @req.params =
- Project_id: @project_id
- entity_id: @entity_id = "entity-id-123"
- entity_type: @entity_type = "entity-type"
- @EditorController.deleteEntity = sinon.stub().callsArg(4)
- @EditorHttpController.deleteEntity @req, @res
- it "should call EditorController.deleteEntity", ->
- @EditorController.deleteEntity
- .calledWith(@project_id, @entity_id, @entity_type, "editor")
- .should.equal true
- it "should send back a success response", ->
- @res.send.calledWith(204).should.equal true
|