Ver Fonte

add unit tests

Hayden Faulds há 8 anos atrás
pai
commit
a72d228354

+ 39 - 0
services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee

@@ -467,3 +467,42 @@ describe "DocumentManager", ->
 
 			it "should call the callback", ->
 				@callback.called.should.equal true
+
+	describe "resyncDocContents", ->
+		describe "when doc is loaded in redis", ->
+			beforeEach ->
+				@RedisManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
+				@RedisManager.queueResyncDocContents = sinon.stub()
+				@DocumentManager.resyncDocContents @project_id, @doc_id, @callback
+
+			it "gets the doc contents from redis", ->
+				@RedisManager.getDoc
+					.calledWith(@project_id, @doc_id)
+					.should.equal true
+
+			it "queues a resync doc content update", ->
+				@RedisManager.queueResyncDocContents
+					.calledWith(@project_id, @doc_id, @lines, @version, @pathname, @callback)
+					.should.equal true
+
+		describe "when doc is not loaded in redis", ->
+			beforeEach ->
+				@RedisManager.getDoc = sinon.stub().callsArgWith(2, null)
+				@PersistenceManager.getDoc = sinon.stub().callsArgWith(2, null, @lines, @version, @ranges, @pathname)
+				@RedisManager.queueResyncDocContents = sinon.stub()
+				@DocumentManager.resyncDocContents @project_id, @doc_id, @callback
+
+			it "tries to get the doc contents from redis", ->
+				@RedisManager.getDoc
+					.calledWith(@project_id, @doc_id)
+					.should.equal true
+
+			it "gets the doc contents from web", ->
+				@PersistenceManager.getDoc
+					.calledWith(@project_id, @doc_id)
+					.should.equal true
+
+			it "queues a resync doc content update", ->
+				@RedisManager.queueResyncDocContents
+					.calledWith(@project_id, @doc_id, @lines, @version, @pathname, @callback)
+					.should.equal true

+ 31 - 0
services/document-updater/test/unit/coffee/HistoryManager/HistoryManagerTests.coffee

@@ -16,7 +16,9 @@ describe "HistoryManager", ->
 						url: "http://trackchanges.example.com"
 			}
 			"logger-sharelatex": @logger = { log: sinon.stub(), error: sinon.stub() }
+			"./DocumentManager": @DocumentManager = {}
 			"./HistoryRedisManager": @HistoryRedisManager = {}
+			"./RedisManager": @RedisManager = {}
 		@project_id = "mock-project-id"
 		@doc_id = "mock-doc-id"
 		@callback = sinon.stub()
@@ -158,3 +160,32 @@ describe "HistoryManager", ->
 				# Previously we were on 16 ops
 				# We didn't pass over a multiple of 5
 				@HistoryManager.shouldFlushHistoryOps(17, ['a', 'b', 'c'].length, 5).should.equal true
+
+	describe "resyncProjectHistory", ->
+		beforeEach ->
+			@docs = [
+				doc: @doc_id
+				path: 'main.tex'
+			]
+			@files = [
+				file: 'mock-file-id'
+				path: 'universe.png'
+				url: "www.filestore.test/#{@project_id}/mock-file-id"
+			]
+			@RedisManager.queueResyncProjectStructure = sinon.stub().yields()
+			@DocumentManager.resyncDocContentsWithLock = sinon.stub().yields()
+			@HistoryManager.resyncProjectHistory @project_id, @docs, @files, @callback
+
+		it "should queue a project structure reync", ->
+			@RedisManager.queueResyncProjectStructure
+				.calledWith(@project_id, @docs, @files)
+				.should.equal true
+
+		it "should queue doc content reyncs", ->
+			@DocumentManager
+				.resyncDocContentsWithLock
+				.calledWith(@project_id, @doc_id)
+				.should.equal true
+
+		it "should call the callback", ->
+			@callback.called.should.equal true

+ 36 - 0
services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee

@@ -544,3 +544,39 @@ describe "HttpController", ->
 				@next
 					.calledWith(new Error("oops"))
 					.should.equal true
+
+	describe "resyncProjectHistory", ->
+		beforeEach ->
+			@docs = sinon.stub()
+			@files = sinon.stub()
+			@fileUpdates = sinon.stub()
+			@req =
+				body:
+					{@docs, @files}
+				params:
+					project_id: @project_id
+
+		describe "successfully", ->
+			beforeEach ->
+				@HistoryManager.resyncProjectHistory = sinon.stub().callsArg(3)
+				@HttpController.resyncProjectHistory(@req, @res, @next)
+
+			it "should accept the change", ->
+				@HistoryManager.resyncProjectHistory
+					.calledWith(@project_id, @docs, @files)
+					.should.equal true
+
+			it "should return a successful No Content response", ->
+				@res.send
+					.calledWith(204)
+					.should.equal true
+
+		describe "when an errors occurs", ->
+			beforeEach ->
+				@HistoryManager.resyncProjectHistory = sinon.stub().callsArgWith(3, new Error("oops"))
+				@HttpController.resyncProjectHistory(@req, @res, @next)
+
+			it "should call next with the error", ->
+				@next
+					.calledWith(new Error("oops"))
+					.should.equal true