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"]
|
2014-04-30 08:06:12 -04:00
|
|
|
DocstoreClient.createProject @project_id, (error) =>
|
|
|
|
throw error if error?
|
2014-05-16 08:06:35 -04:00
|
|
|
DocstoreClient.createDoc @project_id, @doc_id, @lines, (error) =>
|
2014-04-30 08:06:12 -04:00
|
|
|
throw error if error?
|
|
|
|
done()
|
2014-04-29 06:49:09 -04:00
|
|
|
|
|
|
|
afterEach (done) ->
|
|
|
|
DocstoreClient.deleteProject @project_id, done
|
|
|
|
|
|
|
|
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
|
|
|
|
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()
|
2014-06-06 07:37:42 -04:00
|
|
|
DocstoreClient.createDeletedDoc @project_id, @deleted_doc_id, @lines, done
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|