overleaf/services/track-changes/test/acceptance/coffee/helpers/MockWebApi.coffee

42 lines
965 B
CoffeeScript
Raw Normal View History

express = require("express")
app = express()
module.exports = MockWebApi =
users: {}
projects: {}
2015-09-16 18:33:23 -04:00
getUserInfo: (user_id, callback = (error) ->) ->
callback null, @users[user_id] or null
2015-09-16 18:33:23 -04:00
getProjectDetails: (project_id, callback = (error, project) ->) ->
callback null, @projects[project_id]
run: () ->
app.get "/user/:user_id/personal_info", (req, res, next) =>
2015-09-16 18:33:23 -04:00
@getUserInfo req.params.user_id, (error, user) ->
if error?
res.send 500
if !user?
res.send 404
else
res.send JSON.stringify user
app.get "/project/:project_id/details", (req, res, next) =>
2015-09-16 18:33:23 -04:00
@getProjectDetails req.params.project_id, (error, project) ->
if error?
res.send 500
if !project?
res.send 404
else
res.send JSON.stringify project
app.listen 3000, (error) ->
throw error if error?
2017-10-20 10:24:58 -04:00
.on "error", (error) ->
console.error "error starting MockWebApiServer:", error.message
process.exit(1)
MockWebApi.run()