2018-03-22 05:49:12 -04:00
|
|
|
express = require("express")
|
|
|
|
app = express()
|
|
|
|
bodyParser = require('body-parser')
|
2018-05-29 12:21:42 -04:00
|
|
|
sinon = require 'sinon'
|
2018-03-22 05:49:12 -04:00
|
|
|
|
|
|
|
app.use(bodyParser.json())
|
|
|
|
|
|
|
|
module.exports = MockV1Api =
|
2018-05-16 11:31:28 -04:00
|
|
|
users: { }
|
|
|
|
|
|
|
|
setUser: (id, user) ->
|
|
|
|
@users[id] = user
|
2018-03-22 05:49:12 -04:00
|
|
|
|
|
|
|
exportId: null
|
|
|
|
|
|
|
|
exportParams: null
|
|
|
|
|
|
|
|
setExportId: (id) ->
|
|
|
|
@exportId = id
|
|
|
|
|
|
|
|
getLastExportParams: () ->
|
|
|
|
@exportParams
|
|
|
|
|
|
|
|
clearExportParams: () ->
|
|
|
|
@exportParams = null
|
|
|
|
|
2018-05-29 12:21:42 -04:00
|
|
|
syncUserFeatures: sinon.stub()
|
|
|
|
|
2018-07-10 05:42:17 -04:00
|
|
|
affiliations: []
|
|
|
|
|
2018-07-16 08:26:52 -04:00
|
|
|
updateEmail: sinon.stub()
|
|
|
|
|
2018-07-16 12:25:52 -04:00
|
|
|
existingEmails: []
|
|
|
|
|
2018-07-10 05:42:17 -04:00
|
|
|
setAffiliations: (affiliations) -> @affiliations = affiliations
|
|
|
|
|
2018-03-22 05:49:12 -04:00
|
|
|
run: () ->
|
2018-05-29 12:21:42 -04: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 11:31:28 -04:00
|
|
|
if user
|
|
|
|
res.json user
|
|
|
|
else
|
|
|
|
res.sendStatus 404
|
|
|
|
|
2018-05-29 12:21:42 -04: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 05:49:12 -04:00
|
|
|
app.post "/api/v1/sharelatex/exports", (req, res, next) =>
|
|
|
|
@exportParams = Object.assign({}, req.body)
|
|
|
|
res.json exportId: @exportId
|
|
|
|
|
2018-06-21 06:30:12 -04:00
|
|
|
app.get "/api/v2/users/:userId/affiliations", (req, res, next) =>
|
2018-07-10 05:42:17 -04:00
|
|
|
res.json @affiliations
|
2018-06-21 06:30:12 -04:00
|
|
|
|
2018-06-21 11:59:35 -04: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 12:21:42 -04:00
|
|
|
|
2018-07-04 12:59:19 -04: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-07-16 08:26:52 -04:00
|
|
|
app.put '/api/v1/sharelatex/users/:id/email', (req, res, next) =>
|
2018-07-17 06:12:09 -04:00
|
|
|
{ email } = req.body?.user
|
2018-07-16 12:25:52 -04:00
|
|
|
if email in @existingEmails
|
|
|
|
return res.sendStatus 409
|
|
|
|
else
|
|
|
|
@updateEmail parseInt(req.params.id), email
|
|
|
|
return res.sendStatus 200
|
2018-07-16 08:26:52 -04:00
|
|
|
|
2018-03-22 05:49:12 -04:00
|
|
|
app.listen 5000, (error) ->
|
|
|
|
throw error if error?
|
|
|
|
.on "error", (error) ->
|
2018-05-16 11:31:28 -04:00
|
|
|
console.error "error starting MockV1Api:", error.message
|
2018-03-22 05:49:12 -04:00
|
|
|
process.exit(1)
|
2018-09-24 18:03:28 -04:00
|
|
|
|
2018-09-25 06:45:27 -04:00
|
|
|
app.get '/api/v1/sharelatex/docs/:token/is_published', (req, res, next) =>
|
2018-09-24 18:03:28 -04:00
|
|
|
res.json { allow: true }
|
2018-03-22 05:49:12 -04:00
|
|
|
|
|
|
|
MockV1Api.run()
|