2014-04-29 06:49:09 -04:00
|
|
|
sinon = require "sinon"
|
|
|
|
chai = require("chai")
|
|
|
|
chai.should()
|
|
|
|
{ObjectId} = require "mongojs"
|
|
|
|
|
|
|
|
DocstoreClient = require "./helpers/DocstoreClient"
|
|
|
|
|
2014-04-30 08:06:12 -04:00
|
|
|
describe "Getting a doc", ->
|
2014-04-29 06:49:09 -04:00
|
|
|
beforeEach (done) ->
|
|
|
|
@project_id = ObjectId()
|
2014-04-30 08:06:12 -04:00
|
|
|
@doc_id = ObjectId()
|
2014-04-29 06:49:09 -04:00
|
|
|
@lines = ["original", "lines"]
|
2016-12-05 09:21:49 -05:00
|
|
|
@version = 42
|
|
|
|
@ranges = {
|
|
|
|
changes: [{
|
|
|
|
id: ObjectId().toString()
|
|
|
|
op: { i: "foo", p: 3 }
|
|
|
|
meta:
|
|
|
|
user_id: ObjectId().toString()
|
|
|
|
ts: new Date().toString()
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
DocstoreClient.createDoc @project_id, @doc_id, @lines, @version, @ranges, (error) =>
|
2014-04-30 08:06:12 -04:00
|
|
|
throw error if error?
|
2015-02-20 09:28:16 -05:00
|
|
|
done()
|
2014-04-29 06:49:09 -04:00
|
|
|
|
|
|
|
describe "when the doc exists", ->
|
2014-05-08 10:43:08 -04:00
|
|
|
it "should get the doc lines and version", (done) ->
|
2015-02-03 09:05:08 -05:00
|
|
|
DocstoreClient.getDoc @project_id, @doc_id, {}, (error, res, doc) =>
|
2014-04-29 06:49:09 -04:00
|
|
|
doc.lines.should.deep.equal @lines
|
2016-12-05 09:21:49 -05:00
|
|
|
doc.version.should.equal @version
|
|
|
|
doc.ranges.should.deep.equal @ranges
|
2014-04-29 06:49:09 -04:00
|
|
|
done()
|
|
|
|
|
|
|
|
describe "when the doc does not exist", ->
|
|
|
|
it "should return a 404", (done) ->
|
|
|
|
missing_doc_id = ObjectId()
|
2015-02-03 09:05:08 -05:00
|
|
|
DocstoreClient.getDoc @project_id, missing_doc_id, {}, (error, res, doc) ->
|
2014-04-29 06:49:09 -04:00
|
|
|
res.statusCode.should.equal 404
|
|
|
|
done()
|
|
|
|
|
2014-06-06 07:37:42 -04:00
|
|
|
describe "when the doc is a deleted doc", ->
|
|
|
|
beforeEach (done) ->
|
2015-01-22 10:05:48 -05:00
|
|
|
@deleted_doc_id = ObjectId()
|
2016-12-05 09:21:49 -05:00
|
|
|
DocstoreClient.createDoc @project_id, @deleted_doc_id, @lines, @version, @ranges, (error) =>
|
|
|
|
throw error if error?
|
|
|
|
DocstoreClient.deleteDoc @project_id, @deleted_doc_id, done
|
2014-06-06 07:37:42 -04:00
|
|
|
|
2015-01-22 10:05:48 -05:00
|
|
|
it "should return the doc", (done) ->
|
2015-02-03 09:05:08 -05:00
|
|
|
DocstoreClient.getDoc @project_id, @deleted_doc_id, {include_deleted:true},(error, res, doc) =>
|
2015-01-22 10:05:48 -05:00
|
|
|
doc.lines.should.deep.equal @lines
|
2016-12-05 09:21:49 -05:00
|
|
|
doc.version.should.equal @version
|
|
|
|
doc.ranges.should.deep.equal @ranges
|
2015-01-22 10:05:48 -05:00
|
|
|
doc.deleted.should.equal true
|
|
|
|
done()
|
2014-06-06 07:37:42 -04:00
|
|
|
|
2015-02-03 09:05:08 -05:00
|
|
|
it "should return a 404 when the query string is not set", (done)->
|
|
|
|
DocstoreClient.getDoc @project_id, @deleted_doc_id, {},(error, res, doc) =>
|
|
|
|
res.statusCode.should.equal 404
|
|
|
|
done()
|
2015-01-22 10:05:48 -05:00
|
|
|
|