mirror of
https://github.com/overleaf/overleaf.git
synced 2024-12-05 06:06:49 -05:00
d9e0215aee
Camel case variables in real-time GitOrigin-RevId: 0a35d2e39d54c258bed017ea4dcdbf9a19a2a9b1
91 lines
2.3 KiB
JavaScript
91 lines
2.3 KiB
JavaScript
/* eslint-disable
|
|
no-return-assign,
|
|
*/
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
// Fix any style issues and re-enable lint.
|
|
/*
|
|
* decaffeinate suggestions:
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
* DS207: Consider shorter variations of null checks
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
*/
|
|
let MockDocUpdaterServer
|
|
const sinon = require('sinon')
|
|
const express = require('express')
|
|
|
|
module.exports = MockDocUpdaterServer = {
|
|
docs: {},
|
|
|
|
createMockDoc(projectId, docId, data) {
|
|
return (MockDocUpdaterServer.docs[`${projectId}:${docId}`] = data)
|
|
},
|
|
|
|
getDocument(projectId, docId, fromVersion, callback) {
|
|
if (callback == null) {
|
|
callback = function () {}
|
|
}
|
|
return callback(null, MockDocUpdaterServer.docs[`${projectId}:${docId}`])
|
|
},
|
|
|
|
deleteProject: sinon.stub().callsArg(1),
|
|
|
|
getDocumentRequest(req, res, next) {
|
|
const { project_id: projectId, doc_id: docId } = req.params
|
|
let { fromVersion } = req.query
|
|
fromVersion = parseInt(fromVersion, 10)
|
|
return MockDocUpdaterServer.getDocument(
|
|
projectId,
|
|
docId,
|
|
fromVersion,
|
|
(error, data) => {
|
|
if (error != null) {
|
|
return next(error)
|
|
}
|
|
if (!data) {
|
|
return res.sendStatus(404)
|
|
}
|
|
return res.json(data)
|
|
}
|
|
)
|
|
},
|
|
|
|
deleteProjectRequest(req, res, next) {
|
|
const { project_id: projectId } = req.params
|
|
return MockDocUpdaterServer.deleteProject(projectId, error => {
|
|
if (error != null) {
|
|
return next(error)
|
|
}
|
|
return res.sendStatus(204)
|
|
})
|
|
},
|
|
|
|
running: false,
|
|
run(callback) {
|
|
if (callback == null) {
|
|
callback = function () {}
|
|
}
|
|
if (MockDocUpdaterServer.running) {
|
|
return callback()
|
|
}
|
|
const app = express()
|
|
app.get(
|
|
'/project/:project_id/doc/:doc_id',
|
|
MockDocUpdaterServer.getDocumentRequest
|
|
)
|
|
app.delete(
|
|
'/project/:project_id',
|
|
MockDocUpdaterServer.deleteProjectRequest
|
|
)
|
|
return app
|
|
.listen(3003, error => {
|
|
MockDocUpdaterServer.running = true
|
|
return callback(error)
|
|
})
|
|
.on('error', error => {
|
|
console.error('error starting MockDocUpdaterServer:', error.message)
|
|
return process.exit(1)
|
|
})
|
|
},
|
|
}
|
|
|
|
sinon.spy(MockDocUpdaterServer, 'getDocument')
|