mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Add in HTTP end point for deleting docs
This commit is contained in:
parent
885d5de191
commit
984999ec61
8 changed files with 77 additions and 6 deletions
|
@ -11,6 +11,7 @@ app = express()
|
|||
|
||||
app.get '/project/:project_id/doc/:doc_id', HttpController.getDoc
|
||||
app.post '/project/:project_id/doc/:doc_id', bodyParser.json(), HttpController.updateDoc
|
||||
app.del '/project/:project_id/doc/:doc_id', HttpController.deleteDoc
|
||||
|
||||
app.get '/status', (req, res)->
|
||||
res.send('docstore is alive')
|
||||
|
|
|
@ -31,3 +31,11 @@ module.exports = HttpController =
|
|||
res.json {
|
||||
modified: modified
|
||||
}
|
||||
|
||||
deleteDoc: (req, res, next = (error) ->) ->
|
||||
project_id = req.params.project_id
|
||||
doc_id = req.params.doc_id
|
||||
logger.log project_id: project_id, doc_id: doc_id, "deleting doc"
|
||||
DocManager.deleteDoc project_id, doc_id, (error) ->
|
||||
return next(error) if error?
|
||||
res.send 204
|
|
@ -17,4 +17,4 @@ module.exports = MongoManager =
|
|||
insertDoc: (project_id, doc_id, attributes, callback = (error) ->) ->
|
||||
attributes._id = ObjectId(doc_id)
|
||||
attributes.project_id = ObjectId(project_id)
|
||||
db.projects.insert attributes, callback
|
||||
db.docs.insert attributes, callback
|
|
@ -1,6 +1,6 @@
|
|||
Settings = require "settings-sharelatex"
|
||||
mongojs = require "mongojs"
|
||||
db = mongojs.connect(Settings.mongo.url, ["projects"])
|
||||
db = mongojs.connect(Settings.mongo.url, ["projects", "docs"])
|
||||
module.exports =
|
||||
db: db
|
||||
ObjectId: mongojs.ObjectId
|
||||
|
|
|
@ -0,0 +1,39 @@
|
|||
sinon = require "sinon"
|
||||
chai = require("chai")
|
||||
chai.should()
|
||||
{db, ObjectId} = require "../../../app/js/mongojs"
|
||||
|
||||
DocstoreClient = require "./helpers/DocstoreClient"
|
||||
|
||||
describe "Applying updates to a doc", ->
|
||||
beforeEach (done) ->
|
||||
@project_id = ObjectId()
|
||||
@lines = ["original", "lines"]
|
||||
DocstoreClient.createDoc @project_id, @lines, (error, @doc_id) =>
|
||||
done()
|
||||
|
||||
afterEach (done) ->
|
||||
DocstoreClient.deleteProject @project_id, done
|
||||
|
||||
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()
|
||||
|
|
@ -32,6 +32,11 @@ module.exports = DocstoreClient =
|
|||
lines: lines
|
||||
}, callback
|
||||
|
||||
deleteDoc: (project_id, doc_id, callback = (error, res, body) ->) ->
|
||||
request.del {
|
||||
url: "http://localhost:3016/project/#{project_id}/doc/#{doc_id}"
|
||||
}, callback
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -86,3 +86,21 @@ describe "HttpController", ->
|
|||
@res.send
|
||||
.calledWith(400)
|
||||
.should.equal true
|
||||
|
||||
describe "deleteDoc", ->
|
||||
beforeEach ->
|
||||
@req.params =
|
||||
project_id: @project_id
|
||||
doc_id: @doc_id
|
||||
@DocManager.deleteDoc = sinon.stub().callsArg(2)
|
||||
@HttpController.deleteDoc @req, @res, @next
|
||||
|
||||
it "should delete the document", ->
|
||||
@DocManager.deleteDoc
|
||||
.calledWith(@project_id, @doc_id)
|
||||
.should.equal true
|
||||
|
||||
it "should return a 204 (No Content)", ->
|
||||
@res.send
|
||||
.calledWith(204)
|
||||
.should.equal true
|
||||
|
|
|
@ -8,7 +8,7 @@ describe "MongoManager", ->
|
|||
beforeEach ->
|
||||
@MongoManager = SandboxedModule.require modulePath, requires:
|
||||
"./mongojs":
|
||||
db: @db = { projects: {} }
|
||||
db: @db = { projects: {}, docs: {} }
|
||||
ObjectId: ObjectId
|
||||
@project_id = ObjectId().toString()
|
||||
@callback = sinon.stub()
|
||||
|
@ -55,11 +55,11 @@ describe "MongoManager", ->
|
|||
beforeEach ->
|
||||
@doc_id = ObjectId().toString()
|
||||
@lines = ["mock-lines"]
|
||||
@db.projects.insert = sinon.stub().callsArg(1)
|
||||
@db.docs.insert = sinon.stub().callsArg(1)
|
||||
@MongoManager.insertDoc @project_id, @doc_id, lines: @lines, @callback
|
||||
|
||||
it "should insert the attributes with the given doc and project id", ->
|
||||
@db.projects.insert
|
||||
@db.docs.insert
|
||||
.calledWith({
|
||||
_id: ObjectId(@doc_id)
|
||||
project_id: ObjectId(@project_id)
|
||||
|
|
Loading…
Reference in a new issue