|
|
@@ -14,6 +14,7 @@ describe 'ProjectEntityHandler', ->
|
|
|
doc_id = '4eecb1c1bffa66588e0000a2'
|
|
|
folder_id = "4eecaffcbffa66588e000008"
|
|
|
rootFolderId = "4eecaffcbffa66588e000007"
|
|
|
+ userId = 1234
|
|
|
|
|
|
beforeEach ->
|
|
|
@FileStoreHandler =
|
|
|
@@ -235,10 +236,16 @@ describe 'ProjectEntityHandler', ->
|
|
|
@pathAfterMove = {
|
|
|
fileSystem: "/somewhere/else.txt"
|
|
|
}
|
|
|
- @ProjectEntityHandler._removeElementFromMongoArray = sinon.stub().callsArg(3)
|
|
|
+ @ProjectEntityHandler._removeElementFromMongoArray = sinon.stub().callsArgWith(3, null, @project)
|
|
|
@ProjectEntityHandler._putElement = sinon.stub().callsArgWith(4, null, path: @pathAfterMove)
|
|
|
@ProjectGetter.getProject.callsArgWith(2, null, @project)
|
|
|
- @tpdsUpdateSender.moveEntity = sinon.stub().callsArg(1)
|
|
|
+ @tpdsUpdateSender.moveEntity = sinon.stub()
|
|
|
+ @documentUpdaterHandler.updateProjectStructure = sinon.stub().callsArg(4)
|
|
|
+ @ProjectEntityHandler.getAllEntitiesFromProject = sinon.stub()
|
|
|
+ @ProjectEntityHandler.getAllEntitiesFromProject
|
|
|
+ .onFirstCall().callsArgWith(1, null, @oldDocs = [])
|
|
|
+ @ProjectEntityHandler.getAllEntitiesFromProject
|
|
|
+ .onSecondCall().callsArgWith(1, null, @newDocs = [])
|
|
|
|
|
|
describe "moving a doc", ->
|
|
|
beforeEach (done) ->
|
|
|
@@ -246,14 +253,26 @@ describe 'ProjectEntityHandler', ->
|
|
|
@doc = {lines:["1234","312343d"], rev: "1234"}
|
|
|
@path = {
|
|
|
mongo:"folders[0]"
|
|
|
- fileSystem:"/somewhere.txt"
|
|
|
+ fileSystem:"/old_folder/somewhere.txt"
|
|
|
+ }
|
|
|
+ @destFolder = { name: "folder" }
|
|
|
+ @destFolderPath = {
|
|
|
+ mongo: "folders[0]"
|
|
|
+ fileSystem: "/dest_folder"
|
|
|
}
|
|
|
- @projectLocator.findElement = sinon.stub().callsArgWith(1, null, @doc, @path)
|
|
|
- @ProjectEntityHandler.moveEntity project_id, @docId, folder_id, "docs", done
|
|
|
+ @projectLocator.findElement = sinon.stub()
|
|
|
+ @projectLocator.findElement.withArgs({project: @project, element_id: @docId, type: 'docs'})
|
|
|
+ .callsArgWith(1, null, @doc, @path)
|
|
|
+ @ProjectEntityHandler.moveEntity project_id, @docId, folder_id, "docs", userId, done
|
|
|
|
|
|
- it 'should find the project then element', ->
|
|
|
+ it 'should find the doc to move', ->
|
|
|
@projectLocator.findElement.calledWith({element_id: @docId, type: "docs", project: @project }).should.equal true
|
|
|
|
|
|
+ it "should should send the update to the doc updater", ->
|
|
|
+ @documentUpdaterHandler.updateProjectStructure
|
|
|
+ .calledWith(project_id, userId, @oldDocs, @newDocs)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
it 'should remove the element from its current position', ->
|
|
|
@ProjectEntityHandler._removeElementFromMongoArray
|
|
|
.calledWith(@ProjectModel, project_id, @path.mongo ).should.equal true
|
|
|
@@ -278,28 +297,19 @@ describe 'ProjectEntityHandler', ->
|
|
|
@move_to_folder_id = "folder-to-move-to"
|
|
|
@folder = { name: "folder" }
|
|
|
@folder_to_move_to = { name: "folder to move to" }
|
|
|
- @path = {
|
|
|
- mongo: "folders[0]"
|
|
|
- fileSystem: "/somewhere.txt"
|
|
|
- }
|
|
|
- @pathToMoveTo = {
|
|
|
- mongo: "folders[0]"
|
|
|
- fileSystem: "/somewhere.txt"
|
|
|
- }
|
|
|
- @projectLocator.findElement = (options, callback) =>
|
|
|
- if options.element_id == @folder_id
|
|
|
- callback(null, @folder, @path)
|
|
|
- else if options.element_id == @move_to_folder_id
|
|
|
- callback(null, @folder_to_move_to, @pathToMoveTo)
|
|
|
- else
|
|
|
- console.log "UNKNOWN ID", options
|
|
|
- sinon.spy @projectLocator, "findElement"
|
|
|
+ @path = { mongo:"folders[0]" }
|
|
|
+ @pathToMoveTo = { mongo: "folders[0]" }
|
|
|
+ @projectLocator.findElement = sinon.stub()
|
|
|
+ @projectLocator.findElement.withArgs({project: @project, element_id: @folder_id, type: 'folder'})
|
|
|
+ .callsArgWith(1, null, @folder, @path)
|
|
|
+ @projectLocator.findElement.withArgs({project: @project, element_id: @move_to_folder_id, type: 'folder'})
|
|
|
+ .callsArgWith(1, null, @folder_to_move_to, @pathToMoveTo)
|
|
|
|
|
|
describe "when the destination folder is outside the moving folder", ->
|
|
|
beforeEach (done) ->
|
|
|
- @path.fileSystem = "/one/directory"
|
|
|
- @pathToMoveTo.fileSystem = "/another/directory"
|
|
|
- @ProjectEntityHandler.moveEntity project_id, @folder_id, @move_to_folder_id, "folder", done
|
|
|
+ @path.fileSystem = "/one/src_dir"
|
|
|
+ @pathToMoveTo.fileSystem = "/two/dest_dir"
|
|
|
+ @ProjectEntityHandler.moveEntity project_id, @folder_id, @move_to_folder_id, "folder", userId, done
|
|
|
|
|
|
it 'should find the project then element', ->
|
|
|
@projectLocator.findElement
|
|
|
@@ -310,6 +320,11 @@ describe 'ProjectEntityHandler', ->
|
|
|
})
|
|
|
.should.equal true
|
|
|
|
|
|
+ it "should should send the update to the doc updater", ->
|
|
|
+ @documentUpdaterHandler.updateProjectStructure
|
|
|
+ .calledWith(project_id, userId, @oldDocs, @newDocs)
|
|
|
+ .should.equal true
|
|
|
+
|
|
|
it 'should remove the element from its current position', ->
|
|
|
@ProjectEntityHandler._removeElementFromMongoArray
|
|
|
.calledWith(
|
|
|
@@ -345,9 +360,9 @@ describe 'ProjectEntityHandler', ->
|
|
|
@path.fileSystem = "/one/two"
|
|
|
@pathToMoveTo.fileSystem = "/one/two/three"
|
|
|
@callback = sinon.stub()
|
|
|
- @ProjectEntityHandler.moveEntity project_id, @folder_id, @move_to_folder_id, "folder", @callback
|
|
|
+ @ProjectEntityHandler.moveEntity project_id, @folder_id, @move_to_folder_id, "folder", userId, @callback
|
|
|
|
|
|
- it 'should find the folder we are moving to as well element', ->
|
|
|
+ it 'should find the folder we are moving to element', ->
|
|
|
@projectLocator.findElement
|
|
|
.calledWith({
|
|
|
element_id: @move_to_folder_id,
|
|
|
@@ -982,7 +997,6 @@ describe 'ProjectEntityHandler', ->
|
|
|
@entityType = "doc"
|
|
|
@newName = "new.tex"
|
|
|
@path = mongo: "mongo.path", fileSystem: "/file/system/old.tex"
|
|
|
- @userId = 1234
|
|
|
|
|
|
@ProjectGetter.getProject.callsArgWith(2, null, @project)
|
|
|
@ProjectEntityHandler.getAllEntitiesFromProject = sinon.stub()
|
|
|
@@ -997,20 +1011,20 @@ describe 'ProjectEntityHandler', ->
|
|
|
@documentUpdaterHandler.updateProjectStructure = sinon.stub().callsArg(4)
|
|
|
|
|
|
it "should should send the old and new project structure to the doc updater", (done) ->
|
|
|
- @ProjectEntityHandler.renameEntity @project_id, @entity_id, @entityType, @newName, @userId, =>
|
|
|
+ @ProjectEntityHandler.renameEntity project_id, @entity_id, @entityType, @newName, userId, =>
|
|
|
@documentUpdaterHandler.updateProjectStructure.calledWith(
|
|
|
- @project_id, @userId, @oldDocs, @newDocs,
|
|
|
+ project_id, userId, @oldDocs, @newDocs,
|
|
|
).should.equal true
|
|
|
done()
|
|
|
|
|
|
it "should update the name in mongo", (done)->
|
|
|
- @ProjectEntityHandler.renameEntity @project_id, @entity_id, @entityType, @newName, @userId, =>
|
|
|
- @ProjectModel.findOneAndUpdate.calledWith({_id: @project_id}, {"$set":{"mongo.path.name": @newName}}, {"new": true}).should.equal true
|
|
|
+ @ProjectEntityHandler.renameEntity project_id, @entity_id, @entityType, @newName, userId, =>
|
|
|
+ @ProjectModel.findOneAndUpdate.calledWith({_id: project_id}, {"$set":{"mongo.path.name": @newName}}, {"new": true}).should.equal true
|
|
|
done()
|
|
|
|
|
|
it "should send the update to the tpds", (done)->
|
|
|
- @ProjectEntityHandler.renameEntity @project_id, @entity_id, @entityType, @newName, @userId, =>
|
|
|
- @tpdsUpdateSender.moveEntity.calledWith({project_id:@project_id, startPath:@path.fileSystem, endPath:"/file/system/new.tex", project_name:@project.name, rev:4}).should.equal true
|
|
|
+ @ProjectEntityHandler.renameEntity project_id, @entity_id, @entityType, @newName, userId, =>
|
|
|
+ @tpdsUpdateSender.moveEntity.calledWith({project_id:project_id, startPath:@path.fileSystem, endPath:"/file/system/new.tex", project_name:@project.name, rev:4}).should.equal true
|
|
|
done()
|
|
|
|
|
|
describe "_insertDeletedDocReference", ->
|