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

32 lines
811 B
CoffeeScript
Raw Normal View History

2017-11-27 12:09:51 -05:00
express = require("express")
app = express()
module.exports = MockFileStoreApi =
files: {}
run: () ->
app.post "/project/:project_id/file/:file_id", (req, res, next) =>
2018-02-14 10:12:46 -05:00
chunks = []
req.on 'data', (chunk) ->
chunks.push(chunk)
2017-11-27 12:09:51 -05:00
req.on 'end', =>
2018-02-14 10:12:46 -05:00
content = Buffer.concat(chunks).toString()
{project_id, file_id} = req.params
@files[project_id] ?= {}
2018-02-14 10:12:46 -05:00
@files[project_id][file_id] = { content }
res.sendStatus 200
2017-11-27 12:09:51 -05:00
2018-02-14 10:12:46 -05:00
app.get "/project/:project_id/file/:file_id", (req, res, next) =>
{project_id, file_id} = req.params
{ content } = @files[project_id][file_id]
res.send content
2017-11-27 12:09:51 -05:00
app.listen 3009, (error) ->
throw error if error?
.on "error", (error) ->
console.error "error starting MockFileStoreApi:", error.message
process.exit(1)
MockFileStoreApi.run()