From a6666bee62c5d2dd7a225f38196cd9372a8ab9f7 Mon Sep 17 00:00:00 2001 From: Hayden Faulds Date: Mon, 29 Jan 2018 12:46:21 +0000 Subject: [PATCH] group together private in UpdateMerger tests --- .../UpdateMergerTests.coffee | 134 +++++++++--------- 1 file changed, 67 insertions(+), 67 deletions(-) diff --git a/services/web/test/unit/coffee/ThirdPartyDataStore/UpdateMergerTests.coffee b/services/web/test/unit/coffee/ThirdPartyDataStore/UpdateMergerTests.coffee index 1230e2cc2e..2f65886f3a 100644 --- a/services/web/test/unit/coffee/ThirdPartyDataStore/UpdateMergerTests.coffee +++ b/services/web/test/unit/coffee/ThirdPartyDataStore/UpdateMergerTests.coffee @@ -11,7 +11,7 @@ describe 'UpdateMerger :', -> @updateReciver = {} @projectLocator = {} @projectEntityHandler = {} - @fs = + @fs = unlink:sinon.stub().callsArgWith(1) @FileTypeManager = {} @LockManager = @@ -26,7 +26,7 @@ describe 'UpdateMerger :', -> 'logger-sharelatex': log: -> err: -> - "metrics-sharelatex": + "metrics-sharelatex": Timer:-> done:-> "../../infrastructure/LockManager":@LockManager @@ -36,7 +36,7 @@ describe 'UpdateMerger :', -> @update = new BufferedStream() @update.headers = {} - describe 'mergeUpdate :', -> + describe 'mergeUpdate', -> beforeEach -> @path = "/doc1" @fsPath = "file/system/path.tex" @@ -75,70 +75,7 @@ describe 'UpdateMerger :', -> @fs.unlink.calledWith(@fsPath).should.equal true done() - - describe 'processDoc :', (done)-> - beforeEach -> - @doc_id = "312312klnkld" - @docLines = "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\\title{42}\n\\author{Jane Doe}\n\\date{June 2011}" - @splitDocLines = @docLines.split("\n") - @fs.readFile = sinon.stub().callsArgWith(2, null, @docLines) - - @editorController.setDoc = sinon.stub().callsArg(5) - - @update.write(@docLines) - @update.end() - - it 'should set the doc text in the editor controller', (done)-> - @updateMerger.p.processDoc @project_id, @doc_id, @user_id, @update, "path", @source, => - @editorController.setDoc - .calledWith(@project_id, @doc_id, @user_id, @splitDocLines, @source) - .should.equal true - done() - - it 'should create a new doc when it doesnt exist', (done)-> - folder = {_id:"adslkjioj"} - docName = "main.tex" - path = "folder1/folder2/#{docName}" - @editorController.mkdirpWithoutLock = sinon.stub().callsArgWith(2, null, [folder], folder) - @editorController.addDocWithoutLock = sinon.stub().callsArg(6) - - @updateMerger.p.processDoc @project_id, undefined, @user_id, @update, path, @source, => - @editorController.mkdirpWithoutLock - .calledWith(@project_id) - .should.equal true - @editorController.addDocWithoutLock - .calledWith(@project_id, folder._id, docName, @splitDocLines, @source, @user_id) - .should.equal true - done() - - describe 'processFile :', (done)-> - beforeEach -> - @file_id = "file_id_here" - @folder_id = "folder_id_here" - @path = "folder/file.png" - @folder = _id: @folder_id - @fileName = "file.png" - @fsPath = "fs/path.tex" - @editorController.addFileWithoutLock = sinon.stub().callsArg(6) - @editorController.replaceFileWithoutLock = sinon.stub().callsArg(5) - @editorController.deleteEntityWithoutLock = sinon.stub() - @editorController.mkdirpWithoutLock = 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, @source, @user_id, => - @editorController.addFileWithoutLock.called.should.equal false - @editorController.replaceFileWithoutLock.calledWith(@project_id, @file_id, @fsPath, @source, @user_id).should.equal true - done() - - it 'should call add file if the file does not exist', (done)-> - @updateMerger.p.processFile @project_id, undefined, @fsPath, @path, @source, @user_id, => - @editorController.mkdirpWithoutLock.calledWith(@project_id, "folder/").should.equal true - @editorController.addFileWithoutLock.calledWith(@project_id, @folder_id, @fileName, @fsPath, @source, @user_id).should.equal true - @editorController.replaceFileWithoutLock.called.should.equal false - done() - - describe 'delete entity :', (done)-> + describe 'deleteUpdate', (done)-> beforeEach -> @path = "folder/doc1" @type = "mock-type" @@ -160,3 +97,66 @@ describe 'UpdateMerger :', -> .calledWith(@project_id, @entity_id, @type, @source, @user_id) .should.equal true done() + + describe 'private methods', () -> + describe 'processDoc', (done)-> + beforeEach -> + @doc_id = "312312klnkld" + @docLines = "\\documentclass{article}\n\\usepackage[utf8]{inputenc}\n\n\\title{42}\n\\author{Jane Doe}\n\\date{June 2011}" + @splitDocLines = @docLines.split("\n") + @fs.readFile = sinon.stub().callsArgWith(2, null, @docLines) + + @editorController.setDoc = sinon.stub().callsArg(5) + + @update.write(@docLines) + @update.end() + + it 'should set the doc text in the editor controller', (done)-> + @updateMerger.p.processDoc @project_id, @doc_id, @user_id, @update, "path", @source, => + @editorController.setDoc + .calledWith(@project_id, @doc_id, @user_id, @splitDocLines, @source) + .should.equal true + done() + + it 'should create a new doc when it doesnt exist', (done)-> + folder = {_id:"adslkjioj"} + docName = "main.tex" + path = "folder1/folder2/#{docName}" + @editorController.mkdirpWithoutLock = sinon.stub().callsArgWith(2, null, [folder], folder) + @editorController.addDocWithoutLock = sinon.stub().callsArg(6) + + @updateMerger.p.processDoc @project_id, undefined, @user_id, @update, path, @source, => + @editorController.mkdirpWithoutLock + .calledWith(@project_id) + .should.equal true + @editorController.addDocWithoutLock + .calledWith(@project_id, folder._id, docName, @splitDocLines, @source, @user_id) + .should.equal true + done() + + describe 'processFile', (done)-> + beforeEach -> + @file_id = "file_id_here" + @folder_id = "folder_id_here" + @path = "folder/file.png" + @folder = _id: @folder_id + @fileName = "file.png" + @fsPath = "fs/path.tex" + @editorController.addFileWithoutLock = sinon.stub().callsArg(6) + @editorController.replaceFileWithoutLock = sinon.stub().callsArg(5) + @editorController.deleteEntityWithoutLock = sinon.stub() + @editorController.mkdirpWithoutLock = 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, @source, @user_id, => + @editorController.addFileWithoutLock.called.should.equal false + @editorController.replaceFileWithoutLock.calledWith(@project_id, @file_id, @fsPath, @source, @user_id).should.equal true + done() + + it 'should call add file if the file does not exist', (done)-> + @updateMerger.p.processFile @project_id, undefined, @fsPath, @path, @source, @user_id, => + @editorController.mkdirpWithoutLock.calledWith(@project_id, "folder/").should.equal true + @editorController.addFileWithoutLock.calledWith(@project_id, @folder_id, @fileName, @fsPath, @source, @user_id).should.equal true + @editorController.replaceFileWithoutLock.called.should.equal false + done()