diff --git a/services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee b/services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee index 7050f0f370..4a29f54321 100644 --- a/services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee +++ b/services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee @@ -278,6 +278,7 @@ describe "DocumentManager", -> describe "acceptChanges", -> beforeEach -> @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 @lines = ["original", "lines"] @ranges = { entries: "mock", comments: "mock" } @@ -286,7 +287,7 @@ describe "DocumentManager", -> @RangesManager.acceptChanges = sinon.stub().yields(null, @updated_ranges) @RedisManager.updateDocument = sinon.stub().yields() - describe "successfully", -> + describe "successfully with a single change", -> beforeEach -> @DocumentManager.acceptChanges @project_id, @doc_id, [ @change_id ], @callback @@ -308,6 +309,15 @@ describe "DocumentManager", -> it "should call the callback", -> @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", -> beforeEach -> @DocumentManager.getDoc = sinon.stub().yields(null, null, null, null) diff --git a/services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee b/services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee index ec910c9519..617146e787 100644 --- a/services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee +++ b/services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee @@ -343,7 +343,7 @@ describe "HttpController", -> doc_id: @doc_id change_id: @change_id = "mock-change-od-1" - describe "successfully", -> + describe "successfully with a single change", -> beforeEach -> @DocumentManager.acceptChangesWithLock = sinon.stub().callsArgWith(3) @HttpController.acceptChanges(@req, @res, @next) @@ -366,6 +366,24 @@ describe "HttpController", -> it "should time the request", -> @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", -> beforeEach -> @DocumentManager.acceptChangesWithLock = sinon.stub().callsArgWith(3, new Error("oops")) diff --git a/services/document-updater/test/unit/coffee/RangesManager/RangesManagerTests.coffee b/services/document-updater/test/unit/coffee/RangesManager/RangesManagerTests.coffee index fd3bc8faec..bdb075ebe6 100644 --- a/services/document-updater/test/unit/coffee/RangesManager/RangesManagerTests.coffee +++ b/services/document-updater/test/unit/coffee/RangesManager/RangesManagerTests.coffee @@ -10,7 +10,6 @@ describe "RangesManager", -> @RangesManager = SandboxedModule.require modulePath, requires: "logger-sharelatex": @logger = { error: sinon.stub(), log: sinon.stub(), warn: sinon.stub() } - @doc_id = "doc-id-123" @project_id = "project-id-123" @user_id = "user-id-123" @@ -178,4 +177,28 @@ describe "RangesManager", -> @callback.called.should.equal true [error, entries] = @callback.args[0] 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 \")") \ No newline at end of file + 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