mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
return pathname from DocumentController.getDoc
This commit is contained in:
parent
13628f82ec
commit
bf1c24f6f9
4 changed files with 88 additions and 56 deletions
|
@ -7,7 +7,7 @@ module.exports =
|
||||||
doc_id = req.params.doc_id
|
doc_id = req.params.doc_id
|
||||||
plain = req?.query?.plain == 'true'
|
plain = req?.query?.plain == 'true'
|
||||||
logger.log doc_id:doc_id, project_id:project_id, "receiving get document request from api (docupdater)"
|
logger.log doc_id:doc_id, project_id:project_id, "receiving get document request from api (docupdater)"
|
||||||
ProjectEntityHandler.getDoc project_id, doc_id, (error, lines, rev, version, ranges) ->
|
ProjectEntityHandler.getDoc project_id, doc_id, {pathname: true}, (error, lines, rev, version, ranges, pathname) ->
|
||||||
if error?
|
if error?
|
||||||
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
logger.err err:error, doc_id:doc_id, project_id:project_id, "error finding element for getDocument"
|
||||||
return next(error)
|
return next(error)
|
||||||
|
@ -20,6 +20,7 @@ module.exports =
|
||||||
lines: lines
|
lines: lines
|
||||||
version: version
|
version: version
|
||||||
ranges: ranges
|
ranges: ranges
|
||||||
|
pathname: pathname
|
||||||
}
|
}
|
||||||
|
|
||||||
setDocument: (req, res, next = (error) ->) ->
|
setDocument: (req, res, next = (error) ->) ->
|
||||||
|
@ -33,6 +34,3 @@ module.exports =
|
||||||
return next(error)
|
return next(error)
|
||||||
logger.log doc_id:doc_id, project_id:project_id, "finished receiving set document request from api (docupdater)"
|
logger.log doc_id:doc_id, project_id:project_id, "finished receiving set document request from api (docupdater)"
|
||||||
res.sendStatus 200
|
res.sendStatus 200
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -131,7 +131,7 @@ module.exports = ProjectEntityHandler =
|
||||||
setRootDoc: (project_id, newRootDocID, callback = (error) ->)->
|
setRootDoc: (project_id, newRootDocID, callback = (error) ->)->
|
||||||
logger.log project_id: project_id, rootDocId: newRootDocID, "setting root doc"
|
logger.log project_id: project_id, rootDocId: newRootDocID, "setting root doc"
|
||||||
Project.update {_id:project_id}, {rootDoc_id:newRootDocID}, {}, callback
|
Project.update {_id:project_id}, {rootDoc_id:newRootDocID}, {}, callback
|
||||||
|
|
||||||
unsetRootDoc: (project_id, callback = (error) ->) ->
|
unsetRootDoc: (project_id, callback = (error) ->) ->
|
||||||
logger.log project_id: project_id, "removing root doc"
|
logger.log project_id: project_id, "removing root doc"
|
||||||
Project.update {_id:project_id}, {$unset: {rootDoc_id: true}}, {}, callback
|
Project.update {_id:project_id}, {$unset: {rootDoc_id: true}}, {}, callback
|
||||||
|
@ -140,8 +140,15 @@ module.exports = ProjectEntityHandler =
|
||||||
if typeof(options) == "function"
|
if typeof(options) == "function"
|
||||||
callback = options
|
callback = options
|
||||||
options = {}
|
options = {}
|
||||||
DocstoreManager.getDoc project_id, doc_id, options, callback
|
|
||||||
|
|
||||||
|
if options["pathname"]
|
||||||
|
delete options["pathname"]
|
||||||
|
projectLocator.findElement {project_id: project_id, element_id: doc_id, type: 'doc'}, (error, doc, path) =>
|
||||||
|
return callback(error) if error?
|
||||||
|
DocstoreManager.getDoc project_id, doc_id, options, (error, lines, rev, version, ranges) =>
|
||||||
|
callback(error, lines, rev, version, ranges, path.fileSystem)
|
||||||
|
else
|
||||||
|
DocstoreManager.getDoc project_id, doc_id, options, callback
|
||||||
|
|
||||||
addDoc: (project_id, folder_id, docName, docLines, callback = (error, doc, folder_id) ->)=>
|
addDoc: (project_id, folder_id, docName, docLines, callback = (error, doc, folder_id) ->)=>
|
||||||
ProjectGetter.getProjectWithOnlyFolders project_id, (err, project) ->
|
ProjectGetter.getProjectWithOnlyFolders project_id, (err, project) ->
|
||||||
|
@ -158,7 +165,7 @@ module.exports = ProjectEntityHandler =
|
||||||
# Put doc in docstore first, so that if it errors, we don't have a doc_id in the project
|
# Put doc in docstore first, so that if it errors, we don't have a doc_id in the project
|
||||||
# which hasn't been created in docstore.
|
# which hasn't been created in docstore.
|
||||||
DocstoreManager.updateDoc project_id.toString(), doc._id.toString(), docLines, 0, {}, (err, modified, rev) ->
|
DocstoreManager.updateDoc project_id.toString(), doc._id.toString(), docLines, 0, {}, (err, modified, rev) ->
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
|
|
||||||
ProjectEntityHandler._putElement project, folder_id, doc, "doc", (err, result)=>
|
ProjectEntityHandler._putElement project, folder_id, doc, "doc", (err, result)=>
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
|
@ -207,7 +214,7 @@ module.exports = ProjectEntityHandler =
|
||||||
replaceFile: (project_id, file_id, fsPath, callback)->
|
replaceFile: (project_id, file_id, fsPath, callback)->
|
||||||
ProjectGetter.getProject project_id, {name:true}, (err, project) ->
|
ProjectGetter.getProject project_id, {name:true}, (err, project) ->
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
findOpts =
|
findOpts =
|
||||||
project_id:project._id
|
project_id:project._id
|
||||||
element_id:file_id
|
element_id:file_id
|
||||||
type:"file"
|
type:"file"
|
||||||
|
@ -280,7 +287,7 @@ module.exports = ProjectEntityHandler =
|
||||||
procesFolder = (previousFolders, folderName, callback)=>
|
procesFolder = (previousFolders, folderName, callback)=>
|
||||||
previousFolders = previousFolders || []
|
previousFolders = previousFolders || []
|
||||||
parentFolder = previousFolders[previousFolders.length-1]
|
parentFolder = previousFolders[previousFolders.length-1]
|
||||||
if parentFolder?
|
if parentFolder?
|
||||||
parentFolder_id = parentFolder._id
|
parentFolder_id = parentFolder._id
|
||||||
builtUpPath = "#{builtUpPath}/#{folderName}"
|
builtUpPath = "#{builtUpPath}/#{folderName}"
|
||||||
projectLocator.findElementByPath project, builtUpPath, (err, foundFolder)=>
|
projectLocator.findElementByPath project, builtUpPath, (err, foundFolder)=>
|
||||||
|
@ -360,7 +367,7 @@ module.exports = ProjectEntityHandler =
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (err, entity, path)->
|
projectLocator.findElement {project:project, element_id:entity_id, type:entityType}, (err, entity, path)->
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
|
|
||||||
if entityType.match(/folder/)
|
if entityType.match(/folder/)
|
||||||
ensureFolderIsNotMovedIntoChild = (callback = (error) ->) ->
|
ensureFolderIsNotMovedIntoChild = (callback = (error) ->) ->
|
||||||
projectLocator.findElement {project: project, element_id: folder_id, type:"folder"}, (err, destEntity, destPath) ->
|
projectLocator.findElement {project: project, element_id: folder_id, type:"folder"}, (err, destEntity, destPath) ->
|
||||||
|
@ -372,7 +379,7 @@ module.exports = ProjectEntityHandler =
|
||||||
callback()
|
callback()
|
||||||
else
|
else
|
||||||
ensureFolderIsNotMovedIntoChild = (callback = () ->) -> callback()
|
ensureFolderIsNotMovedIntoChild = (callback = () ->) -> callback()
|
||||||
|
|
||||||
ensureFolderIsNotMovedIntoChild (error) ->
|
ensureFolderIsNotMovedIntoChild (error) ->
|
||||||
return callback(error) if error?
|
return callback(error) if error?
|
||||||
self._removeElementFromMongoArray Project, project_id, path.mongo, (err)->
|
self._removeElementFromMongoArray Project, project_id, path.mongo, (err)->
|
||||||
|
@ -382,7 +389,7 @@ module.exports = ProjectEntityHandler =
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
ProjectEntityHandler._putElement project, destinationFolder_id, entity, entityType, (err, result)->
|
ProjectEntityHandler._putElement project, destinationFolder_id, entity, entityType, (err, result)->
|
||||||
return callback(err) if err?
|
return callback(err) if err?
|
||||||
opts =
|
opts =
|
||||||
project_id:project_id
|
project_id:project_id
|
||||||
project_name:project.name
|
project_name:project.name
|
||||||
startPath:path.fileSystem
|
startPath:path.fileSystem
|
||||||
|
@ -506,7 +513,7 @@ module.exports = ProjectEntityHandler =
|
||||||
|
|
||||||
|
|
||||||
_countElements : (project, callback)->
|
_countElements : (project, callback)->
|
||||||
|
|
||||||
countFolder = (folder, cb = (err, count)->)->
|
countFolder = (folder, cb = (err, count)->)->
|
||||||
|
|
||||||
jobs = _.map folder?.folders, (folder)->
|
jobs = _.map folder?.folders, (folder)->
|
||||||
|
|
|
@ -24,6 +24,7 @@ describe "DocumentController", ->
|
||||||
@doc_lines = ["one", "two", "three"]
|
@doc_lines = ["one", "two", "three"]
|
||||||
@version = 42
|
@version = 42
|
||||||
@ranges = {"mock": "ranges"}
|
@ranges = {"mock": "ranges"}
|
||||||
|
@pathname = '/a/b/c/file.tex'
|
||||||
@rev = 5
|
@rev = 5
|
||||||
|
|
||||||
describe "getDocument", ->
|
describe "getDocument", ->
|
||||||
|
@ -34,12 +35,12 @@ describe "DocumentController", ->
|
||||||
|
|
||||||
describe "when the document exists", ->
|
describe "when the document exists", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, null, @doc_lines, @rev, @version, @ranges)
|
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(3, null, @doc_lines, @rev, @version, @ranges, @pathname)
|
||||||
@DocumentController.getDocument(@req, @res, @next)
|
@DocumentController.getDocument(@req, @res, @next)
|
||||||
|
|
||||||
it "should get the document from Mongo", ->
|
it "should get the document from Mongo", ->
|
||||||
@ProjectEntityHandler.getDoc
|
@ProjectEntityHandler.getDoc
|
||||||
.calledWith(@project_id, @doc_id)
|
.calledWith(@project_id, @doc_id, pathname: true)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should return the document data to the client as JSON", ->
|
it "should return the document data to the client as JSON", ->
|
||||||
|
@ -48,10 +49,11 @@ describe "DocumentController", ->
|
||||||
lines: @doc_lines
|
lines: @doc_lines
|
||||||
version: @version
|
version: @version
|
||||||
ranges: @ranges
|
ranges: @ranges
|
||||||
|
pathname: @pathname
|
||||||
|
|
||||||
describe "when the document doesn't exist", ->
|
describe "when the document doesn't exist", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(2, new Errors.NotFoundError("not found"), null)
|
@ProjectEntityHandler.getDoc = sinon.stub().callsArgWith(3, new Errors.NotFoundError("not found"), null)
|
||||||
@DocumentController.getDocument(@req, @res, @next)
|
@DocumentController.getDocument(@req, @res, @next)
|
||||||
|
|
||||||
it "should call next with the NotFoundError", ->
|
it "should call next with the NotFoundError", ->
|
||||||
|
|
|
@ -14,17 +14,17 @@ describe 'ProjectEntityHandler', ->
|
||||||
doc_id = '4eecb1c1bffa66588e0000a2'
|
doc_id = '4eecb1c1bffa66588e0000a2'
|
||||||
folder_id = "4eecaffcbffa66588e000008"
|
folder_id = "4eecaffcbffa66588e000008"
|
||||||
rootFolderId = "4eecaffcbffa66588e000007"
|
rootFolderId = "4eecaffcbffa66588e000007"
|
||||||
|
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@FileStoreHandler =
|
@FileStoreHandler =
|
||||||
uploadFileFromDisk:(project_id, fileRef, localImagePath, callback)->callback()
|
uploadFileFromDisk:(project_id, fileRef, localImagePath, callback)->callback()
|
||||||
copyFile: sinon.stub().callsArgWith(4, null)
|
copyFile: sinon.stub().callsArgWith(4, null)
|
||||||
@tpdsUpdateSender =
|
@tpdsUpdateSender =
|
||||||
addDoc:sinon.stub().callsArg(1)
|
addDoc:sinon.stub().callsArg(1)
|
||||||
addFile:sinon.stub().callsArg(1)
|
addFile:sinon.stub().callsArg(1)
|
||||||
addFolder:sinon.stub().callsArg(1)
|
addFolder:sinon.stub().callsArg(1)
|
||||||
@rootFolder =
|
@rootFolder =
|
||||||
_id:rootFolderId,
|
_id:rootFolderId,
|
||||||
folders:[
|
folders:[
|
||||||
{name:"level1", folders:[]}
|
{name:"level1", folders:[]}
|
||||||
]
|
]
|
||||||
|
@ -46,7 +46,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
@FileModel = class File
|
@FileModel = class File
|
||||||
constructor:(options)->
|
constructor:(options)->
|
||||||
{@name} = options
|
{@name} = options
|
||||||
@._id = "file_id"
|
@._id = "file_id"
|
||||||
@rev = 0
|
@rev = 0
|
||||||
@FolderModel = class Folder
|
@FolderModel = class Folder
|
||||||
constructor:(options)->
|
constructor:(options)->
|
||||||
|
@ -57,12 +57,12 @@ describe 'ProjectEntityHandler', ->
|
||||||
|
|
||||||
@ProjectModel.findById = (project_id, callback)=> callback(null, @project)
|
@ProjectModel.findById = (project_id, callback)=> callback(null, @project)
|
||||||
@ProjectModel.getProject = (project_id, fields, callback)=> callback(null, @project)
|
@ProjectModel.getProject = (project_id, fields, callback)=> callback(null, @project)
|
||||||
@ProjectGetter =
|
@ProjectGetter =
|
||||||
getProjectWithOnlyFolders : (project_id, callback)=> callback(null, @project)
|
getProjectWithOnlyFolders : (project_id, callback)=> callback(null, @project)
|
||||||
getProjectWithoutDocLines : (project_id, callback)=> callback(null, @project)
|
getProjectWithoutDocLines : (project_id, callback)=> callback(null, @project)
|
||||||
getProject:sinon.stub()
|
getProject:sinon.stub()
|
||||||
@projectUpdater = markAsUpdated:sinon.stub()
|
@projectUpdater = markAsUpdated:sinon.stub()
|
||||||
@projectLocator =
|
@projectLocator =
|
||||||
findElement : sinon.stub()
|
findElement : sinon.stub()
|
||||||
@settings =
|
@settings =
|
||||||
maxEntitiesPerProject:200
|
maxEntitiesPerProject:200
|
||||||
|
@ -97,8 +97,8 @@ describe 'ProjectEntityHandler', ->
|
||||||
else
|
else
|
||||||
cb null, @parentFolder
|
cb null, @parentFolder
|
||||||
@ProjectEntityHandler.addFolder = (project_id, parentFolder_id, folderName, callback)=>
|
@ProjectEntityHandler.addFolder = (project_id, parentFolder_id, folderName, callback)=>
|
||||||
callback null, {name:folderName}, @parentFolder_id
|
callback null, {name:folderName}, @parentFolder_id
|
||||||
|
|
||||||
it 'should return the root folder if the path is just a slash', (done)->
|
it 'should return the root folder if the path is just a slash', (done)->
|
||||||
path = "/"
|
path = "/"
|
||||||
@ProjectEntityHandler.mkdirp project_id, path, (err, folders, lastFolder)=>
|
@ProjectEntityHandler.mkdirp project_id, path, (err, folders, lastFolder)=>
|
||||||
|
@ -239,7 +239,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
@ProjectEntityHandler._putElement = sinon.stub().callsArgWith(4, null, path: @pathAfterMove)
|
@ProjectEntityHandler._putElement = sinon.stub().callsArgWith(4, null, path: @pathAfterMove)
|
||||||
@ProjectGetter.getProject.callsArgWith(2, null, @project)
|
@ProjectGetter.getProject.callsArgWith(2, null, @project)
|
||||||
@tpdsUpdateSender.moveEntity = sinon.stub().callsArg(1)
|
@tpdsUpdateSender.moveEntity = sinon.stub().callsArg(1)
|
||||||
|
|
||||||
describe "moving a doc", ->
|
describe "moving a doc", ->
|
||||||
beforeEach (done) ->
|
beforeEach (done) ->
|
||||||
@docId = "4eecaffcbffa66588e000009"
|
@docId = "4eecaffcbffa66588e000009"
|
||||||
|
@ -257,10 +257,10 @@ describe 'ProjectEntityHandler', ->
|
||||||
it 'should remove the element from its current position', ->
|
it 'should remove the element from its current position', ->
|
||||||
@ProjectEntityHandler._removeElementFromMongoArray
|
@ProjectEntityHandler._removeElementFromMongoArray
|
||||||
.calledWith(@ProjectModel, project_id, @path.mongo ).should.equal true
|
.calledWith(@ProjectModel, project_id, @path.mongo ).should.equal true
|
||||||
|
|
||||||
it "should put the element back in the new folder", ->
|
it "should put the element back in the new folder", ->
|
||||||
@ProjectEntityHandler._putElement.calledWith(@project, folder_id, @doc, "docs").should.equal true
|
@ProjectEntityHandler._putElement.calledWith(@project, folder_id, @doc, "docs").should.equal true
|
||||||
|
|
||||||
it 'should tell the third party data store', ->
|
it 'should tell the third party data store', ->
|
||||||
@tpdsUpdateSender.moveEntity
|
@tpdsUpdateSender.moveEntity
|
||||||
.calledWith({
|
.calledWith({
|
||||||
|
@ -271,7 +271,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
rev: @doc.rev
|
rev: @doc.rev
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "moving a folder", ->
|
describe "moving a folder", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@folder_id = "folder-to-move"
|
@folder_id = "folder-to-move"
|
||||||
|
@ -294,7 +294,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
else
|
else
|
||||||
console.log "UNKNOWN ID", options
|
console.log "UNKNOWN ID", options
|
||||||
sinon.spy @projectLocator, "findElement"
|
sinon.spy @projectLocator, "findElement"
|
||||||
|
|
||||||
describe "when the destination folder is outside the moving folder", ->
|
describe "when the destination folder is outside the moving folder", ->
|
||||||
beforeEach (done) ->
|
beforeEach (done) ->
|
||||||
@path.fileSystem = "/one/directory"
|
@path.fileSystem = "/one/directory"
|
||||||
|
@ -318,7 +318,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
@path.mongo
|
@path.mongo
|
||||||
)
|
)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should put the element back in the new folder", ->
|
it "should put the element back in the new folder", ->
|
||||||
@ProjectEntityHandler._putElement
|
@ProjectEntityHandler._putElement
|
||||||
.calledWith(
|
.calledWith(
|
||||||
|
@ -328,7 +328,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
"folder"
|
"folder"
|
||||||
)
|
)
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it 'should tell the third party data store', ->
|
it 'should tell the third party data store', ->
|
||||||
@tpdsUpdateSender.moveEntity
|
@tpdsUpdateSender.moveEntity
|
||||||
.calledWith({
|
.calledWith({
|
||||||
|
@ -339,7 +339,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
rev: @folder.rev
|
rev: @folder.rev
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "when the destination folder is inside the moving folder", ->
|
describe "when the destination folder is inside the moving folder", ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
@path.fileSystem = "/one/two"
|
@path.fileSystem = "/one/two"
|
||||||
|
@ -355,7 +355,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
project: @project
|
project: @project
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
it "should return an error", ->
|
it "should return an error", ->
|
||||||
@callback
|
@callback
|
||||||
.calledWith(new Error("destination folder is a child folder of me"))
|
.calledWith(new Error("destination folder is a child folder of me"))
|
||||||
|
@ -385,16 +385,41 @@ describe 'ProjectEntityHandler', ->
|
||||||
@rev = 5
|
@rev = 5
|
||||||
@version = 42
|
@version = 42
|
||||||
@ranges = {"mock": "ranges"}
|
@ranges = {"mock": "ranges"}
|
||||||
|
|
||||||
@DocstoreManager.getDoc = sinon.stub().callsArgWith(3, null, @lines, @rev, @version, @ranges)
|
@DocstoreManager.getDoc = sinon.stub().callsArgWith(3, null, @lines, @rev, @version, @ranges)
|
||||||
@ProjectEntityHandler.getDoc project_id, doc_id, @callback
|
|
||||||
|
|
||||||
it "should call the docstore", ->
|
describe 'without pathname option', ->
|
||||||
@DocstoreManager.getDoc
|
beforeEach ->
|
||||||
.calledWith(project_id, doc_id)
|
@ProjectEntityHandler.getDoc project_id, doc_id, @callback
|
||||||
.should.equal true
|
|
||||||
|
it "should call the docstore", ->
|
||||||
|
@DocstoreManager.getDoc
|
||||||
|
.calledWith(project_id, doc_id)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should call the callback with the lines, version and rev", ->
|
||||||
|
@callback.calledWith(null, @lines, @rev, @version, @ranges).should.equal true
|
||||||
|
|
||||||
|
describe 'with pathname option', ->
|
||||||
|
beforeEach ->
|
||||||
|
@project = 'a project'
|
||||||
|
@path = mongo: "mongo.path", fileSystem: "/file/system/path"
|
||||||
|
@projectLocator.findElement = sinon.stub().callsArgWith(1, null, {}, @path)
|
||||||
|
@ProjectEntityHandler.getDoc project_id, doc_id, {pathname: true}, @callback
|
||||||
|
|
||||||
|
it "should call the project locator", ->
|
||||||
|
@projectLocator.findElement
|
||||||
|
.calledWith({project_id: project_id, element_id: doc_id, type: 'doc'})
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should call the docstore", ->
|
||||||
|
@DocstoreManager.getDoc
|
||||||
|
.calledWith(project_id, doc_id)
|
||||||
|
.should.equal true
|
||||||
|
|
||||||
|
it "should return the pathname if option given", ->
|
||||||
|
@callback.calledWith(null, @lines, @rev, @version, @ranges, @path.fileSystem).should.equal true
|
||||||
|
|
||||||
it "should call the callback with the lines, version and rev", ->
|
|
||||||
@callback.calledWith(null, @lines, @rev, @version, @ranges).should.equal true
|
|
||||||
|
|
||||||
describe 'addDoc', ->
|
describe 'addDoc', ->
|
||||||
beforeEach ->
|
beforeEach ->
|
||||||
|
@ -876,7 +901,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
path: path
|
path: path
|
||||||
})
|
})
|
||||||
.should.equal true
|
.should.equal true
|
||||||
|
|
||||||
describe "setRootDoc", ->
|
describe "setRootDoc", ->
|
||||||
it "should call Project.update", ->
|
it "should call Project.update", ->
|
||||||
@project_id = "project-id-123234adfs"
|
@project_id = "project-id-123234adfs"
|
||||||
|
@ -907,22 +932,22 @@ describe 'ProjectEntityHandler', ->
|
||||||
|
|
||||||
it 'should copy the file in FileStoreHandler', (done)->
|
it 'should copy the file in FileStoreHandler', (done)->
|
||||||
@ProjectEntityHandler._putElement = sinon.stub().callsArgWith(4, null, {path:{fileSystem:"somehintg"}})
|
@ProjectEntityHandler._putElement = sinon.stub().callsArgWith(4, null, {path:{fileSystem:"somehintg"}})
|
||||||
@ProjectEntityHandler.copyFileFromExistingProject project_id, folder_id, oldProject_id, oldFileRef, (err, fileRef, parentFolder)=>
|
@ProjectEntityHandler.copyFileFromExistingProject project_id, folder_id, oldProject_id, oldFileRef, (err, fileRef, parentFolder)=>
|
||||||
@FileStoreHandler.copyFile.calledWith(oldProject_id, oldFileRef._id, project_id, fileRef._id).should.equal true
|
@FileStoreHandler.copyFile.calledWith(oldProject_id, oldFileRef._id, project_id, fileRef._id).should.equal true
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'should put file into folder by calling put element', (done)->
|
it 'should put file into folder by calling put element', (done)->
|
||||||
@ProjectEntityHandler._putElement = (passedProject, passedFolder_id, passedFileRef, passedType, callback)->
|
@ProjectEntityHandler._putElement = (passedProject, passedFolder_id, passedFileRef, passedType, callback)->
|
||||||
passedProject._id.should.equal project_id
|
passedProject._id.should.equal project_id
|
||||||
passedFolder_id.should.equal folder_id
|
passedFolder_id.should.equal folder_id
|
||||||
passedFileRef.name.should.equal fileName
|
passedFileRef.name.should.equal fileName
|
||||||
passedType.should.equal 'file'
|
passedType.should.equal 'file'
|
||||||
done()
|
done()
|
||||||
|
|
||||||
@ProjectEntityHandler.copyFileFromExistingProject project_id, folder_id, oldProject_id, oldFileRef, (err, fileRef, parentFolder)->
|
@ProjectEntityHandler.copyFileFromExistingProject project_id, folder_id, oldProject_id, oldFileRef, (err, fileRef, parentFolder)->
|
||||||
|
|
||||||
it 'should return doc and parent folder', (done)->
|
it 'should return doc and parent folder', (done)->
|
||||||
@ProjectEntityHandler.copyFileFromExistingProject project_id, folder_id, oldProject_id, oldFileRef, (err, fileRef, parentFolder)->
|
@ProjectEntityHandler.copyFileFromExistingProject project_id, folder_id, oldProject_id, oldFileRef, (err, fileRef, parentFolder)->
|
||||||
parentFolder.should.equal folder_id
|
parentFolder.should.equal folder_id
|
||||||
fileRef.name.should.equal fileName
|
fileRef.name.should.equal fileName
|
||||||
done()
|
done()
|
||||||
|
@ -942,7 +967,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
options.rev.should.equal 0
|
options.rev.should.equal 0
|
||||||
done()
|
done()
|
||||||
|
|
||||||
@ProjectEntityHandler.copyFileFromExistingProject project_id, folder_id, oldProject_id, oldFileRef, (err, fileRef, parentFolder)->
|
@ProjectEntityHandler.copyFileFromExistingProject project_id, folder_id, oldProject_id, oldFileRef, (err, fileRef, parentFolder)->
|
||||||
|
|
||||||
|
|
||||||
describe "renameEntity", ->
|
describe "renameEntity", ->
|
||||||
|
@ -1054,7 +1079,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
@folder =
|
@folder =
|
||||||
_id: ObjectId()
|
_id: ObjectId()
|
||||||
name: "someFolder"
|
name: "someFolder"
|
||||||
@doc =
|
@doc =
|
||||||
_id: ObjectId()
|
_id: ObjectId()
|
||||||
name: "new.tex"
|
name: "new.tex"
|
||||||
@path = mongo: "mongo.path", fileSystem: "/file/system/old.tex"
|
@path = mongo: "mongo.path", fileSystem: "/file/system/old.tex"
|
||||||
|
@ -1064,7 +1089,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
|
|
||||||
|
|
||||||
describe "updating the project", ->
|
describe "updating the project", ->
|
||||||
|
|
||||||
|
|
||||||
it "should use the correct mongo path", (done)->
|
it "should use the correct mongo path", (done)->
|
||||||
@ProjectEntityHandler._putElement @project, @folder._id, @doc, "docs", (err)=>
|
@ProjectEntityHandler._putElement @project, @folder._id, @doc, "docs", (err)=>
|
||||||
|
@ -1089,12 +1114,12 @@ describe 'ProjectEntityHandler', ->
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should error if the element has no _id", (done)->
|
it "should error if the element has no _id", (done)->
|
||||||
doc =
|
doc =
|
||||||
name:"something"
|
name:"something"
|
||||||
@ProjectEntityHandler._putElement @project, @folder._id, doc, "doc", (err)=>
|
@ProjectEntityHandler._putElement @project, @folder._id, doc, "doc", (err)=>
|
||||||
@ProjectModel.update.called.should.equal false
|
@ProjectModel.update.called.should.equal false
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
describe "_countElements", ->
|
describe "_countElements", ->
|
||||||
|
@ -1109,7 +1134,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
fileRefs:{}
|
fileRefs:{}
|
||||||
folders: [
|
folders: [
|
||||||
{
|
{
|
||||||
docs:[_id:1234],
|
docs:[_id:1234],
|
||||||
fileRefs:[{_id:23123}, {_id:123213}, {_id:2312}]
|
fileRefs:[{_id:23123}, {_id:123213}, {_id:2312}]
|
||||||
folders:[
|
folders:[
|
||||||
{
|
{
|
||||||
|
@ -1131,7 +1156,7 @@ describe 'ProjectEntityHandler', ->
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
it "should return the correct number", (done)->
|
it "should return the correct number", (done)->
|
||||||
@ProjectEntityHandler._countElements @project, (err, count)->
|
@ProjectEntityHandler._countElements @project, (err, count)->
|
||||||
|
@ -1142,19 +1167,19 @@ describe 'ProjectEntityHandler', ->
|
||||||
@project.rootFolder[0].folders[0].folders = undefined
|
@project.rootFolder[0].folders[0].folders = undefined
|
||||||
@ProjectEntityHandler._countElements @project, (err, count)->
|
@ProjectEntityHandler._countElements @project, (err, count)->
|
||||||
count.should.equal 17
|
count.should.equal 17
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should deal with null docs", (done)->
|
it "should deal with null docs", (done)->
|
||||||
@project.rootFolder[0].folders[0].docs = undefined
|
@project.rootFolder[0].folders[0].docs = undefined
|
||||||
@ProjectEntityHandler._countElements @project, (err, count)->
|
@ProjectEntityHandler._countElements @project, (err, count)->
|
||||||
count.should.equal 23
|
count.should.equal 23
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it "should deal with null fileRefs", (done)->
|
it "should deal with null fileRefs", (done)->
|
||||||
@project.rootFolder[0].folders[0].folders[0].fileRefs = undefined
|
@project.rootFolder[0].folders[0].folders[0].fileRefs = undefined
|
||||||
@ProjectEntityHandler._countElements @project, (err, count)->
|
@ProjectEntityHandler._countElements @project, (err, count)->
|
||||||
count.should.equal 23
|
count.should.equal 23
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue