2018-03-22 09:49:12 +00:00
|
|
|
express = require("express")
|
|
|
|
app = express()
|
|
|
|
bodyParser = require('body-parser')
|
2018-05-29 16:21:42 +00:00
|
|
|
sinon = require 'sinon'
|
2018-03-22 09:49:12 +00:00
|
|
|
|
|
|
|
app.use(bodyParser.json())
|
|
|
|
|
|
|
|
module.exports = MockV1Api =
|
2018-05-16 15:31:28 +00:00
|
|
|
users: { }
|
|
|
|
|
|
|
|
setUser: (id, user) ->
|
|
|
|
@users[id] = user
|
2018-03-22 09:49:12 +00:00
|
|
|
|
|
|
|
exportId: null
|
|
|
|
|
|
|
|
exportParams: null
|
|
|
|
|
|
|
|
setExportId: (id) ->
|
|
|
|
@exportId = id
|
|
|
|
|
|
|
|
getLastExportParams: () ->
|
|
|
|
@exportParams
|
|
|
|
|
|
|
|
clearExportParams: () ->
|
|
|
|
@exportParams = null
|
|
|
|
|
2018-05-29 16:21:42 +00:00
|
|
|
syncUserFeatures: sinon.stub()
|
|
|
|
|
2018-07-10 09:42:17 +00:00
|
|
|
affiliations: []
|
|
|
|
|
|
|
|
setAffiliations: (affiliations) -> @affiliations = affiliations
|
|
|
|
|
2018-03-22 09:49:12 +00:00
|
|
|
run: () ->
|
2018-05-29 16:21:42 +00:00
|
|
|
app.get "/api/v1/sharelatex/users/:v1_user_id/plan_code", (req, res, next) =>
|
|
|
|
user = @users[req.params.v1_user_id]
|
2018-05-16 15:31:28 +00:00
|
|
|
if user
|
|
|
|
res.json user
|
|
|
|
else
|
|
|
|
res.sendStatus 404
|
|
|
|
|
2018-05-29 16:21:42 +00:00
|
|
|
app.post "/api/v1/sharelatex/users/:v1_user_id/sync", (req, res, next) =>
|
|
|
|
@syncUserFeatures(req.params.v1_user_id)
|
|
|
|
res.sendStatus 200
|
|
|
|
|
2018-03-22 09:49:12 +00:00
|
|
|
app.post "/api/v1/sharelatex/exports", (req, res, next) =>
|
|
|
|
@exportParams = Object.assign({}, req.body)
|
|
|
|
res.json exportId: @exportId
|
|
|
|
|
2018-06-21 10:30:12 +00:00
|
|
|
app.get "/api/v2/users/:userId/affiliations", (req, res, next) =>
|
2018-07-10 09:42:17 +00:00
|
|
|
res.json @affiliations
|
2018-06-21 10:30:12 +00:00
|
|
|
|
2018-06-21 15:59:35 +00:00
|
|
|
app.post "/api/v2/users/:userId/affiliations", (req, res, next) =>
|
|
|
|
res.sendStatus 201
|
|
|
|
|
|
|
|
app.delete "/api/v2/users/:userId/affiliations/:email", (req, res, next) =>
|
|
|
|
res.sendStatus 204
|
2018-05-29 16:21:42 +00:00
|
|
|
|
2018-07-04 16:59:19 +00:00
|
|
|
app.get '/universities/list', (req, res, next) ->
|
|
|
|
res.json []
|
|
|
|
|
|
|
|
app.get '/universities/list/:id', (req, res, next) ->
|
|
|
|
res.json id: parseInt(req.params.id)
|
|
|
|
|
|
|
|
app.get '/university/domains', (req, res, next) ->
|
|
|
|
res.json []
|
|
|
|
|
2018-03-22 09:49:12 +00:00
|
|
|
app.listen 5000, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
.on "error", (error) ->
|
2018-05-16 15:31:28 +00:00
|
|
|
console.error "error starting MockV1Api:", error.message
|
2018-03-22 09:49:12 +00:00
|
|
|
process.exit(1)
|
|
|
|
|
|
|
|
MockV1Api.run()
|