mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-05 22:01:38 +00:00
Track the source of updates through the system on adding/updating of docs and files
This commit is contained in:
parent
4f2ab51ebd
commit
6800c1a15e
10 changed files with 100 additions and 97 deletions
|
@ -160,29 +160,29 @@ module.exports = EditorController =
|
|||
if callback?
|
||||
callback()
|
||||
|
||||
setDoc: (project_id, doc_id, docLines, callback = (err)->)->
|
||||
setDoc: (project_id, doc_id, docLines, source, callback = (err)->)->
|
||||
DocumentUpdaterHandler.setDocument project_id, doc_id, docLines, (err)=>
|
||||
logger.log project_id:project_id, doc_id:doc_id, "notifying users that the document has been updated"
|
||||
EditorRealTimeController.emitToRoom(project_id, "entireDocUpdate", doc_id)
|
||||
EditorRealTimeController.emitToRoom(project_id, "entireDocUpdate", doc_id, source)
|
||||
DocumentUpdaterHandler.flushDocToMongo project_id, doc_id, callback
|
||||
|
||||
addDoc: (project_id, folder_id, docName, docLines, callback = (error, doc)->)->
|
||||
addDoc: (project_id, folder_id, docName, docLines, source, callback = (error, doc)->)->
|
||||
docName = docName.trim()
|
||||
logger.log {project_id, folder_id, docName}, "sending new doc to project"
|
||||
logger.log {project_id, folder_id, docName, source}, "sending new doc to project"
|
||||
Metrics.inc "editor.add-doc"
|
||||
ProjectEntityHandler.addDoc project_id, folder_id, docName, docLines, (err, doc, folder_id)=>
|
||||
EditorRealTimeController.emitToRoom(project_id, 'reciveNewDoc', folder_id, doc)
|
||||
EditorRealTimeController.emitToRoom(project_id, 'reciveNewDoc', folder_id, doc, source)
|
||||
callback(err, doc)
|
||||
|
||||
addFile: (project_id, folder_id, fileName, path, callback = (error, file)->)->
|
||||
addFile: (project_id, folder_id, fileName, path, source, callback = (error, file)->)->
|
||||
fileName = fileName.trim()
|
||||
logger.log {project_id, folder_id, fileName, path}, "sending new file to project"
|
||||
Metrics.inc "editor.add-file"
|
||||
ProjectEntityHandler.addFile project_id, folder_id, fileName, path, (err, fileRef, folder_id)=>
|
||||
EditorRealTimeController.emitToRoom(project_id, 'reciveNewFile', folder_id, fileRef)
|
||||
EditorRealTimeController.emitToRoom(project_id, 'reciveNewFile', folder_id, fileRef, source)
|
||||
callback(err, fileRef)
|
||||
|
||||
replaceFile: (project_id, file_id, fsPath, callback = (error) ->)->
|
||||
replaceFile: (project_id, file_id, fsPath, source, callback = (error) ->)->
|
||||
ProjectEntityHandler.replaceFile project_id, file_id, fsPath, callback
|
||||
|
||||
addFolder: (project_id, folder_id, folderName, callback = (error, folder)->)->
|
||||
|
@ -203,12 +203,12 @@ module.exports = EditorController =
|
|||
async.series jobs, (err)->
|
||||
callback err, newFolders, lastFolder
|
||||
|
||||
deleteEntity: (project_id, entity_id, entityType, callback)->
|
||||
logger.log {project_id, entity_id, entityType}, "start delete process of entity"
|
||||
deleteEntity: (project_id, entity_id, entityType, source, callback)->
|
||||
logger.log {project_id, entity_id, entityType, source}, "start delete process of entity"
|
||||
Metrics.inc "editor.delete-entity"
|
||||
ProjectEntityHandler.deleteEntity project_id, entity_id, entityType, =>
|
||||
logger.log project_id:project_id, entity_id:entity_id, entityType:entityType, "telling users entity has been deleted"
|
||||
EditorRealTimeController.emitToRoom(project_id, 'removeEntity', entity_id)
|
||||
EditorRealTimeController.emitToRoom(project_id, 'removeEntity', entity_id, source)
|
||||
if callback?
|
||||
callback()
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ module.exports = EditorHttpController =
|
|||
project_id = req.params.Project_id
|
||||
name = req.body.name
|
||||
parent_folder_id = req.body.parent_folder_id
|
||||
EditorController.addDoc project_id, parent_folder_id, name, [], (error, doc) ->
|
||||
EditorController.addDoc project_id, parent_folder_id, name, [], "editor", (error, doc) ->
|
||||
return next(error) if error?
|
||||
res.json doc
|
||||
|
||||
|
@ -61,7 +61,7 @@ module.exports = EditorHttpController =
|
|||
project_id = req.params.Project_id
|
||||
entity_id = req.params.entity_id
|
||||
entity_type = req.params.entity_type
|
||||
EditorController.deleteEntity project_id, entity_id, entity_type, (error) ->
|
||||
EditorController.deleteEntity project_id, entity_id, entity_type, "editor", (error) ->
|
||||
return next(error) if error?
|
||||
res.send 204
|
||||
|
||||
|
|
|
@ -36,8 +36,9 @@ module.exports =
|
|||
updateProjectContents: (req, res, next = (error) ->) ->
|
||||
{project_id} = req.params
|
||||
path = "/" + req.params[0] # UpdateMerger expects leading slash
|
||||
logger.log project_id: project_id, path: path, "received project contents update"
|
||||
UpdateMerger.mergeUpdate project_id, path, req, (error) ->
|
||||
source = req.headers["x-sl-update-source"]
|
||||
logger.log project_id: project_id, path: path, source: source, "received project contents update"
|
||||
UpdateMerger.mergeUpdate project_id, path, req, source, (error) ->
|
||||
return next(error) if error?
|
||||
res.send(200)
|
||||
req.session.destroy()
|
||||
|
@ -45,8 +46,9 @@ module.exports =
|
|||
deleteProjectContents: (req, res, next = (error) ->) ->
|
||||
{project_id} = req.params
|
||||
path = "/" + req.params[0] # UpdateMerger expects leading slash
|
||||
logger.log project_id: project_id, path: path, "received project contents delete request"
|
||||
UpdateMerger.deleteUpdate project_id, path, (error) ->
|
||||
source = req.headers["x-sl-update-source"]
|
||||
logger.log project_id: project_id, path: path, source: source, "received project contents delete request"
|
||||
UpdateMerger.deleteUpdate project_id, path, source, (error) ->
|
||||
return next(error) if error?
|
||||
res.send(200)
|
||||
req.session.destroy()
|
||||
|
|
|
@ -8,7 +8,7 @@ uuid = require('node-uuid')
|
|||
fs = require('fs')
|
||||
|
||||
module.exports =
|
||||
mergeUpdate: (project_id, path, updateRequest, callback = (error) ->)->
|
||||
mergeUpdate: (project_id, path, updateRequest, source, callback = (error) ->)->
|
||||
self = @
|
||||
logger.log project_id:project_id, path:path, "merging update from tpds"
|
||||
projectLocator.findElementByPath project_id, path, (err, element)=>
|
||||
|
@ -22,11 +22,11 @@ module.exports =
|
|||
return callback()
|
||||
FileTypeManager.isBinary path, fsPath, (err, isFile)->
|
||||
if isFile
|
||||
self.p.processFile project_id, elementId, fsPath, path, callback #TODO clean up the stream written to disk here
|
||||
self.p.processFile project_id, elementId, fsPath, path, source, callback #TODO clean up the stream written to disk here
|
||||
else
|
||||
self.p.processDoc project_id, elementId, fsPath, path, callback
|
||||
self.p.processDoc project_id, elementId, fsPath, path, source, callback
|
||||
|
||||
deleteUpdate: (project_id, path, callback)->
|
||||
deleteUpdate: (project_id, path, source, callback)->
|
||||
projectLocator.findElementByPath project_id, path, (err, element)->
|
||||
type = 'file'
|
||||
if err? || !element?
|
||||
|
@ -37,36 +37,36 @@ module.exports =
|
|||
else if element.folders?
|
||||
type = 'folder'
|
||||
logger.log project_id:project_id, path:path, type:type, element:element, "processing update to delete entity from tpds"
|
||||
editorController.deleteEntity project_id, element._id, type, (err)->
|
||||
editorController.deleteEntity project_id, element._id, type, source, (err)->
|
||||
logger.log project_id:project_id, path:path, "finished processing update to delete entity from tpds"
|
||||
callback()
|
||||
|
||||
p:
|
||||
|
||||
processDoc: (project_id, doc_id, fsPath, path, callback)->
|
||||
processDoc: (project_id, doc_id, fsPath, path, source, callback)->
|
||||
readFileIntoTextArray fsPath, (err, docLines)->
|
||||
if err?
|
||||
logger.err project_id:project_id, doc_id:doc_id, fsPath:fsPath, "error reading file into text array for process doc update"
|
||||
return callback(err)
|
||||
logger.log docLines:docLines, doc_id:doc_id, project_id:project_id, "processing doc update from tpds"
|
||||
if doc_id?
|
||||
editorController.setDoc project_id, doc_id, docLines, (err)->
|
||||
editorController.setDoc project_id, doc_id, docLines, source, (err)->
|
||||
callback()
|
||||
else
|
||||
setupNewEntity project_id, path, (err, folder, fileName)->
|
||||
editorController.addDoc project_id, folder._id, fileName, docLines, (err)->
|
||||
editorController.addDoc project_id, folder._id, fileName, docLines, source, (err)->
|
||||
callback()
|
||||
|
||||
processFile: (project_id, file_id, fsPath, path, callback)->
|
||||
processFile: (project_id, file_id, fsPath, path, source, callback)->
|
||||
finish = (err)->
|
||||
logger.log project_id:project_id, file_id:file_id, path:path, "completed processing file update from tpds"
|
||||
callback(err)
|
||||
logger.log project_id:project_id, file_id:file_id, path:path, "processing file update from tpds"
|
||||
setupNewEntity project_id, path, (err, folder, fileName) =>
|
||||
if file_id?
|
||||
editorController.replaceFile project_id, file_id, fsPath, finish
|
||||
editorController.replaceFile project_id, file_id, fsPath, source, finish
|
||||
else
|
||||
editorController.addFile project_id, folder._id, fileName, fsPath, finish
|
||||
editorController.addFile project_id, folder._id, fileName, fsPath, source, finish
|
||||
|
||||
writeStreamToDisk: (project_id, file_id, stream, callback = (err, fsPath)->)->
|
||||
if !file_id?
|
||||
|
|
|
@ -11,7 +11,7 @@ module.exports = FileSystemImportManager =
|
|||
return callback(error) if error?
|
||||
content = content.replace(/\r/g, "")
|
||||
lines = content.split("\n")
|
||||
EditorController.addDoc project_id, folder_id, name, lines, callback
|
||||
EditorController.addDoc project_id, folder_id, name, lines, "upload", callback
|
||||
|
||||
addFile: (project_id, folder_id, name, path, replace, callback = (error, file)-> )->
|
||||
if replace
|
||||
|
@ -24,14 +24,14 @@ module.exports = FileSystemImportManager =
|
|||
existingFile = fileRef
|
||||
break
|
||||
if existingFile?
|
||||
EditorController.replaceFile project_id, existingFile._id, path, callback
|
||||
EditorController.replaceFile project_id, existingFile._id, path, "upload", callback
|
||||
else
|
||||
EditorController.addFile project_id, folder_id, name, path, callback
|
||||
EditorController.addFile project_id, folder_id, name, path, "upload", callback
|
||||
else
|
||||
EditorController.addFile project_id, folder_id, name, path, callback
|
||||
EditorController.addFile project_id, folder_id, name, path, "upload", callback
|
||||
|
||||
addFolder: (project_id, folder_id, name, path, replace, callback = (error)-> ) ->
|
||||
EditorController.addFolder project_id, folder_id, name, (error, new_folder) =>
|
||||
EditorController.addFolder project_id, folder_id, name, "upload", (error, new_folder) =>
|
||||
return callback(error) if error?
|
||||
@addFolderContents project_id, new_folder._id, path, replace, (error) ->
|
||||
return callback(error) if error?
|
||||
|
|
|
@ -14,6 +14,7 @@ describe "EditorController", ->
|
|||
|
||||
|
||||
@doc_id = "test-doc-id"
|
||||
@source = "dropbox"
|
||||
|
||||
@projectModelView = "projectModelView"
|
||||
|
||||
|
@ -419,24 +420,24 @@ describe "EditorController", ->
|
|||
|
||||
it 'should send the document to the documentUpdaterHandler', (done)->
|
||||
@DocumentUpdaterHandler.setDocument = sinon.stub().withArgs(@project_id, @doc_id, @docLines).callsArg(3)
|
||||
@EditorController.setDoc @project_id, @doc_id, @docLines, (err)->
|
||||
@EditorController.setDoc @project_id, @doc_id, @docLines, @source, (err)->
|
||||
done()
|
||||
|
||||
it 'should send the update to the connected users', (done)->
|
||||
@EditorController.setDoc @project_id, @doc_id, @docLines, (err)=>
|
||||
@EditorRealTimeController.emitToRoom.calledWith(@project_id, "entireDocUpdate", @doc_id).should.equal true
|
||||
@EditorController.setDoc @project_id, @doc_id, @docLines, @source, (err)=>
|
||||
@EditorRealTimeController.emitToRoom.calledWith(@project_id, "entireDocUpdate", @doc_id, @source).should.equal true
|
||||
done()
|
||||
|
||||
it 'should send the new doc lines to the doucment updater', (done)->
|
||||
@DocumentUpdaterHandler.setDocument = ->
|
||||
mock = sinon.mock(@DocumentUpdaterHandler).expects("setDocument").withArgs(@project_id, @doc_id, @docLines).once().callsArg(3)
|
||||
|
||||
@EditorController.setDoc @project_id, @doc_id, @docLines, (err)=>
|
||||
@EditorController.setDoc @project_id, @doc_id, @docLines, @source, (err)=>
|
||||
mock.verify()
|
||||
done()
|
||||
|
||||
it 'should flush the doc to mongo', (done)->
|
||||
@EditorController.setDoc @project_id, @doc_id, @docLines, (err)=>
|
||||
@EditorController.setDoc @project_id, @doc_id, @docLines, @source, (err)=>
|
||||
@DocumentUpdaterHandler.flushDocToMongo.calledWith(@project_id, @doc_id).should.equal true
|
||||
done()
|
||||
|
||||
|
@ -455,22 +456,22 @@ describe "EditorController", ->
|
|||
it 'should add the doc using the project entity handler', (done)->
|
||||
mock = sinon.mock(@ProjectEntityHandler).expects("addDoc").withArgs(@project_id, @folder_id, @docName, @docLines).callsArg(4)
|
||||
|
||||
@EditorController.addDoc @project_id, @folder_id, @docName, @docLines, ->
|
||||
@EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, ->
|
||||
mock.verify()
|
||||
done()
|
||||
|
||||
it 'should send the update out to the users in the project', (done)->
|
||||
@ProjectEntityHandler.addDoc = sinon.stub().callsArgWith(4, null, @doc, @folder_id)
|
||||
|
||||
@EditorController.addDoc @project_id, @folder_id, @docName, @docLines, =>
|
||||
@EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, =>
|
||||
@EditorRealTimeController.emitToRoom
|
||||
.calledWith(@project_id, "reciveNewDoc", @folder_id, @doc)
|
||||
.calledWith(@project_id, "reciveNewDoc", @folder_id, @doc, @source)
|
||||
.should.equal true
|
||||
done()
|
||||
|
||||
it 'should return the doc to the callback', (done) ->
|
||||
@ProjectEntityHandler.addDoc = sinon.stub().callsArgWith(4, null, @doc, @folder_id)
|
||||
@EditorController.addDoc @project_id, @folder_id, @docName, @docLines, (error, doc) =>
|
||||
@EditorController.addDoc @project_id, @folder_id, @docName, @docLines, @source, (error, doc) =>
|
||||
doc.should.equal @doc
|
||||
done()
|
||||
|
||||
|
@ -487,22 +488,22 @@ describe "EditorController", ->
|
|||
|
||||
it 'should add the folder using the project entity handler', (done)->
|
||||
mock = sinon.mock(@ProjectEntityHandler).expects("addFile").withArgs(@project_id).callsArg(4)
|
||||
@EditorController.addFile @project_id, @folder_id, @fileName, @stream, =>
|
||||
@EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, =>
|
||||
mock.verify()
|
||||
done()
|
||||
|
||||
it 'should send the update of a new folder out to the users in the project', (done)->
|
||||
@ProjectEntityHandler.addFile = sinon.stub().callsArgWith(4, null, @file, @folder_id)
|
||||
|
||||
@EditorController.addFile @project_id, @folder_id, @fileName, @stream, =>
|
||||
@EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, =>
|
||||
@EditorRealTimeController.emitToRoom
|
||||
.calledWith(@project_id, "reciveNewFile", @folder_id, @file)
|
||||
.calledWith(@project_id, "reciveNewFile", @folder_id, @file, @source)
|
||||
.should.equal true
|
||||
done()
|
||||
|
||||
it "should return the file in the callback", (done) ->
|
||||
@ProjectEntityHandler.addFile = sinon.stub().callsArgWith(4, null, @file, @folder_id)
|
||||
@EditorController.addFile @project_id, @folder_id, @fileName, @stream, (error, file) =>
|
||||
@EditorController.addFile @project_id, @folder_id, @fileName, @stream, @source, (error, file) =>
|
||||
file.should.equal @file
|
||||
done()
|
||||
|
||||
|
@ -515,7 +516,7 @@ describe "EditorController", ->
|
|||
|
||||
it 'should send the replace file message to the editor controller', (done)->
|
||||
@ProjectEntityHandler.replaceFile = sinon.stub().callsArgWith(3)
|
||||
@EditorController.replaceFile @project_id, @file_id, @fsPath, =>
|
||||
@EditorController.replaceFile @project_id, @file_id, @fsPath, @source, =>
|
||||
@ProjectEntityHandler.replaceFile.calledWith(@project_id, @file_id, @fsPath).should.equal true
|
||||
done()
|
||||
|
||||
|
@ -585,14 +586,14 @@ describe "EditorController", ->
|
|||
it 'should delete the folder using the project entity handler', (done)->
|
||||
mock = sinon.mock(@ProjectEntityHandler).expects("deleteEntity").withArgs(@project_id, @entity_id, @type).callsArg(3)
|
||||
|
||||
@EditorController.deleteEntity @project_id, @entity_id, @type, ->
|
||||
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, ->
|
||||
mock.verify()
|
||||
done()
|
||||
|
||||
it 'notify users an entity has been deleted', (done)->
|
||||
@EditorController.deleteEntity @project_id, @entity_id, @type, =>
|
||||
@EditorController.deleteEntity @project_id, @entity_id, @type, @source, =>
|
||||
@EditorRealTimeController.emitToRoom
|
||||
.calledWith(@project_id, "removeEntity", @entity_id)
|
||||
.calledWith(@project_id, "removeEntity", @entity_id, @source)
|
||||
.should.equal true
|
||||
done()
|
||||
|
||||
|
|
|
@ -55,12 +55,12 @@ describe "EditorHttpController", ->
|
|||
@req.body =
|
||||
name: @name = "doc-name"
|
||||
parent_folder_id: @parent_folder_id
|
||||
@EditorController.addDoc = sinon.stub().callsArgWith(4, null, @doc)
|
||||
@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, [])
|
||||
.calledWith(@project_id, @parent_folder_id, @name, [], "editor")
|
||||
.should.equal true
|
||||
|
||||
it "should send the doc back as JSON", ->
|
||||
|
@ -147,12 +147,12 @@ describe "EditorHttpController", ->
|
|||
Project_id: @project_id
|
||||
entity_id: @entity_id = "entity-id-123"
|
||||
entity_type: @entity_type = "entity-type"
|
||||
@EditorController.deleteEntity = sinon.stub().callsArg(3)
|
||||
@EditorController.deleteEntity = sinon.stub().callsArg(4)
|
||||
@EditorHttpController.deleteEntity @req, @res
|
||||
|
||||
it "should call EditorController.deleteEntity", ->
|
||||
@EditorController.deleteEntity
|
||||
.calledWith(@project_id, @entity_id, @entity_type)
|
||||
.calledWith(@project_id, @entity_id, @entity_type, "editor")
|
||||
.should.equal true
|
||||
|
||||
it "should send back a success response", ->
|
||||
|
|
|
@ -72,7 +72,7 @@ describe 'TpdsController', ->
|
|||
|
||||
describe 'updateProjectContents', ->
|
||||
beforeEach ->
|
||||
@UpdateMerger.mergeUpdate = sinon.stub().callsArg(3)
|
||||
@UpdateMerger.mergeUpdate = sinon.stub().callsArg(4)
|
||||
@req =
|
||||
params:
|
||||
0: @path = "chapters/main.tex"
|
||||
|
@ -80,7 +80,7 @@ describe 'TpdsController', ->
|
|||
session:
|
||||
destroy: sinon.stub()
|
||||
headers:
|
||||
"x-update-source": @source = "github"
|
||||
"x-sl-update-source": @source = "github"
|
||||
@res =
|
||||
send: sinon.stub()
|
||||
|
||||
|
@ -88,7 +88,7 @@ describe 'TpdsController', ->
|
|||
|
||||
it "should merge the update", ->
|
||||
@UpdateMerger.mergeUpdate
|
||||
.calledWith(@project_id, "/" + @path, @req)
|
||||
.calledWith(@project_id, "/" + @path, @req, @source)
|
||||
.should.equal true
|
||||
|
||||
it "should return a success", ->
|
||||
|
@ -99,7 +99,7 @@ describe 'TpdsController', ->
|
|||
|
||||
describe 'deleteProjectContents', ->
|
||||
beforeEach ->
|
||||
@UpdateMerger.deleteUpdate = sinon.stub().callsArg(2)
|
||||
@UpdateMerger.deleteUpdate = sinon.stub().callsArg(3)
|
||||
@req =
|
||||
params:
|
||||
0: @path = "chapters/main.tex"
|
||||
|
@ -107,7 +107,7 @@ describe 'TpdsController', ->
|
|||
session:
|
||||
destroy: sinon.stub()
|
||||
headers:
|
||||
"x-update-source": @source = "github"
|
||||
"x-sl-update-source": @source = "github"
|
||||
@res =
|
||||
send: sinon.stub()
|
||||
|
||||
|
@ -115,7 +115,7 @@ describe 'TpdsController', ->
|
|||
|
||||
it "should delete the file", ->
|
||||
@UpdateMerger.deleteUpdate
|
||||
.calledWith(@project_id, "/" + @path)
|
||||
.calledWith(@project_id, "/" + @path, @source)
|
||||
.should.equal true
|
||||
|
||||
it "should return a success", ->
|
||||
|
|
|
@ -39,7 +39,7 @@ describe 'UpdateMerger :', ->
|
|||
|
||||
@projectLocator.findElementByPath = sinon.spy()
|
||||
|
||||
@updateMerger.mergeUpdate @project_id, @path, @update, =>
|
||||
@updateMerger.mergeUpdate @project_id, @path, @update, @source, =>
|
||||
|
||||
@projectLocator.findElementByPath.calledWith(@project_id, @path).should.equal true
|
||||
done()
|
||||
|
@ -49,7 +49,7 @@ describe 'UpdateMerger :', ->
|
|||
filePath = ".gitignore"
|
||||
@projectLocator.findElementByPath = (_, __, cb)->cb(null, {_id:"id"})
|
||||
@FileTypeManager.shouldIgnore.callsArgWith(1, null, true)
|
||||
@updateMerger.mergeUpdate @project_id, filePath, @update, =>
|
||||
@updateMerger.mergeUpdate @project_id, filePath, @update, @source, =>
|
||||
@FileTypeManager.isBinary.called.should.equal false
|
||||
@FileTypeManager.shouldIgnore.calledWith(filePath).should.equal true
|
||||
done()
|
||||
|
@ -60,12 +60,12 @@ describe 'UpdateMerger :', ->
|
|||
@FileTypeManager.isBinary.callsArgWith(2, null, false)
|
||||
@projectLocator.findElementByPath = (_, __, cb)->cb(null, {_id:doc_id})
|
||||
@FileTypeManager.shouldIgnore.callsArgWith(1, null, false)
|
||||
@updateMerger.p.processDoc = sinon.stub().callsArgWith(4)
|
||||
@updateMerger.p.processDoc = sinon.stub().callsArgWith(5)
|
||||
filePath = "/folder/doc.tex"
|
||||
|
||||
@updateMerger.mergeUpdate @project_id, filePath, @update, =>
|
||||
@updateMerger.mergeUpdate @project_id, filePath, @update, @source, =>
|
||||
@FileTypeManager.isBinary.calledWith(filePath, @fsPath).should.equal true
|
||||
@updateMerger.p.processDoc.calledWith(@project_id, doc_id, @fsPath, filePath).should.equal true
|
||||
@updateMerger.p.processDoc.calledWith(@project_id, doc_id, @fsPath, filePath, @source).should.equal true
|
||||
done()
|
||||
|
||||
it 'should process update as file when it is not a doc', (done)->
|
||||
|
@ -73,11 +73,11 @@ describe 'UpdateMerger :', ->
|
|||
@projectLocator.findElementByPath = (_, __, cb)->cb(null, {_id:file_id})
|
||||
@FileTypeManager.isBinary.callsArgWith(2, null, true)
|
||||
@FileTypeManager.shouldIgnore.callsArgWith(1, null, false)
|
||||
@updateMerger.p.processFile = sinon.stub().callsArgWith(4)
|
||||
@updateMerger.p.processFile = sinon.stub().callsArgWith(5)
|
||||
filePath = "/folder/file1.png"
|
||||
|
||||
@updateMerger.mergeUpdate @project_id, filePath, @update, =>
|
||||
@updateMerger.p.processFile.calledWith(@project_id, file_id, @fsPath, filePath).should.equal true
|
||||
@updateMerger.mergeUpdate @project_id, filePath, @update, @source, =>
|
||||
@updateMerger.p.processFile.calledWith(@project_id, file_id, @fsPath, filePath, @source).should.equal true
|
||||
@FileTypeManager.isBinary.calledWith(filePath, @fsPath).should.equal true
|
||||
done()
|
||||
|
||||
|
@ -91,12 +91,12 @@ describe 'UpdateMerger :', ->
|
|||
|
||||
it 'should set the doc text in the editor controller', (done)->
|
||||
@editorController.setDoc = ->
|
||||
mock = sinon.mock(@editorController).expects("setDoc").withArgs(@project_id, @doc_id, @splitDocLines).callsArg(3)
|
||||
mock = sinon.mock(@editorController).expects("setDoc").withArgs(@project_id, @doc_id, @splitDocLines, @source).callsArg(4)
|
||||
|
||||
@update.write(@docLines)
|
||||
@update.end()
|
||||
|
||||
@updateMerger.p.processDoc @project_id, @doc_id, @update, "path", ->
|
||||
@updateMerger.p.processDoc @project_id, @doc_id, @update, "path", @source, ->
|
||||
mock.verify()
|
||||
done()
|
||||
|
||||
|
@ -106,12 +106,12 @@ describe 'UpdateMerger :', ->
|
|||
path = "folder1/folder2/#{docName}"
|
||||
@editorController.mkdirp = sinon.stub().withArgs(@project_id).callsArgWith(2, null, [folder], folder)
|
||||
@editorController.addDoc = ->
|
||||
mock = sinon.mock(@editorController).expects("addDoc").withArgs(@project_id, folder._id, docName, @splitDocLines).callsArg(4)
|
||||
mock = sinon.mock(@editorController).expects("addDoc").withArgs(@project_id, folder._id, docName, @splitDocLines, @source).callsArg(5)
|
||||
|
||||
@update.write(@docLines)
|
||||
@update.end()
|
||||
|
||||
@updateMerger.p.processDoc @project_id, undefined, @update, path, ->
|
||||
@updateMerger.p.processDoc @project_id, undefined, @update, path, @source, ->
|
||||
mock.verify()
|
||||
done()
|
||||
|
||||
|
@ -123,22 +123,22 @@ describe 'UpdateMerger :', ->
|
|||
@folder = _id: @folder_id
|
||||
@fileName = "file.png"
|
||||
@fsPath = "fs/path.tex"
|
||||
@editorController.addFile = sinon.stub().callsArg(4)
|
||||
@editorController.replaceFile = sinon.stub().callsArg(3)
|
||||
@editorController.addFile = sinon.stub().callsArg(5)
|
||||
@editorController.replaceFile = sinon.stub().callsArg(4)
|
||||
@editorController.deleteEntity = sinon.stub()
|
||||
@editorController.mkdirp = sinon.stub().withArgs(@project_id).callsArgWith(2, null, [@folder], @folder)
|
||||
@updateMerger.p.writeStreamToDisk = sinon.stub().withArgs(@project_id, @file_id, @update).callsArgWith(3, null, @fsPath)
|
||||
|
||||
it 'should replace file if the file already exists', (done)->
|
||||
@updateMerger.p.processFile @project_id, @file_id, @fsPath, @path, =>
|
||||
@updateMerger.p.processFile @project_id, @file_id, @fsPath, @path, @source, =>
|
||||
@editorController.addFile.called.should.equal false
|
||||
@editorController.replaceFile.calledWith(@project_id, @file_id, @fsPath).should.equal true
|
||||
@editorController.replaceFile.calledWith(@project_id, @file_id, @fsPath, @source).should.equal true
|
||||
done()
|
||||
|
||||
it 'should call add file if the file does not exist', (done)->
|
||||
@updateMerger.p.processFile @project_id, undefined, @fsPath, @path, =>
|
||||
@updateMerger.p.processFile @project_id, undefined, @fsPath, @path, @source, =>
|
||||
@editorController.mkdirp.calledWith(@project_id, "folder/").should.equal true
|
||||
@editorController.addFile.calledWith(@project_id, @folder_id, @fileName, @fsPath).should.equal true
|
||||
@editorController.addFile.calledWith(@project_id, @folder_id, @fileName, @fsPath, @source).should.equal true
|
||||
@editorController.replaceFile.called.should.equal false
|
||||
done()
|
||||
|
||||
|
@ -153,26 +153,26 @@ describe 'UpdateMerger :', ->
|
|||
|
||||
it 'should get the element id', ->
|
||||
@projectLocator.findElementByPath = sinon.spy()
|
||||
@updateMerger.deleteUpdate @project_id, @path, ->
|
||||
@updateMerger.deleteUpdate @project_id, @path, @source, ->
|
||||
@projectLocator.findElementByPath.calledWith(@project_id, @path).should.equal true
|
||||
|
||||
it 'should delete the entity in the editor controller with type doc when entity has docLines array', (done)->
|
||||
@entity.lines = []
|
||||
mock = sinon.mock(@editorController).expects("deleteEntity").withArgs(@project_id, @entity_id, "doc").callsArg(3)
|
||||
@updateMerger.deleteUpdate @project_id, @path, ->
|
||||
mock = sinon.mock(@editorController).expects("deleteEntity").withArgs(@project_id, @entity_id, "doc", @source).callsArg(4)
|
||||
@updateMerger.deleteUpdate @project_id, @path, @source, ->
|
||||
mock.verify()
|
||||
done()
|
||||
|
||||
it 'should delete the entity in the editor controller with type folder when entity has folders array', (done)->
|
||||
@entity.folders = []
|
||||
mock = sinon.mock(@editorController).expects("deleteEntity").withArgs(@project_id, @entity_id, "folder").callsArg(3)
|
||||
@updateMerger.deleteUpdate @project_id, @path, ->
|
||||
mock = sinon.mock(@editorController).expects("deleteEntity").withArgs(@project_id, @entity_id, "folder", @source).callsArg(4)
|
||||
@updateMerger.deleteUpdate @project_id, @path, @source, ->
|
||||
mock.verify()
|
||||
done()
|
||||
|
||||
it 'should delete the entity in the editor controller with type file when entity has no interesting properties', (done)->
|
||||
mock = sinon.mock(@editorController).expects("deleteEntity").withArgs(@project_id, @entity_id, "file").callsArg(3)
|
||||
@updateMerger.deleteUpdate @project_id, @path, ->
|
||||
mock = sinon.mock(@editorController).expects("deleteEntity").withArgs(@project_id, @entity_id, "file", @source).callsArg(4)
|
||||
@updateMerger.deleteUpdate @project_id, @path, @source, ->
|
||||
mock.verify()
|
||||
done()
|
||||
|
||||
|
|
|
@ -22,14 +22,14 @@ describe "FileSystemImportManager", ->
|
|||
@docContent = "one\ntwo\nthree"
|
||||
@docLines = @docContent.split("\n")
|
||||
@fs.readFile = sinon.stub().callsArgWith(2, null, @docContent)
|
||||
@EditorController.addDoc = sinon.stub().callsArg(4)
|
||||
@EditorController.addDoc = sinon.stub().callsArg(5)
|
||||
@FileSystemImportManager.addDoc @project_id, @folder_id, @name, @path_on_disk, false, @callback
|
||||
|
||||
it "should read the file from disk", ->
|
||||
@fs.readFile.calledWith(@path_on_disk, "utf8").should.equal true
|
||||
|
||||
it "should insert the doc", ->
|
||||
@EditorController.addDoc.calledWith(@project_id, @folder_id, @name, @docLines)
|
||||
@EditorController.addDoc.calledWith(@project_id, @folder_id, @name, @docLines, "upload")
|
||||
.should.equal true
|
||||
|
||||
describe "addDoc with windows line ending", ->
|
||||
|
@ -37,20 +37,20 @@ describe "FileSystemImportManager", ->
|
|||
@docContent = "one\r\ntwo\r\nthree"
|
||||
@docLines = ["one", "two", "three"]
|
||||
@fs.readFile = sinon.stub().callsArgWith(2, null, @docContent)
|
||||
@EditorController.addDoc = sinon.stub().callsArg(4)
|
||||
@EditorController.addDoc = sinon.stub().callsArg(5)
|
||||
@FileSystemImportManager.addDoc @project_id, @folder_id, @name, @path_on_disk, false, @callback
|
||||
|
||||
it "should strip the \\r characters before adding", ->
|
||||
@EditorController.addDoc.calledWith(@project_id, @folder_id, @name, @docLines)
|
||||
@EditorController.addDoc.calledWith(@project_id, @folder_id, @name, @docLines, "upload")
|
||||
.should.equal true
|
||||
|
||||
describe "addFile with replace set to false", ->
|
||||
beforeEach ->
|
||||
@EditorController.addFile = sinon.stub().callsArg(4)
|
||||
@EditorController.addFile = sinon.stub().callsArg(5)
|
||||
@FileSystemImportManager.addFile @project_id, @folder_id, @name, @path_on_disk, false, @callback
|
||||
|
||||
it "should add the file", ->
|
||||
@EditorController.addFile.calledWith(@project_id, @folder_id, @name, @path_on_disk)
|
||||
@EditorController.addFile.calledWith(@project_id, @folder_id, @name, @path_on_disk, "upload")
|
||||
.should.equal true
|
||||
|
||||
describe "addFile with replace set to true", ->
|
||||
|
@ -63,7 +63,7 @@ describe "FileSystemImportManager", ->
|
|||
}]
|
||||
}
|
||||
@ProjectLocator.findElement = sinon.stub().callsArgWith(1, null, @folder)
|
||||
@EditorController.addFile = sinon.stub().callsArg(4)
|
||||
@EditorController.addFile = sinon.stub().callsArg(5)
|
||||
@FileSystemImportManager.addFile @project_id, @folder_id, @name, @path_on_disk, true, @callback
|
||||
|
||||
it "should look up the folder", ->
|
||||
|
@ -72,7 +72,7 @@ describe "FileSystemImportManager", ->
|
|||
.should.equal true
|
||||
|
||||
it "should add the file", ->
|
||||
@EditorController.addFile.calledWith(@project_id, @folder_id, @name, @path_on_disk)
|
||||
@EditorController.addFile.calledWith(@project_id, @folder_id, @name, @path_on_disk, "upload")
|
||||
.should.equal true
|
||||
|
||||
describe "when the file does exist", ->
|
||||
|
@ -87,7 +87,7 @@ describe "FileSystemImportManager", ->
|
|||
}]
|
||||
}
|
||||
@ProjectLocator.findElement = sinon.stub().callsArgWith(1, null, @folder)
|
||||
@EditorController.replaceFile = sinon.stub().callsArg(3)
|
||||
@EditorController.replaceFile = sinon.stub().callsArg(4)
|
||||
@FileSystemImportManager.addFile @project_id, @folder_id, @name, @path_on_disk, true, @callback
|
||||
|
||||
it "should look up the folder", ->
|
||||
|
@ -96,18 +96,18 @@ describe "FileSystemImportManager", ->
|
|||
.should.equal true
|
||||
|
||||
it "should replace the file", ->
|
||||
@EditorController.replaceFile.calledWith(@project_id, @file_id, @path_on_disk)
|
||||
@EditorController.replaceFile.calledWith(@project_id, @file_id, @path_on_disk, "upload")
|
||||
.should.equal true
|
||||
|
||||
describe "addFolder", ->
|
||||
beforeEach ->
|
||||
@new_folder_id = "new-folder-id"
|
||||
@EditorController.addFolder = sinon.stub().callsArgWith(3, null, _id: @new_folder_id)
|
||||
@EditorController.addFolder = sinon.stub().callsArgWith(4, null, _id: @new_folder_id)
|
||||
@FileSystemImportManager.addFolderContents = sinon.stub().callsArg(4)
|
||||
@FileSystemImportManager.addFolder @project_id, @folder_id, @name, @path_on_disk, @replace, @callback
|
||||
|
||||
it "should add a folder to the project", ->
|
||||
@EditorController.addFolder.calledWith(@project_id, @folder_id, @name)
|
||||
@EditorController.addFolder.calledWith(@project_id, @folder_id, @name, "upload")
|
||||
.should.equal true
|
||||
|
||||
it "should add the folders contents", ->
|
||||
|
|
Loading…
Reference in a new issue