Kaynağa Gözat

Fix UpdateManager tests

James Allen 10 yıl önce
ebeveyn
işleme
e7ff05e792

+ 76 - 3
services/document-updater/test/unit/coffee/UpdateManager/ApplyingUpdates.coffee

@@ -14,12 +14,14 @@ describe "UpdateManager", ->
 			"./RedisManager" : @RedisManager = {}
 			"./WebRedisManager" : @WebRedisManager = {}
 			"./ShareJsUpdateManager" : @ShareJsUpdateManager = {}
-			"./TrackChangesManager" : @TrackChangesManager = {}
+			"./HistoryManager" : @HistoryManager = {}
 			"logger-sharelatex": @logger = { log: sinon.stub() }
 			"./Metrics": @Metrics =
 				Timer: class Timer
 					done: sinon.stub()
 			"settings-sharelatex": Settings = {}
+			"./DocumentManager": @DocumentManager = {}
+			"./TrackChangesManager": @TrackChangesManager = {}
 
 	describe "processOutstandingUpdates", ->
 		beforeEach ->
@@ -158,7 +160,7 @@ describe "UpdateManager", ->
 			@appliedOps = ["mock-applied-ops"]
 			@ShareJsUpdateManager.applyUpdate = sinon.stub().callsArgWith(3, null, @updatedDocLines, @version, @appliedOps)
 			@RedisManager.updateDocument = sinon.stub().callsArg(4)
-			@TrackChangesManager.pushUncompressedHistoryOps = sinon.stub().callsArg(3)
+			@HistoryManager.pushUncompressedHistoryOps = sinon.stub().callsArg(3)
 		
 		describe "normally", ->
 			beforeEach ->
@@ -175,7 +177,7 @@ describe "UpdateManager", ->
 					.should.equal true
 			
 			it "should push the applied ops into the track changes queue", ->
-				@TrackChangesManager.pushUncompressedHistoryOps
+				@HistoryManager.pushUncompressedHistoryOps
 					.calledWith(@project_id, @doc_id, @appliedOps)
 					.should.equal true
 
@@ -195,3 +197,74 @@ describe "UpdateManager", ->
 				# \uFFFD is 'replacement character'
 				@update.op[0].i.should.equal "\uFFFD\uFFFD"
 
+	describe "lockUpdatesAndDo", ->
+		beforeEach ->
+			@method = sinon.stub().callsArgWith(3, null, @response_arg1)
+			@callback = sinon.stub()
+			@arg1 = "argument 1"
+			@response_arg1 = "response argument 1"
+			@lockValue = "mock-lock-value"
+			@LockManager.getLock = sinon.stub().callsArgWith(1, null, @lockValue)
+			@LockManager.releaseLock = sinon.stub().callsArg(2)
+
+		describe "successfully", ->
+			beforeEach ->
+				@UpdateManager.continueProcessingUpdatesWithLock = sinon.stub()
+				@UpdateManager.processOutstandingUpdates = sinon.stub().callsArg(2)
+				@UpdateManager.lockUpdatesAndDo @method, @project_id, @doc_id, @arg1, @callback
+
+			it "should lock the doc", ->
+				@LockManager.getLock
+					.calledWith(@doc_id)
+					.should.equal true
+
+			it "should process any outstanding updates", ->
+				@UpdateManager.processOutstandingUpdates
+					.calledWith(@project_id, @doc_id)
+					.should.equal true
+
+			it "should call the method", ->
+				@method
+					.calledWith(@project_id, @doc_id, @arg1)
+					.should.equal true
+
+			it "should return the method response to the callback", ->
+				@callback
+					.calledWith(null, @response_arg1)
+					.should.equal true
+
+			it "should release the lock", ->
+				@LockManager.releaseLock
+					.calledWith(@doc_id, @lockValue)
+					.should.equal true
+
+			it "should continue processing updates", ->
+				@UpdateManager.continueProcessingUpdatesWithLock
+					.calledWith(@project_id, @doc_id)
+					.should.equal true
+
+		describe "when processOutstandingUpdates returns an error", ->
+			beforeEach ->
+				@UpdateManager.processOutstandingUpdates = sinon.stub().callsArgWith(2, @error = new Error("Something went wrong"))
+				@UpdateManager.lockUpdatesAndDo @method, @project_id, @doc_id, @arg1, @callback
+
+			it "should free the lock", ->
+				@LockManager.releaseLock.calledWith(@doc_id, @lockValue).should.equal true
+				
+			it "should return the error in the callback", ->
+				@callback.calledWith(@error).should.equal true
+
+		describe "when the method returns an error", ->
+			beforeEach ->
+				@UpdateManager.processOutstandingUpdates = sinon.stub().callsArg(2)
+				@method = sinon.stub().callsArgWith(3, @error = new Error("something went wrong"), @response_arg1)
+				@UpdateManager.lockUpdatesAndDo @method, @project_id, @doc_id, @arg1, @callback
+
+			it "should free the lock", ->
+				@LockManager.releaseLock.calledWith(@doc_id, @lockValue).should.equal true
+				
+			it "should return the error in the callback", ->
+				@callback.calledWith(@error).should.equal true
+
+
+

