Refactor arguments to MongoManager.getUpdatesBetweenDates

This commit is contained in:
James Allen 2014-03-05 15:06:46 +00:00
parent 188d620ce1
commit a46963a349
5 changed files with 18 additions and 13 deletions

View file

@ -10,7 +10,7 @@ module.exports = DiffManager =
return callback(error) if error?
DocumentUpdaterManager.getDocument project_id, doc_id, (error, lines, version) ->
return callback(error) if error?
MongoManager.getUpdatesBetweenDates doc_id, fromDate, toDate, (error, updates) ->
MongoManager.getUpdatesBetweenDates doc_id, from: fromDate, to: toDate, (error, updates) ->
return callback(error) if error?
callback(null, lines, version, updates)

View file

@ -28,3 +28,8 @@ module.exports = HttpController =
return next(error) if error?
res.send JSON.stringify(diff: diff)
getUpdates: (req, res, next = (error) ->) ->
doc_id = req.params.doc_id
project_id = req.params.project_id

View file

@ -39,13 +39,13 @@ module.exports = MongoManager =
v: update.v
}, callback
getUpdatesBetweenDates:(doc_id, fromDate, toDate, callback = (error, updates) ->) ->
getUpdatesBetweenDates:(doc_id, options = {}, callback = (error, updates) ->) ->
query =
doc_id: ObjectId(doc_id.toString())
if fromDate?
query["meta.start_ts"] = { $gte: fromDate }
if toDate?
query["meta.end_ts"] = { $lte: toDate }
if options.from?
query["meta.end_ts"] = { $gte: options.from }
if options.to?
query["meta.start_ts"] = { $lte: options.to }
db.docHistory
.find( query )
.sort( "meta.end_ts": -1 )

View file

@ -27,7 +27,7 @@ describe "DiffManager", ->
@HistoryManager.processUncompressedUpdatesWithLock = sinon.stub().callsArg(1)
@DocumentUpdaterManager.getDocument = sinon.stub().callsArgWith(2, null, @lines, @version)
@MongoManager.getUpdatesBetweenDates = sinon.stub().callsArgWith(3, null, @updates)
@MongoManager.getUpdatesBetweenDates = sinon.stub().callsArgWith(2, null, @updates)
@DiffManager.getLatestDocAndUpdates @project_id, @doc_id, @from, @to, @callback
it "should ensure the latest updates have been compressed", ->
@ -42,7 +42,7 @@ describe "DiffManager", ->
it "should get the requested updates from Mongo", ->
@MongoManager.getUpdatesBetweenDates
.calledWith(@doc_id, @from, @to)
.calledWith(@doc_id, from: @from, to: @to)
.should.equal true
it "should call the callback with the lines, version and updates", ->

View file

@ -145,14 +145,14 @@ describe "MongoManager", ->
describe "with a toDate", ->
beforeEach ->
@MongoManager.getUpdatesBetweenDates @doc_id, @from, @to, @callback
@MongoManager.getUpdatesBetweenDates @doc_id, from: @from, to: @to, @callback
it "should find the all updates between the to and from date", ->
@db.docHistory.find
.calledWith({
doc_id: ObjectId(@doc_id)
"meta.start_ts": { $gte: @from }
"meta.end_ts": { $lte: @to }
"meta.end_ts": { $gte: @from }
"meta.start_ts": { $lte: @to }
})
.should.equal true
@ -166,13 +166,13 @@ describe "MongoManager", ->
describe "without a todo date", ->
beforeEach ->
@MongoManager.getUpdatesBetweenDates @doc_id, @from, null, @callback
@MongoManager.getUpdatesBetweenDates @doc_id, from: @from, @callback
it "should find the all updates after the from date", ->
@db.docHistory.find
.calledWith({
doc_id: ObjectId(@doc_id)
"meta.start_ts": { $gte: @from }
"meta.end_ts": { $gte: @from }
})
.should.equal true