GettingDocsTests.coffee 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. sinon = require "sinon"
  2. chai = require("chai")
  3. chai.should()
  4. {ObjectId} = require "mongojs"
  5. DocstoreClient = require "./helpers/DocstoreClient"
  6. describe "Getting a doc", ->
  7. beforeEach (done) ->
  8. @project_id = ObjectId()
  9. @doc_id = ObjectId()
  10. @lines = ["original", "lines"]
  11. DocstoreClient.createDoc @project_id, @doc_id, @lines, (error) =>
  12. throw error if error?
  13. done()
  14. describe "when the doc exists", ->
  15. it "should get the doc lines and version", (done) ->
  16. DocstoreClient.getDoc @project_id, @doc_id, {}, (error, res, doc) =>
  17. doc.lines.should.deep.equal @lines
  18. done()
  19. describe "when the doc does not exist", ->
  20. it "should return a 404", (done) ->
  21. missing_doc_id = ObjectId()
  22. DocstoreClient.getDoc @project_id, missing_doc_id, {}, (error, res, doc) ->
  23. res.statusCode.should.equal 404
  24. done()
  25. describe "when the doc is a deleted doc", ->
  26. beforeEach (done) ->
  27. @deleted_doc_id = ObjectId()
  28. DocstoreClient.createDeletedDoc @project_id, @deleted_doc_id, @lines, done
  29. it "should return the doc", (done) ->
  30. DocstoreClient.getDoc @project_id, @deleted_doc_id, {include_deleted:true},(error, res, doc) =>
  31. doc.lines.should.deep.equal @lines
  32. doc.deleted.should.equal true
  33. done()
  34. it "should return a 404 when the query string is not set", (done)->
  35. DocstoreClient.getDoc @project_id, @deleted_doc_id, {},(error, res, doc) =>
  36. res.statusCode.should.equal 404
  37. done()