From 144804e516dbc9e83493cb6ba37c7ba6e2f62c3a Mon Sep 17 00:00:00 2001 From: Paulo Reis Date: Mon, 8 May 2017 16:34:17 +0100 Subject: [PATCH] Update tests with new methods. --- .../app/coffee/HttpController.coffee | 2 +- .../app/coffee/RangesManager.coffee | 2 +- .../DocumentManager/DocumentManagerTests.coffee | 12 ++++++------ .../HttpController/HttpControllerTests.coffee | 16 ++++++++-------- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/services/document-updater/app/coffee/HttpController.coffee b/services/document-updater/app/coffee/HttpController.coffee index cac024a802..13e618e734 100644 --- a/services/document-updater/app/coffee/HttpController.coffee +++ b/services/document-updater/app/coffee/HttpController.coffee @@ -98,7 +98,7 @@ module.exports = HttpController = acceptChanges: (req, res, next = (error) ->) -> {project_id, doc_id} = req.params - {change_ids} = req.body + change_ids = req.body?.change_ids if !change_ids? change_ids = [ req.params.change_id ] logger.log {project_id, doc_id}, "accepting #{ change_ids.length } changes via http" diff --git a/services/document-updater/app/coffee/RangesManager.coffee b/services/document-updater/app/coffee/RangesManager.coffee index 1fa56559b3..d0653bb6a2 100644 --- a/services/document-updater/app/coffee/RangesManager.coffee +++ b/services/document-updater/app/coffee/RangesManager.coffee @@ -35,7 +35,7 @@ module.exports = RangesManager = acceptChanges: (change_ids, ranges, callback = (error, ranges) ->) -> {changes, comments} = ranges - logger.log {change_id}, "accepting #{ change_ids.length } changes in ranges" + logger.log "accepting #{ change_ids.length } changes in ranges" rangesTracker = new RangesTracker(changes, comments) rangesTracker.removeChangeIds(change_ids) response = RangesManager._getRanges(rangesTracker) diff --git a/services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee b/services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee index 47fbde021b..7050f0f370 100644 --- a/services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee +++ b/services/document-updater/test/unit/coffee/DocumentManager/DocumentManagerTests.coffee @@ -283,12 +283,12 @@ describe "DocumentManager", -> @ranges = { entries: "mock", comments: "mock" } @updated_ranges = { entries: "updated", comments: "updated" } @DocumentManager.getDoc = sinon.stub().yields(null, @lines, @version, @ranges) - @RangesManager.acceptChange = sinon.stub().yields(null, @updated_ranges) + @RangesManager.acceptChanges = sinon.stub().yields(null, @updated_ranges) @RedisManager.updateDocument = sinon.stub().yields() describe "successfully", -> beforeEach -> - @DocumentManager.acceptChange @project_id, @doc_id, @change_id, @callback + @DocumentManager.acceptChanges @project_id, @doc_id, [ @change_id ], @callback it "should get the document's current ranges", -> @DocumentManager.getDoc @@ -296,8 +296,8 @@ describe "DocumentManager", -> .should.equal true it "should apply the accept change to the ranges", -> - @RangesManager.acceptChange - .calledWith(@change_id, @ranges) + @RangesManager.acceptChanges + .calledWith([ @change_id ], @ranges) .should.equal true it "should save the updated ranges", -> @@ -311,7 +311,7 @@ describe "DocumentManager", -> describe "when the doc is not found", -> beforeEach -> @DocumentManager.getDoc = sinon.stub().yields(null, null, null, null) - @DocumentManager.acceptChange @project_id, @doc_id, @change_id, @callback + @DocumentManager.acceptChanges @project_id, @doc_id, [ @change_id ], @callback it "should not save anything", -> @RedisManager.updateDocument.called.should.equal false @@ -356,7 +356,7 @@ describe "DocumentManager", -> describe "when the doc is not found", -> beforeEach -> @DocumentManager.getDoc = sinon.stub().yields(null, null, null, null) - @DocumentManager.acceptChange @project_id, @doc_id, @comment_id, @callback + @DocumentManager.acceptChanges @project_id, @doc_id, [ @comment_id ], @callback it "should not save anything", -> @RedisManager.updateDocument.called.should.equal false diff --git a/services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee b/services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee index 69b40c85d2..ec910c9519 100644 --- a/services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee +++ b/services/document-updater/test/unit/coffee/HttpController/HttpControllerTests.coffee @@ -335,7 +335,7 @@ describe "HttpController", -> .calledWith(new Error("oops")) .should.equal true - describe "acceptChange", -> + describe "acceptChanges", -> beforeEach -> @req = params: @@ -345,12 +345,12 @@ describe "HttpController", -> describe "successfully", -> beforeEach -> - @DocumentManager.acceptChangeWithLock = sinon.stub().callsArgWith(3) - @HttpController.acceptChange(@req, @res, @next) + @DocumentManager.acceptChangesWithLock = sinon.stub().callsArgWith(3) + @HttpController.acceptChanges(@req, @res, @next) it "should accept the change", -> - @DocumentManager.acceptChangeWithLock - .calledWith(@project_id, @doc_id, @change_id) + @DocumentManager.acceptChangesWithLock + .calledWith(@project_id, @doc_id, [ @change_id ]) .should.equal true it "should return a successful No Content response", -> @@ -360,7 +360,7 @@ describe "HttpController", -> it "should log the request", -> @logger.log - .calledWith({@project_id, @doc_id, @change_id}, "accepting change via http") + .calledWith({@project_id, @doc_id}, "accepting 1 changes via http") .should.equal true it "should time the request", -> @@ -368,8 +368,8 @@ describe "HttpController", -> describe "when an errors occurs", -> beforeEach -> - @DocumentManager.acceptChangeWithLock = sinon.stub().callsArgWith(3, new Error("oops")) - @HttpController.acceptChange(@req, @res, @next) + @DocumentManager.acceptChangesWithLock = sinon.stub().callsArgWith(3, new Error("oops")) + @HttpController.acceptChanges(@req, @res, @next) it "should call next with the error", -> @next