Selaa lähdekoodia

Update tests; add new ones for multiple changes.

Paulo Reis 9 vuotta sitten
vanhempi
sitoutus
f690ef078a

+ 11 - 1
services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee

@@ -278,6 +278,7 @@ describe "DocumentManager", ->
 	describe "acceptChanges", ->
 	describe "acceptChanges", ->
 		beforeEach ->
 		beforeEach ->
 			@change_id = "mock-change-id"
 			@change_id = "mock-change-id"
+			@change_ids = [ "mock-change-id-1", "mock-change-id-2", "mock-change-id-3", "mock-change-id-4" ]
 			@version = 34
 			@version = 34
 			@lines = ["original", "lines"]
 			@lines = ["original", "lines"]
 			@ranges = { entries: "mock", comments: "mock" }
 			@ranges = { entries: "mock", comments: "mock" }
@@ -286,7 +287,7 @@ describe "DocumentManager", ->
 			@RangesManager.acceptChanges = sinon.stub().yields(null, @updated_ranges)
 			@RangesManager.acceptChanges = sinon.stub().yields(null, @updated_ranges)
 			@RedisManager.updateDocument = sinon.stub().yields()
 			@RedisManager.updateDocument = sinon.stub().yields()
 		
 		
-		describe "successfully", ->
+		describe "successfully with a single change", ->
 			beforeEach ->
 			beforeEach ->
 				@DocumentManager.acceptChanges @project_id, @doc_id, [ @change_id ], @callback
 				@DocumentManager.acceptChanges @project_id, @doc_id, [ @change_id ], @callback
 			
 			
@@ -308,6 +309,15 @@ describe "DocumentManager", ->
 			it "should call the callback", ->
 			it "should call the callback", ->
 				@callback.called.should.equal true
 				@callback.called.should.equal true
 
 
+		describe "successfully with multiple changes", ->
+			beforeEach ->
+				@DocumentManager.acceptChanges @project_id, @doc_id, @change_ids, @callback
+			
+			it "should apply the accept change to the ranges", ->
+				@RangesManager.acceptChanges
+					.calledWith(@change_ids, @ranges)
+					.should.equal true
+
 		describe "when the doc is not found", ->
 		describe "when the doc is not found", ->
 			beforeEach ->
 			beforeEach ->
 				@DocumentManager.getDoc = sinon.stub().yields(null, null, null, null)
 				@DocumentManager.getDoc = sinon.stub().yields(null, null, null, null)

+ 19 - 1
services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee

@@ -343,7 +343,7 @@ describe "HttpController", ->
 					doc_id: @doc_id
 					doc_id: @doc_id
 					change_id: @change_id = "mock-change-od-1"
 					change_id: @change_id = "mock-change-od-1"
 
 
-		describe "successfully", ->
+		describe "successfully with a single change", ->
 			beforeEach ->
 			beforeEach ->
 				@DocumentManager.acceptChangesWithLock = sinon.stub().callsArgWith(3)
 				@DocumentManager.acceptChangesWithLock = sinon.stub().callsArgWith(3)
 				@HttpController.acceptChanges(@req, @res, @next)
 				@HttpController.acceptChanges(@req, @res, @next)
@@ -366,6 +366,24 @@ describe "HttpController", ->
 			it "should time the request", ->
 			it "should time the request", ->
 				@Metrics.Timer::done.called.should.equal true
 				@Metrics.Timer::done.called.should.equal true
 
 
+		describe "succesfully with with multiple changes", ->
+			beforeEach ->
+				@change_ids = [ "mock-change-od-1", "mock-change-od-2", "mock-change-od-3", "mock-change-od-4" ]
+				@req.body =
+					change_ids: @change_ids
+				@DocumentManager.acceptChangesWithLock = sinon.stub().callsArgWith(3)
+				@HttpController.acceptChanges(@req, @res, @next)
+
+			it "should accept the changes in the body payload", ->
+				@DocumentManager.acceptChangesWithLock
+					.calledWith(@project_id, @doc_id, @change_ids)
+					.should.equal true
+
+			it "should log the request with the correct number of changes", ->
+				@logger.log
+					.calledWith({@project_id, @doc_id}, "accepting #{ @change_ids.length } changes via http")
+					.should.equal true
+
 		describe "when an errors occurs", ->
 		describe "when an errors occurs", ->
 			beforeEach ->
 			beforeEach ->
 				@DocumentManager.acceptChangesWithLock = sinon.stub().callsArgWith(3, new Error("oops"))
 				@DocumentManager.acceptChangesWithLock = sinon.stub().callsArgWith(3, new Error("oops"))

+ 25 - 2
services/document-updater/test/unit/coffee/RangesManager/RangesManagerTests.coffee

@@ -10,7 +10,6 @@ describe "RangesManager", ->
 		@RangesManager = SandboxedModule.require modulePath,
 		@RangesManager = SandboxedModule.require modulePath,
 			requires:
 			requires:
 				"logger-sharelatex": @logger = { error: sinon.stub(), log: sinon.stub(), warn: sinon.stub() }
 				"logger-sharelatex": @logger = { error: sinon.stub(), log: sinon.stub(), warn: sinon.stub() }
-		
 		@doc_id = "doc-id-123"
 		@doc_id = "doc-id-123"
 		@project_id = "project-id-123"
 		@project_id = "project-id-123"
 		@user_id = "user-id-123"
 		@user_id = "user-id-123"
@@ -178,4 +177,28 @@ describe "RangesManager", ->
 				@callback.called.should.equal true
 				@callback.called.should.equal true
 				[error, entries] = @callback.args[0]
 				[error, entries] = @callback.args[0]
 				expect(error).to.not.be.null
 				expect(error).to.not.be.null
-				expect(error.message).to.equal("Change ({\"op\":{\"i\":\"five\",\"p\":15},\"metadata\":{\"user_id\":\"user-id-123\"}}) doesn't match text (\"our \")")
+				expect(error.message).to.equal("Change ({\"op\":{\"i\":\"five\",\"p\":15},\"metadata\":{\"user_id\":\"user-id-123\"}}) doesn't match text (\"our \")")
+
+	describe "acceptChanges", ->
+		beforeEach ->
+			@ranges = { entries: "mock", comments: "mock" }
+
+		describe "successfully with a single change", ->
+			beforeEach ->
+				@change_id = "mock-change-id"
+				@RangesManager.acceptChanges [ @change_id ], @ranges 
+
+			it "should log the call with the correct number of changes", ->
+				@logger.log
+					.calledWith("accepting 1 changes in ranges")
+					.should.equal true
+
+		describe "successfully with multiple changes", ->
+			beforeEach ->
+				@change_ids = [ "mock-change-id-1", "mock-change-id-2", "mock-change-id-3", "mock-change-id-4" ]
+				@RangesManager.acceptChanges @change_ids, @ranges
+
+			it "should log the call with the correct number of changes", ->
+				@logger.log
+					.calledWith("accepting #{ @change_ids.length } changes in ranges")
+					.should.equal true