overleaf/services/docstore/test/acceptance/coffee/helpers/DocstoreClient.coffee

53 lines
1.8 KiB
CoffeeScript
Raw Normal View History

request = require("request").defaults(jar: false)
{db, ObjectId} = require("../../../../app/js/mongojs")
2015-06-01 17:24:40 -04:00
settings = require("settings-sharelatex")
2015-06-02 18:24:45 -04:00
DocArchiveManager = require("../../../../app/js/DocArchiveManager.js")
module.exports = DocstoreClient =
2014-04-30 08:06:12 -04:00
2014-05-16 08:06:35 -04:00
createDoc: (project_id, doc_id, lines, callback = (error) ->) ->
db.docs.save({_id: doc_id, project_id:project_id, lines: lines, rev:1}, callback)
createDeletedDoc: (project_id, doc_id, lines, callback = (error) ->) ->
db.docs.insert {
_id: doc_id
project_id: project_id
lines: lines
deleted: true
}, callback
getDoc: (project_id, doc_id, qs, callback = (error, res, body) ->) ->
request.get {
2015-06-01 17:24:40 -04:00
url: "http://localhost:#{settings.internal.docstore.port}/project/#{project_id}/doc/#{doc_id}"
json: true
qs:qs
}, callback
2014-04-30 08:06:12 -04:00
getAllDocs: (project_id, callback = (error, res, body) ->) ->
request.get {
2015-06-01 17:24:40 -04:00
url: "http://localhost:#{settings.internal.docstore.port}/project/#{project_id}/doc"
2014-04-30 08:06:12 -04:00
json: true
}, callback
2014-05-16 08:06:35 -04:00
updateDoc: (project_id, doc_id, lines, callback = (error, res, body) ->) ->
request.post {
2015-06-01 17:24:40 -04:00
url: "http://localhost:#{settings.internal.docstore.port}/project/#{project_id}/doc/#{doc_id}"
json:
lines: lines
}, callback
deleteDoc: (project_id, doc_id, callback = (error, res, body) ->) ->
request.del {
2015-06-01 17:24:40 -04:00
url: "http://localhost:#{settings.internal.docstore.port}/project/#{project_id}/doc/#{doc_id}"
}, callback
2015-06-01 17:24:40 -04:00
archiveAllDoc: (project_id, callback = (error, res, body) ->) ->
request.post {
url: "http://localhost:#{settings.internal.docstore.port}/project/#{project_id}/archive"
}, callback
2015-06-02 18:24:45 -04:00
getS3Doc: (project_id, doc_id, callback = (error, res, body) ->) ->
options = DocArchiveManager.buildS3Options(true, project_id+"/"+doc_id)
request.get options, callback