2014-04-29 11:36:10 -04:00
|
|
|
sinon = require "sinon"
|
|
|
|
chai = require("chai")
|
|
|
|
chai.should()
|
|
|
|
{db, ObjectId} = require "../../../app/js/mongojs"
|
|
|
|
|
|
|
|
DocstoreClient = require "./helpers/DocstoreClient"
|
|
|
|
|
2014-04-30 08:06:12 -04:00
|
|
|
describe "Deleting a doc", ->
|
2014-04-29 11:36:10 -04:00
|
|
|
beforeEach (done) ->
|
|
|
|
@project_id = ObjectId()
|
2014-04-30 08:06:12 -04:00
|
|
|
@doc_id = ObjectId()
|
2014-04-29 11:36:10 -04:00
|
|
|
@lines = ["original", "lines"]
|
2014-05-08 10:43:08 -04:00
|
|
|
@version = 42
|
2016-12-05 09:21:49 -05:00
|
|
|
@ranges = []
|
|
|
|
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 11:36:10 -04:00
|
|
|
|
|
|
|
describe "when the doc exists", ->
|
|
|
|
beforeEach (done) ->
|
|
|
|
DocstoreClient.deleteDoc @project_id, @doc_id, (error, @res, doc) =>
|
|
|
|
done()
|
|
|
|
|
|
|
|
afterEach (done) ->
|
|
|
|
db.docs.remove({_id: @doc_id}, done)
|
|
|
|
|
|
|
|
it "should insert a deleted doc into the docs collection", (done) ->
|
|
|
|
db.docs.find _id: @doc_id, (error, docs) =>
|
|
|
|
docs[0]._id.should.deep.equal @doc_id
|
|
|
|
docs[0].lines.should.deep.equal @lines
|
|
|
|
docs[0].deleted.should.equal true
|
|
|
|
done()
|
|
|
|
|
|
|
|
describe "when the doc does not exist", ->
|
|
|
|
it "should return a 404", (done) ->
|
|
|
|
missing_doc_id = ObjectId()
|
|
|
|
DocstoreClient.deleteDoc @project_id, missing_doc_id, (error, res, doc) ->
|
|
|
|
res.statusCode.should.equal 404
|
|
|
|
done()
|
|
|
|
|