Update tests with new methods.

This commit is contained in:
Paulo Reis 2017-05-08 16:34:17 +01:00
parent d7ac57d054
commit 144804e516
4 changed files with 16 additions and 16 deletions

View file

@ -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"

View file

@ -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)

View file

@ -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

View file

@ -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