mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
add v1 template tests
This commit is contained in:
parent
7f86ddc72c
commit
d47e845367
3 changed files with 85 additions and 1 deletions
|
@ -1,7 +1,7 @@
|
|||
path = require('path')
|
||||
Project = require('../../../js/models/Project').Project
|
||||
ProjectUploadManager = require('../../../js/Features/Uploads/ProjectUploadManager')
|
||||
ProjectOptionsHandler = require("../../../js/Features/Project/ProjectOptionsHandler")
|
||||
ProjectOptionsHandler = require('../../../js/Features/Project/ProjectOptionsHandler')
|
||||
AuthenticationController = require('../../../js/Features/Authentication/AuthenticationController')
|
||||
settings = require('settings-sharelatex')
|
||||
fs = require('fs')
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
settings = require("settings-sharelatex")
|
||||
logger = require("logger-sharelatex")
|
||||
|
||||
module.exports =
|
||||
saveTemplateDataInSession: (req, res, next)->
|
||||
if req.query.templateName
|
||||
req.session.templateData = req.query
|
||||
next()
|
|
@ -0,0 +1,76 @@
|
|||
should = require('chai').should()
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
assert = require('assert')
|
||||
path = require('path')
|
||||
sinon = require('sinon')
|
||||
modulePath = '../../../../app/js/Features/Templates/TemplatesController'
|
||||
|
||||
|
||||
describe 'TemplatesController', ->
|
||||
|
||||
project_id = "213432"
|
||||
|
||||
beforeEach ->
|
||||
@request = sinon.stub()
|
||||
@request.returns {
|
||||
pipe:->
|
||||
on:->
|
||||
}
|
||||
@fs = {
|
||||
unlink : sinon.stub()
|
||||
createWriteStream : sinon.stub().returns(on:(_, cb)->cb())
|
||||
}
|
||||
@ProjectUploadManager = {createProjectFromZipArchive : sinon.stub().callsArgWith(3, null, {_id:project_id})}
|
||||
@dumpFolder = "dump/path"
|
||||
@ProjectOptionsHandler = {setCompiler:sinon.stub().callsArgWith(2)}
|
||||
@uuid = "1234"
|
||||
@ProjectDetailsHandler =
|
||||
getProjectDescription:sinon.stub()
|
||||
@Project =
|
||||
update: sinon.stub().callsArgWith(3, null)
|
||||
@controller = SandboxedModule.require modulePath, requires:
|
||||
'../../../js/Features/Uploads/ProjectUploadManager':@ProjectUploadManager
|
||||
'../../../js/Features/Project/ProjectOptionsHandler':@ProjectOptionsHandler
|
||||
'../../../js/Features/Authentication/AuthenticationController': @AuthenticationController = {getLoggedInUserId: sinon.stub()}
|
||||
'./TemplatesPublisher':@TemplatesPublisher
|
||||
"logger-sharelatex":
|
||||
log:->
|
||||
err:->
|
||||
"settings-sharelatex":
|
||||
path:
|
||||
dumpFolder:@dumpFolder
|
||||
siteUrl: @siteUrl = "http://localhost:3000"
|
||||
apis:
|
||||
v1:
|
||||
url: @v1Url="http://overleaf.com"
|
||||
user: "sharelatex"
|
||||
pass: "password"
|
||||
overleaf:
|
||||
host: @v1Url
|
||||
"uuid":v4:=>@uuid
|
||||
"request": @request
|
||||
"fs":@fs
|
||||
"../../../../app/js/models/Project": {Project: @Project}
|
||||
@zipUrl = "%2Ftemplates%2F52fb86a81ae1e566597a25f6%2Fv%2F4%2Fzip&templateName=Moderncv%20Banking&compiler=pdflatex"
|
||||
@templateName = "project name here"
|
||||
@user_id = "1234"
|
||||
@req =
|
||||
session:
|
||||
user: _id:@user_id
|
||||
templateData:
|
||||
zipUrl: @zipUrl
|
||||
templateName: @templateName
|
||||
@redirect = {}
|
||||
@AuthenticationController.getLoggedInUserId.returns(@user_id)
|
||||
|
||||
describe 'v1Templates', ->
|
||||
|
||||
it "should fetch zip from v1 based on template id", (done)->
|
||||
@templateVersionId = 15
|
||||
@req.body = {templateVersionId: @templateVersionId}
|
||||
|
||||
redirect = =>
|
||||
@request.calledWith("#{@v1Url}/api/v1/sharelatex/templates/#{@templateVersionId}").should.equal true
|
||||
done()
|
||||
res = redirect:redirect
|
||||
@controller.createProjectFromV1Template @req, res
|
Loading…
Reference in a new issue