overleaf/services/web/test/acceptance/coffee/helpers/MockDocUpdaterApi.coffee

46 lines
1.3 KiB
CoffeeScript
Raw Normal View History

express = require("express")
app = express()
2017-11-27 12:09:51 -05:00
bodyParser = require "body-parser"
jsonParser = bodyParser.json()
module.exports = MockDocUpdaterApi =
updates: {}
2017-11-27 12:09:51 -05:00
clearProjectStructureUpdates: () ->
@updates = {}
2017-11-27 12:09:51 -05:00
getProjectStructureUpdates: (project_id) ->
@updates[project_id] || { docUpdates: [], fileUpdates: [] }
2017-11-27 12:09:51 -05:00
addProjectStructureUpdates: (project_id, userId, docUpdates, fileUpdates) ->
@updates[project_id] ||= { docUpdates: [], fileUpdates: [] }
2017-11-27 12:09:51 -05:00
for update in docUpdates
update.userId = userId
@updates[project_id].docUpdates.push(update)
2017-11-27 12:09:51 -05:00
for update in fileUpdates
update.userId = userId
@updates[project_id].fileUpdates.push(update)
2017-11-27 12:09:51 -05:00
run: () ->
app.post "/project/:project_id/flush", (req, res, next) =>
res.sendStatus 200
2017-11-27 12:09:51 -05:00
app.post "/project/:project_id", jsonParser, (req, res, next) =>
project_id = req.params.project_id
{userId, docUpdates, fileUpdates} = req.body
@addProjectStructureUpdates(project_id, userId, docUpdates, fileUpdates)
res.sendStatus 200
app.delete "/project/:project_id/doc/:doc_id", (req, res, next) =>
res.send 204
app.listen 3003, (error) ->
throw error if error?
2017-10-20 10:31:10 -04:00
.on "error", (error) ->
console.error "error starting MockDocUpdaterApi:", error.message
process.exit(1)
MockDocUpdaterApi.run()