|
@@ -26,12 +26,10 @@ describe "MongoManager", ->
|
|
|
@MongoManager.findDoc @project_id, @doc_id, @filter, @callback
|
|
@MongoManager.findDoc @project_id, @doc_id, @filter, @callback
|
|
|
|
|
|
|
|
it "should find the doc", ->
|
|
it "should find the doc", ->
|
|
|
- @db.docs.find
|
|
|
|
|
- .calledWith({
|
|
|
|
|
- _id: ObjectId(@doc_id)
|
|
|
|
|
- project_id: ObjectId(@project_id)
|
|
|
|
|
- }, @filter)
|
|
|
|
|
- .should.equal true
|
|
|
|
|
|
|
+ @db.docs.find.lastCall.args.slice(0,2).should.deep.equal([
|
|
|
|
|
+ {_id: ObjectId(@doc_id), project_id: ObjectId(@project_id)},
|
|
|
|
|
+ @filter
|
|
|
|
|
+ ])
|
|
|
|
|
|
|
|
it "should call the callback with the doc", ->
|
|
it "should call the callback with the doc", ->
|
|
|
@callback.calledWith(null, @doc).should.equal true
|
|
@callback.calledWith(null, @doc).should.equal true
|
|
@@ -50,12 +48,9 @@ describe "MongoManager", ->
|
|
|
@MongoManager.getProjectsDocs @project_id, include_deleted: false, @filter, @callback
|
|
@MongoManager.getProjectsDocs @project_id, include_deleted: false, @filter, @callback
|
|
|
|
|
|
|
|
it "should find the non-deleted docs via the project_id", ->
|
|
it "should find the non-deleted docs via the project_id", ->
|
|
|
- @db.docs.find
|
|
|
|
|
- .calledWith({
|
|
|
|
|
- project_id: ObjectId(@project_id)
|
|
|
|
|
- deleted: { $ne: true }
|
|
|
|
|
- }, @filter)
|
|
|
|
|
- .should.equal true
|
|
|
|
|
|
|
+ @db.docs.find.lastCall.args.slice(0,1).should.deep.equal([
|
|
|
|
|
+ {project_id: ObjectId(@project_id), deleted: {$ne: true}}
|
|
|
|
|
+ ])
|
|
|
|
|
|
|
|
it "should call the callback with the docs", ->
|
|
it "should call the callback with the docs", ->
|
|
|
@callback.calledWith(null, [@doc, @doc3, @doc4]).should.equal true
|
|
@callback.calledWith(null, [@doc, @doc3, @doc4]).should.equal true
|
|
@@ -65,11 +60,10 @@ describe "MongoManager", ->
|
|
|
@MongoManager.getProjectsDocs @project_id, include_deleted: true, @filter, @callback
|
|
@MongoManager.getProjectsDocs @project_id, include_deleted: true, @filter, @callback
|
|
|
|
|
|
|
|
it "should find all via the project_id", ->
|
|
it "should find all via the project_id", ->
|
|
|
- @db.docs.find
|
|
|
|
|
- .calledWith({
|
|
|
|
|
- project_id: ObjectId(@project_id)
|
|
|
|
|
- }, @filter)
|
|
|
|
|
- .should.equal true
|
|
|
|
|
|
|
+ @db.docs.find.lastCall.args.slice(0,2).should.deep.equal([
|
|
|
|
|
+ {project_id: ObjectId(@project_id)},
|
|
|
|
|
+ @filter
|
|
|
|
|
+ ])
|
|
|
|
|
|
|
|
it "should call the callback with the docs", ->
|
|
it "should call the callback with the docs", ->
|
|
|
@callback.calledWith(null, [@doc, @doc3, @doc4]).should.equal true
|
|
@callback.calledWith(null, [@doc, @doc3, @doc4]).should.equal true
|
|
@@ -119,9 +113,10 @@ describe "MongoManager", ->
|
|
|
@MongoManager.getDocVersion @doc_id, @callback
|
|
@MongoManager.getDocVersion @doc_id, @callback
|
|
|
|
|
|
|
|
it "should look for the doc in the database", ->
|
|
it "should look for the doc in the database", ->
|
|
|
- @db.docOps.find
|
|
|
|
|
- .calledWith({ doc_id: ObjectId(@doc_id) }, {version: 1})
|
|
|
|
|
- .should.equal true
|
|
|
|
|
|
|
+ @db.docOps.find.lastCall.args.slice(0,2).should.deep.equal([
|
|
|
|
|
+ { doc_id: ObjectId(@doc_id) },
|
|
|
|
|
+ {version: 1}
|
|
|
|
|
+ ])
|
|
|
|
|
|
|
|
it "should call the callback with the version", ->
|
|
it "should call the callback with the version", ->
|
|
|
@callback.calledWith(null, @version).should.equal true
|
|
@callback.calledWith(null, @version).should.equal true
|
|
@@ -141,16 +136,11 @@ describe "MongoManager", ->
|
|
|
@MongoManager.setDocVersion @doc_id, @version, @callback
|
|
@MongoManager.setDocVersion @doc_id, @version, @callback
|
|
|
|
|
|
|
|
it "should update the doc version", ->
|
|
it "should update the doc version", ->
|
|
|
- @db.docOps.update
|
|
|
|
|
- .calledWith({
|
|
|
|
|
- doc_id: ObjectId(@doc_id)
|
|
|
|
|
- }, {
|
|
|
|
|
- $set:
|
|
|
|
|
- version: @version
|
|
|
|
|
- }, {
|
|
|
|
|
- upsert: true
|
|
|
|
|
- })
|
|
|
|
|
- .should.equal true
|
|
|
|
|
|
|
+ @db.docOps.update.lastCall.args.slice(0,3).should.deep.equal([
|
|
|
|
|
+ {doc_id: ObjectId(@doc_id)},
|
|
|
|
|
+ {$set: {version: @version}},
|
|
|
|
|
+ {upsert: true}
|
|
|
|
|
+ ])
|
|
|
|
|
|
|
|
it "should call the callback", ->
|
|
it "should call the callback", ->
|
|
|
@callback.called.should.equal true
|
|
@callback.called.should.equal true
|