|
|
@@ -11,9 +11,11 @@ describe "Applying updates to a doc", ->
|
|
|
@doc_id = ObjectId()
|
|
|
@originalLines = ["original", "lines"]
|
|
|
@newLines = ["new", "lines"]
|
|
|
+ @originalVersion = 42
|
|
|
+ @newVersion = 53
|
|
|
DocstoreClient.createProject @project_id, (error) =>
|
|
|
throw error if error?
|
|
|
- DocstoreClient.createDoc @project_id, @doc_id, @lines, (error) =>
|
|
|
+ DocstoreClient.createDoc @project_id, @doc_id, @lines, @version, (error) =>
|
|
|
throw error if error?
|
|
|
done()
|
|
|
|
|
|
@@ -22,7 +24,7 @@ describe "Applying updates to a doc", ->
|
|
|
|
|
|
describe "when the content has changed", ->
|
|
|
beforeEach (done) ->
|
|
|
- DocstoreClient.updateDoc @project_id, @doc_id, @newLines, (error, res, @body) =>
|
|
|
+ DocstoreClient.updateDoc @project_id, @doc_id, @newLines, @newVersion, (error, res, @body) =>
|
|
|
done()
|
|
|
|
|
|
it "should return modified = true", ->
|
|
|
@@ -31,11 +33,12 @@ describe "Applying updates to a doc", ->
|
|
|
it "should update the doc in the API", (done) ->
|
|
|
DocstoreClient.getDoc @project_id, @doc_id, (error, res, doc) =>
|
|
|
doc.lines.should.deep.equal @newLines
|
|
|
+ doc.version.should.deep.equal @newVersion
|
|
|
done()
|
|
|
|
|
|
describe "when the content has not been updated", ->
|
|
|
beforeEach (done) ->
|
|
|
- DocstoreClient.updateDoc @project_id, @doc_id, @originalLines, (error, res, @body) =>
|
|
|
+ DocstoreClient.updateDoc @project_id, @doc_id, @originalLines, @originalVersion, (error, res, @body) =>
|
|
|
done()
|
|
|
|
|
|
it "should return modified = false", ->
|
|
|
@@ -44,12 +47,13 @@ describe "Applying updates to a doc", ->
|
|
|
it "should not update the doc in the API", (done) ->
|
|
|
DocstoreClient.getDoc @project_id, @doc_id, (error, res, doc) =>
|
|
|
doc.lines.should.deep.equal @originalLines
|
|
|
+ doc.version.should.deep.equal @originalVersion
|
|
|
done()
|
|
|
|
|
|
describe "when the doc does not exist", ->
|
|
|
beforeEach (done) ->
|
|
|
missing_doc_id = ObjectId()
|
|
|
- DocstoreClient.updateDoc @project_id, missing_doc_id, @originalLines, (error, @res, @body) =>
|
|
|
+ DocstoreClient.updateDoc @project_id, missing_doc_id, @originalLines, @newVersion, (error, @res, @body) =>
|
|
|
done()
|
|
|
|
|
|
it "should return a 404", ->
|
|
|
@@ -58,7 +62,7 @@ describe "Applying updates to a doc", ->
|
|
|
describe "when the project does not exist", ->
|
|
|
beforeEach (done) ->
|
|
|
missing_project_id = ObjectId()
|
|
|
- DocstoreClient.updateDoc missing_project_id, @doc_id, @originalLines, (error, @res, @body) =>
|
|
|
+ DocstoreClient.updateDoc missing_project_id, @doc_id, @originalLines, @newVersion, (error, @res, @body) =>
|
|
|
done()
|
|
|
|
|
|
it "should return a 404", ->
|
|
|
@@ -67,7 +71,7 @@ describe "Applying updates to a doc", ->
|
|
|
describe "when malformed doc lines are provided", ->
|
|
|
describe "when the lines are not an array", ->
|
|
|
beforeEach (done) ->
|
|
|
- DocstoreClient.updateDoc @project_id, @doc_id, { foo: "bar" }, (error, @res, @body) =>
|
|
|
+ DocstoreClient.updateDoc @project_id, @doc_id, { foo: "bar" }, @newVersion, (error, @res, @body) =>
|
|
|
done()
|
|
|
|
|
|
it "should return 400", ->
|
|
|
@@ -80,7 +84,7 @@ describe "Applying updates to a doc", ->
|
|
|
|
|
|
describe "when the lines are not present", ->
|
|
|
beforeEach (done) ->
|
|
|
- DocstoreClient.updateDoc @project_id, @doc_id, null, (error, @res, @body) =>
|
|
|
+ DocstoreClient.updateDoc @project_id, @doc_id, null, @newVersion, (error, @res, @body) =>
|
|
|
done()
|
|
|
|
|
|
it "should return 400", ->
|