mirror of
https://github.com/overleaf/overleaf.git
synced 2025-04-12 07:36:46 +00:00
Unit test brand variation id.
This commit is contained in:
parent
29787c42c5
commit
901fb0fc1e
4 changed files with 67 additions and 5 deletions
|
@ -49,7 +49,7 @@ module.exports =
|
|||
|
||||
setBrandVariationId: (project_id, brandVariationId, callback = ()->)->
|
||||
logger.log project_id:project_id, brandVariationId:brandVariationId, "setting the brand variation id"
|
||||
if !brandVariationId?
|
||||
if !brandVariationId? or brandVariationId == ""
|
||||
return callback()
|
||||
conditions = {_id:project_id}
|
||||
update = {brandVariationId}
|
||||
|
|
|
@ -110,7 +110,6 @@ setMainFile = (project_id, mainFile, callback) ->
|
|||
callback()
|
||||
|
||||
setBrandVariationId = (project_id, brandVariationId, callback) ->
|
||||
logger.log brandVariationId, "brandVariationId"
|
||||
if brandVariationId?
|
||||
ProjectOptionsHandler.setBrandVariationId project_id, brandVariationId, callback
|
||||
else
|
||||
|
|
|
@ -4,7 +4,7 @@ should = chai.should()
|
|||
modulePath = "../../../../app/js/Features/Project/ProjectOptionsHandler.js"
|
||||
SandboxedModule = require('sandboxed-module')
|
||||
|
||||
describe 'creating a project', ->
|
||||
describe 'ProjectOptionsHandler', ->
|
||||
project_id = "4eecaffcbffa66588e000008"
|
||||
|
||||
beforeEach ->
|
||||
|
@ -77,3 +77,23 @@ describe 'creating a project', ->
|
|||
@projectModel.update.called.should.equal true
|
||||
done()
|
||||
@projectModel.update.args[0][3]()
|
||||
|
||||
describe "setting the brandVariationId", ->
|
||||
it 'should perform and update on mongo', (done)->
|
||||
@handler.setBrandVariationId project_id, "123", (err)=>
|
||||
args = @projectModel.update.args[0]
|
||||
args[0]._id.should.equal project_id
|
||||
args[1].brandVariationId.should.equal "123"
|
||||
done()
|
||||
@projectModel.update.args[0][3]()
|
||||
|
||||
|
||||
it 'should not perform and update on mongo if there is no brand variation', (done)->
|
||||
@handler.setBrandVariationId project_id, null, (err)=>
|
||||
@projectModel.update.called.should.equal false
|
||||
done()
|
||||
|
||||
it 'should not perform and update on mongo if brand variation is an empty string', (done)->
|
||||
@handler.setBrandVariationId project_id, "", (err)=>
|
||||
@projectModel.update.called.should.equal false
|
||||
done()
|
||||
|
|
|
@ -8,7 +8,7 @@ modulePath = '../../../../app/js/Features/Templates/TemplatesController'
|
|||
|
||||
describe 'TemplatesController', ->
|
||||
|
||||
project_id = "213432"
|
||||
@project_id = "213432"
|
||||
|
||||
beforeEach ->
|
||||
@request = sinon.stub()
|
||||
|
@ -20,11 +20,12 @@ describe 'TemplatesController', ->
|
|||
unlink : sinon.stub()
|
||||
createWriteStream : sinon.stub().returns(on:(_, cb)->cb())
|
||||
}
|
||||
@ProjectUploadManager = {createProjectFromZipArchive : sinon.stub().callsArgWith(3, null, {_id:project_id})}
|
||||
@ProjectUploadManager = {createProjectFromZipArchive : sinon.stub().callsArgWith(3, null, {_id:@project_id})}
|
||||
@dumpFolder = "dump/path"
|
||||
@ProjectOptionsHandler = {
|
||||
setCompiler:sinon.stub().callsArgWith(2)
|
||||
setImageName:sinon.stub().callsArgWith(2)
|
||||
setBrandVariationId:sinon.stub().callsArgWith(2)
|
||||
}
|
||||
@uuid = "1234"
|
||||
@ProjectRootDocManager = {
|
||||
|
@ -83,3 +84,45 @@ describe 'TemplatesController', ->
|
|||
done()
|
||||
res = redirect:redirect
|
||||
@controller.createProjectFromV1Template @req, res
|
||||
|
||||
it "should set project options based on payload data", (done)->
|
||||
@compiler = "pdflatex"
|
||||
@mainFile = "main.tex"
|
||||
@brandVariationId = "123"
|
||||
|
||||
@req.body =
|
||||
templateVersionId: 15
|
||||
templateId: 14231
|
||||
name: @templateName
|
||||
compiler: @compiler
|
||||
mainFile: @mainFile
|
||||
brandVariationId: @brandVariationId
|
||||
|
||||
redirect = =>
|
||||
@ProjectOptionsHandler.setCompiler.calledWith(@project_id, @compiler).should.equal true
|
||||
@ProjectOptionsHandler.setBrandVariationId.calledWith(@project_id, @brandVariationId).should.equal true
|
||||
@ProjectRootDocManager.setRootDocFromName.calledWith(@project_id, @mainFile).should.equal true
|
||||
done()
|
||||
res = redirect:redirect
|
||||
@controller.createProjectFromV1Template @req, res
|
||||
|
||||
it "should only set project options which are defined in the payload", (done)->
|
||||
@compiler = "pdflatex"
|
||||
@brandVariationId = "123"
|
||||
|
||||
@req.body =
|
||||
templateVersionId: 15
|
||||
templateId: 14231
|
||||
name: @templateName
|
||||
compiler: @compiler
|
||||
brandVariationId: @brandVariationId
|
||||
|
||||
redirect = =>
|
||||
# Payload doesn't refine a main file, so `setRootDocFromName` should not be called
|
||||
@ProjectOptionsHandler.setCompiler.calledWith(@project_id, @compiler).should.equal true
|
||||
@ProjectOptionsHandler.setBrandVariationId.calledWith(@project_id, @brandVariationId).should.equal true
|
||||
@ProjectRootDocManager.setRootDocFromName.called.should.equal false
|
||||
done()
|
||||
res = redirect:redirect
|
||||
@controller.createProjectFromV1Template @req, res
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue