Forráskód Böngészése

group together private in UpdateMerger tests

Hayden Faulds 8 éve
szülő
commit
a6666bee62

+ 67 - 67
services/web/test/unit/coffee/ThirdPartyDataStore/UpdateMergerTests.coffee

@@ -11,7 +11,7 @@ describe 'UpdateMerger :', ->
 		@updateReciver = {}
 		@updateReciver = {}
 		@projectLocator = {}
 		@projectLocator = {}
 		@projectEntityHandler = {}
 		@projectEntityHandler = {}
-		@fs = 
+		@fs =
 			unlink:sinon.stub().callsArgWith(1)
 			unlink:sinon.stub().callsArgWith(1)
 		@FileTypeManager = {}
 		@FileTypeManager = {}
 		@LockManager =
 		@LockManager =
@@ -26,7 +26,7 @@ describe 'UpdateMerger :', ->
 			'logger-sharelatex':
 			'logger-sharelatex':
 				log: ->
 				log: ->
 				err: ->
 				err: ->
-			"metrics-sharelatex": 
+			"metrics-sharelatex":
 				Timer:->
 				Timer:->
 					done:->
 					done:->
 			"../../infrastructure/LockManager":@LockManager
 			"../../infrastructure/LockManager":@LockManager
@@ -36,7 +36,7 @@ describe 'UpdateMerger :', ->
 		@update = new BufferedStream()
 		@update = new BufferedStream()
 		@update.headers = {}
 		@update.headers = {}
 
 
-	describe 'mergeUpdate :', ->
+	describe 'mergeUpdate', ->
 		beforeEach ->
 		beforeEach ->
 			@path = "/doc1"
 			@path = "/doc1"
 			@fsPath = "file/system/path.tex"
 			@fsPath = "file/system/path.tex"
@@ -75,70 +75,7 @@ describe 'UpdateMerger :', ->
 				@fs.unlink.calledWith(@fsPath).should.equal true
 				@fs.unlink.calledWith(@fsPath).should.equal true
 				done()
 				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 ->
 		beforeEach ->
 			@path = "folder/doc1"
 			@path = "folder/doc1"
 			@type = "mock-type"
 			@type = "mock-type"
@@ -160,3 +97,66 @@ describe 'UpdateMerger :', ->
 					.calledWith(@project_id, @entity_id, @type, @source, @user_id)
 					.calledWith(@project_id, @entity_id, @type, @source, @user_id)
 					.should.equal true
 					.should.equal true
 				done()
 				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()