+ 0 - 90
services/document-updater/test/unit/coffee/UpdateManager/lockUpdatesAndDoTests.coffee

@@ -1,90 +0,0 @@
-sinon = require('sinon')
-chai = require('chai')
-should = chai.should()
-modulePath = "../../../../app/js/UpdateManager.js"
-SandboxedModule = require('sandboxed-module')
-
-describe 'UpdateManager - lockUpdatesAndDo', ->
-	beforeEach ->
-		@UpdateManager = SandboxedModule.require modulePath, requires:
-			"./LockManager" : @LockManager = {}
-			"./RedisManager" : @RedisManager = {}
-			"./WebRedisManager" : @WebRedisManager = {}
-			"./ShareJsUpdateManager" : @ShareJsUpdateManager = {}
-			"./TrackChangesManager" : @TrackChangesManager = {}
-			"logger-sharelatex": @logger = { log: sinon.stub() }
-			"./Metrics": @Metrics =
-				Timer: class Timer
-					done: sinon.stub()
-			"settings-sharelatex": Settings = {}
-		@project_id = "project-id-123"
-		@doc_id = "doc-id-123"
-		@method = sinon.stub().callsArgWith(3, null, @response_arg1)
-		@callback = sinon.stub()
-		@arg1 = "argument 1"
-		@response_arg1 = "response argument 1"
-		@lockValue = "mock-lock-value"
-		@LockManager.getLock = sinon.stub().callsArgWith(1, null, @lockValue)
-		@LockManager.releaseLock = sinon.stub().callsArg(2)
-
-	describe "successfully", ->
-		beforeEach ->
-			@UpdateManager.continueProcessingUpdatesWithLock = sinon.stub()
-			@UpdateManager.processOutstandingUpdates = sinon.stub().callsArg(2)
-			@UpdateManager.lockUpdatesAndDo @method, @project_id, @doc_id, @arg1, @callback
-
-		it "should lock the doc", ->
-			@LockManager.getLock
-				.calledWith(@doc_id)
-				.should.equal true
-
-		it "should process any outstanding updates", ->
-			@UpdateManager.processOutstandingUpdates
-				.calledWith(@project_id, @doc_id)
-				.should.equal true
-
-		it "should call the method", ->
-			@method
-				.calledWith(@project_id, @doc_id, @arg1)
-				.should.equal true
-
-		it "should return the method response to the callback", ->
-			@callback
-				.calledWith(null, @response_arg1)
-				.should.equal true
-
-		it "should release the lock", ->
-			@LockManager.releaseLock
-				.calledWith(@doc_id, @lockValue)
-				.should.equal true
-
-		it "should continue processing updates", ->
-			@UpdateManager.continueProcessingUpdatesWithLock
-				.calledWith(@project_id, @doc_id)
-				.should.equal true
-
-	describe "when processOutstandingUpdates returns an error", ->
-		beforeEach ->
-			@UpdateManager.processOutstandingUpdates = sinon.stub().callsArgWith(2, @error = new Error("Something went wrong"))
-			@UpdateManager.lockUpdatesAndDo @method, @project_id, @doc_id, @arg1, @callback
-
-		it "should free the lock", ->
-			@LockManager.releaseLock.calledWith(@doc_id, @lockValue).should.equal true
-			
-		it "should return the error in the callback", ->
-			@callback.calledWith(@error).should.equal true
-
-	describe "when the method returns an error", ->
-		beforeEach ->
-			@UpdateManager.processOutstandingUpdates = sinon.stub().callsArg(2)
-			@method = sinon.stub().callsArgWith(3, @error = new Error("something went wrong"), @response_arg1)
-			@UpdateManager.lockUpdatesAndDo @method, @project_id, @doc_id, @arg1, @callback
-
-		it "should free the lock", ->
-			@LockManager.releaseLock.calledWith(@doc_id, @lockValue).should.equal true
-			
-		it "should return the error in the callback", ->
-			@callback.calledWith(@error).should.equal true
-
-
-