mirror of
https://github.com/overleaf/overleaf.git
synced 2025-03-15 04:14:47 +00:00
Add project export acceptance tests
- Add acceptance tests - Add `MockV1Api` helper - Add flush endpoint to `MockProjectHistoryApi` helper
This commit is contained in:
parent
e34dd90a1f
commit
3922b8b916
3 changed files with 102 additions and 0 deletions
56
services/web/test/acceptance/coffee/ExportsTests.coffee
Normal file
56
services/web/test/acceptance/coffee/ExportsTests.coffee
Normal file
|
@ -0,0 +1,56 @@
|
|||
expect = require('chai').expect
|
||||
request = require './helpers/request'
|
||||
_ = require 'underscore'
|
||||
|
||||
|
||||
User = require './helpers/User'
|
||||
ProjectGetter = require '../../../app/js/Features/Project/ProjectGetter.js'
|
||||
ExportsHandler = require '../../../app/js/Features/Exports/ExportsHandler.js'
|
||||
|
||||
MockProjectHistoryApi = require './helpers/MockProjectHistoryApi'
|
||||
MockV1Api = require './helpers/MockV1Api'
|
||||
|
||||
describe 'Exports', ->
|
||||
before (done) ->
|
||||
@brand_variation_id = '18'
|
||||
@owner = new User()
|
||||
@owner.login (error) =>
|
||||
throw error if error?
|
||||
@owner.createProject 'example-project', {template: 'example'}, (error, @project_id) =>
|
||||
throw error if error?
|
||||
done()
|
||||
|
||||
describe 'exporting a project', ->
|
||||
beforeEach (done) ->
|
||||
@version = Math.floor(Math.random() * 10000)
|
||||
MockProjectHistoryApi.setProjectVersion(@project_id, @version)
|
||||
@export_id = Math.floor(Math.random() * 10000)
|
||||
MockV1Api.setExportId(@export_id)
|
||||
MockV1Api.clearExportParams()
|
||||
@owner.request {
|
||||
method: 'POST',
|
||||
url: "/project/#{@project_id}/export/#{@brand_variation_id}",
|
||||
json: {},
|
||||
}, (error, response, body) =>
|
||||
throw error if error?
|
||||
expect(response.statusCode).to.equal 200
|
||||
@exportResponseBody = body
|
||||
done()
|
||||
|
||||
it 'should have sent correct data to v1', (done) ->
|
||||
{project, user, destination, options} = MockV1Api.getLastExportParams()
|
||||
# project details should match
|
||||
expect(project.id).to.equal @project_id
|
||||
expect(project.rootDocPath).to.equal '/main.tex'
|
||||
# version should match what was retrieved from project-history
|
||||
expect(project.historyVersion).to.equal @version
|
||||
# user details should match
|
||||
expect(user.id).to.equal @owner.id
|
||||
expect(user.email).to.equal @owner.email
|
||||
# brand-variation should match
|
||||
expect(destination.brandVariationId).to.equal @brand_variation_id
|
||||
done()
|
||||
|
||||
it 'should have returned the export ID provided by v1', (done) ->
|
||||
expect(@exportResponseBody.export_v1_id).to.equal @export_id
|
||||
done()
|
|
@ -6,9 +6,14 @@ module.exports = MockProjectHistoryApi =
|
|||
|
||||
oldFiles: {}
|
||||
|
||||
projectVersions: {}
|
||||
|
||||
addOldFile: (project_id, version, pathname, content) ->
|
||||
@oldFiles["#{project_id}:#{version}:#{pathname}"] = content
|
||||
|
||||
setProjectVersion: (project_id, version) ->
|
||||
@projectVersions[project_id] = version
|
||||
|
||||
run: () ->
|
||||
app.post "/project", (req, res, next) =>
|
||||
res.json project: id: 1
|
||||
|
@ -21,6 +26,13 @@ module.exports = MockProjectHistoryApi =
|
|||
else
|
||||
res.send 404
|
||||
|
||||
app.get "/project/:project_id/version", (req, res, next) =>
|
||||
{project_id} = req.params
|
||||
if @projectVersions[project_id]?
|
||||
res.json version: @projectVersions[project_id]
|
||||
else
|
||||
res.send 404
|
||||
|
||||
app.listen 3054, (error) ->
|
||||
throw error if error?
|
||||
.on "error", (error) ->
|
||||
|
|
34
services/web/test/acceptance/coffee/helpers/MockV1Api.coffee
Normal file
34
services/web/test/acceptance/coffee/helpers/MockV1Api.coffee
Normal file
|
@ -0,0 +1,34 @@
|
|||
express = require("express")
|
||||
app = express()
|
||||
bodyParser = require('body-parser')
|
||||
|
||||
app.use(bodyParser.json())
|
||||
|
||||
module.exports = MockV1Api =
|
||||
|
||||
exportId: null
|
||||
|
||||
exportParams: null
|
||||
|
||||
setExportId: (id) ->
|
||||
@exportId = id
|
||||
|
||||
getLastExportParams: () ->
|
||||
@exportParams
|
||||
|
||||
clearExportParams: () ->
|
||||
@exportParams = null
|
||||
|
||||
run: () ->
|
||||
app.post "/api/v1/sharelatex/exports", (req, res, next) =>
|
||||
#{project, version, pathname}
|
||||
@exportParams = Object.assign({}, req.body)
|
||||
res.json exportId: @exportId
|
||||
|
||||
app.listen 5000, (error) ->
|
||||
throw error if error?
|
||||
.on "error", (error) ->
|
||||
console.error "error starting MockOverleafAPI:", error.message
|
||||
process.exit(1)
|
||||
|
||||
MockV1Api.run()
|
Loading…
Reference in a new issue