|
@@ -24,10 +24,10 @@ describe "PersistenceManager.getDoc", ->
|
|
|
@lines = ["mock", "doc", "lines"]
|
|
@lines = ["mock", "doc", "lines"]
|
|
|
@version = 42
|
|
@version = 42
|
|
|
|
|
|
|
|
- describe "when the version is set in the web api", ->
|
|
|
|
|
|
|
+ describe "when the version is set in the web api but not Mongo", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@PersistenceManager.getDocFromWeb = sinon.stub().callsArgWith(2, null, @lines, @version)
|
|
@PersistenceManager.getDocFromWeb = sinon.stub().callsArgWith(2, null, @lines, @version)
|
|
|
- @PersistenceManager.getDocVersionInMongo = sinon.stub()
|
|
|
|
|
|
|
+ @PersistenceManager.getDocVersionInMongo = sinon.stub().callsArgWith(1, null, null)
|
|
|
@PersistenceManager.getDoc @project_id, @doc_id, @callback
|
|
@PersistenceManager.getDoc @project_id, @doc_id, @callback
|
|
|
|
|
|
|
|
it "should look up the doc in the web api", ->
|
|
it "should look up the doc in the web api", ->
|
|
@@ -35,9 +35,10 @@ describe "PersistenceManager.getDoc", ->
|
|
|
.calledWith(@project_id, @doc_id)
|
|
.calledWith(@project_id, @doc_id)
|
|
|
.should.equal true
|
|
.should.equal true
|
|
|
|
|
|
|
|
- it "should not look up the version in Mongo", ->
|
|
|
|
|
|
|
+ it "should look up the version in Mongo", ->
|
|
|
@PersistenceManager.getDocVersionInMongo
|
|
@PersistenceManager.getDocVersionInMongo
|
|
|
- .called.should.equal false
|
|
|
|
|
|
|
+ .calledWith(@doc_id)
|
|
|
|
|
+ .should.equal true
|
|
|
|
|
|
|
|
it "should call the callback with the lines and version", ->
|
|
it "should call the callback with the lines and version", ->
|
|
|
@callback.calledWith(null, @lines, @version).should.equal true
|
|
@callback.calledWith(null, @lines, @version).should.equal true
|
|
@@ -48,11 +49,6 @@ describe "PersistenceManager.getDoc", ->
|
|
|
@PersistenceManager.getDocVersionInMongo = sinon.stub().callsArgWith(1, null, @version)
|
|
@PersistenceManager.getDocVersionInMongo = sinon.stub().callsArgWith(1, null, @version)
|
|
|
@PersistenceManager.getDoc @project_id, @doc_id, @callback
|
|
@PersistenceManager.getDoc @project_id, @doc_id, @callback
|
|
|
|
|
|
|
|
- it "should look up the version in Mongo", ->
|
|
|
|
|
- @PersistenceManager.getDocVersionInMongo
|
|
|
|
|
- .calledWith(@doc_id)
|
|
|
|
|
- .should.equal true
|
|
|
|
|
-
|
|
|
|
|
it "shoud log a warning", ->
|
|
it "shoud log a warning", ->
|
|
|
@logger.warn
|
|
@logger.warn
|
|
|
.calledWith(project_id: @project_id, doc_id: @doc_id, "loading doc version from mongo - deprecated")
|
|
.calledWith(project_id: @project_id, doc_id: @doc_id, "loading doc version from mongo - deprecated")
|
|
@@ -61,6 +57,24 @@ describe "PersistenceManager.getDoc", ->
|
|
|
it "should call the callback with the lines and version", ->
|
|
it "should call the callback with the lines and version", ->
|
|
|
@callback.calledWith(null, @lines, @version).should.equal true
|
|
@callback.calledWith(null, @lines, @version).should.equal true
|
|
|
|
|
|
|
|
|
|
+ describe "when the version in the web api is ahead of Mongo", ->
|
|
|
|
|
+ beforeEach ->
|
|
|
|
|
+ @PersistenceManager.getDocFromWeb = sinon.stub().callsArgWith(2, null, @lines, @version)
|
|
|
|
|
+ @PersistenceManager.getDocVersionInMongo = sinon.stub().callsArgWith(1, null, @version - 20)
|
|
|
|
|
+ @PersistenceManager.getDoc @project_id, @doc_id, @callback
|
|
|
|
|
+
|
|
|
|
|
+ it "should call the callback with the web version", ->
|
|
|
|
|
+ @callback.calledWith(null, @lines, @version).should.equal true
|
|
|
|
|
+
|
|
|
|
|
+ describe "when the version in the web api is behind Mongo", ->
|
|
|
|
|
+ beforeEach ->
|
|
|
|
|
+ @PersistenceManager.getDocFromWeb = sinon.stub().callsArgWith(2, null, @lines, @version - 20)
|
|
|
|
|
+ @PersistenceManager.getDocVersionInMongo = sinon.stub().callsArgWith(1, null, @version)
|
|
|
|
|
+ @PersistenceManager.getDoc @project_id, @doc_id, @callback
|
|
|
|
|
+
|
|
|
|
|
+ it "should call the callback with the Mongo version", ->
|
|
|
|
|
+ @callback.calledWith(null, @lines, @version).should.equal true
|
|
|
|
|
+
|
|
|
describe "when the version is not set", ->
|
|
describe "when the version is not set", ->
|
|
|
beforeEach ->
|
|
beforeEach ->
|
|
|
@PersistenceManager.getDocFromWeb = sinon.stub().callsArgWith(2, null, @lines, null)
|
|
@PersistenceManager.getDocFromWeb = sinon.stub().callsArgWith(2, null, @lines, null)
|