overleaf/services/web/test/unit/coffee/Project/ProjectOptionsHandlerTests.coffee

110 lines
3.8 KiB
CoffeeScript
Raw Normal View History

2014-02-12 05:23:40 -05:00
sinon = require('sinon')
chai = require('chai')
expect = chai.expect
2014-02-12 05:23:40 -05:00
should = chai.should()
modulePath = "../../../../app/js/Features/Project/ProjectOptionsHandler.js"
SandboxedModule = require('sandboxed-module')
2018-10-10 07:02:43 -04:00
describe 'ProjectOptionsHandler', ->
2014-02-12 05:23:40 -05:00
project_id = "4eecaffcbffa66588e000008"
beforeEach ->
@projectModel = class Project
constructor:(options)->
@projectModel.update = sinon.spy()
@handler = SandboxedModule.require modulePath, requires:
'../../models/Project':{Project:@projectModel}
'settings-sharelatex':
languages:[
{name: "English", code: "en"}
{name: "French", code: "fr"}
]
2018-08-13 05:48:11 -04:00
imageRoot: "docker-repo/subdir"
allowedImageNames: [
{imageName: "texlive-0000.0", imageDesc: "test image 0"}
{imageName: "texlive-1234.5", imageDesc: "test image 1"}
]
2014-02-12 05:23:40 -05:00
'logger-sharelatex':
log:->
err:->
describe 'Setting the compiler', ->
it 'should perform and update on mongo', (done)->
@handler.setCompiler project_id, "xeLaTeX", (err)=>
args = @projectModel.update.args[0]
args[0]._id.should.equal project_id
args[1].compiler.should.equal "xelatex"
done()
@projectModel.update.args[0][3]()
it 'should not perform and update on mongo if it is not a reconised compiler', (done)->
@handler.setCompiler project_id, "something", (err)=>
@projectModel.update.called.should.equal false
done()
2018-08-13 05:48:11 -04:00
describe 'Setting the imageName', ->
it 'should perform and update on mongo', (done)->
@handler.setImageName project_id, "texlive-1234.5", (err)=>
args = @projectModel.update.args[0]
args[0]._id.should.equal project_id
args[1].imageName.should.equal "docker-repo/subdir/texlive-1234.5"
done()
@projectModel.update.args[0][3]()
it 'should not perform and update on mongo if it is not a reconised compiler', (done)->
@handler.setImageName project_id, "something", (err)=>
@projectModel.update.called.should.equal false
done()
2014-02-12 05:23:40 -05:00
describe "setting the spellCheckLanguage", ->
it 'should perform and update on mongo', (done)->
@handler.setSpellCheckLanguage project_id, "fr", (err)=>
args = @projectModel.update.args[0]
args[0]._id.should.equal project_id
args[1].spellCheckLanguage.should.equal "fr"
done()
@projectModel.update.args[0][3]()
it 'should not perform and update on mongo if it is not a reconised compiler', (done)->
@handler.setSpellCheckLanguage project_id, "no a lang", (err)=>
@projectModel.update.called.should.equal false
done()
it 'should perform and update on mongo if the language is blank (means turn it off)', (done)->
@handler.setSpellCheckLanguage project_id, "", (err)=>
@projectModel.update.called.should.equal true
done()
@projectModel.update.args[0][3]()
2018-10-10 07:02:43 -04:00
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()
describe "unsetting the brandVariationId", ->
it 'should perform and update on mongo', (done)->
@handler.unsetBrandVariationId project_id, (err)=>
args = @projectModel.update.args[0]
args[0]._id.should.equal project_id
expect(args[1]).to.deep.equal {$unset: {brandVariationId: 1}}
done()
@projectModel.update.args[0][3]()