2019-05-29 05:21:06 -04:00
|
|
|
/* eslint-disable
|
|
|
|
camelcase,
|
|
|
|
handle-callback-err,
|
|
|
|
max-len,
|
|
|
|
no-return-assign,
|
|
|
|
no-unused-vars,
|
|
|
|
no-useless-constructor,
|
|
|
|
*/
|
|
|
|
// TODO: This file was created by bulk-decaffeinate.
|
|
|
|
// Fix any style issues and re-enable lint.
|
|
|
|
/*
|
|
|
|
* decaffeinate suggestions:
|
|
|
|
* DS102: Remove unnecessary code created because of implicit returns
|
|
|
|
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
|
|
|
|
*/
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const chai = require('chai')
|
|
|
|
const { expect } = chai
|
|
|
|
const should = chai.should()
|
|
|
|
const modulePath =
|
|
|
|
'../../../../app/src/Features/Project/ProjectOptionsHandler.js'
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
|
|
|
|
describe('ProjectOptionsHandler', function() {
|
|
|
|
const project_id = '4eecaffcbffa66588e000008'
|
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
let Project
|
|
|
|
this.projectModel = Project = class Project {
|
|
|
|
constructor(options) {}
|
|
|
|
}
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne = sinon.stub().yields()
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2019-08-08 11:08:14 -04:00
|
|
|
this.handler = SandboxedModule.require(modulePath, {
|
2019-07-15 06:33:47 -04:00
|
|
|
globals: {
|
|
|
|
console: console
|
|
|
|
},
|
2019-05-29 05:21:06 -04:00
|
|
|
requires: {
|
|
|
|
'../../models/Project': { Project: this.projectModel },
|
|
|
|
'settings-sharelatex': {
|
|
|
|
languages: [
|
|
|
|
{ name: 'English', code: 'en' },
|
|
|
|
{ name: 'French', code: 'fr' }
|
|
|
|
],
|
|
|
|
imageRoot: 'docker-repo/subdir',
|
|
|
|
allowedImageNames: [
|
|
|
|
{ imageName: 'texlive-0000.0', imageDesc: 'test image 0' },
|
|
|
|
{ imageName: 'texlive-1234.5', imageDesc: 'test image 1' }
|
|
|
|
]
|
|
|
|
},
|
|
|
|
'logger-sharelatex': {
|
|
|
|
log() {},
|
|
|
|
err() {}
|
|
|
|
}
|
|
|
|
}
|
2019-08-08 11:08:14 -04:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('Setting the compiler', function() {
|
|
|
|
it('should perform and update on mongo', function(done) {
|
|
|
|
this.handler.setCompiler(project_id, 'xeLaTeX', err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
const args = this.projectModel.updateOne.args[0]
|
2019-05-29 05:21:06 -04:00
|
|
|
args[0]._id.should.equal(project_id)
|
|
|
|
args[1].compiler.should.equal('xelatex')
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-08-08 11:08:14 -04:00
|
|
|
it('should not perform and update on mongo if it is not a recognised compiler', function(done) {
|
|
|
|
this.handler.setCompiler(project_id, 'something', err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne.called.should.equal(false)
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when called without arg', function() {
|
|
|
|
it('should callback with null', function(done) {
|
|
|
|
this.handler.setCompiler(project_id, null, err => {
|
|
|
|
expect(err).to.be.undefined
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne.callCount.should.equal(0)
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when mongo update error occurs', function() {
|
|
|
|
beforeEach(function() {
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne = sinon.stub().yields('error')
|
2019-08-08 11:08:14 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should callback with error', function(done) {
|
|
|
|
this.handler.setCompiler(project_id, 'xeLaTeX', err => {
|
|
|
|
err.should.equal('error')
|
|
|
|
done()
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Setting the imageName', function() {
|
|
|
|
it('should perform and update on mongo', function(done) {
|
|
|
|
this.handler.setImageName(project_id, 'texlive-1234.5', err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
const args = this.projectModel.updateOne.args[0]
|
2019-05-29 05:21:06 -04:00
|
|
|
args[0]._id.should.equal(project_id)
|
|
|
|
args[1].imageName.should.equal('docker-repo/subdir/texlive-1234.5')
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should not perform and update on mongo if it is not a reconised compiler', function(done) {
|
2019-08-08 11:08:14 -04:00
|
|
|
this.handler.setImageName(project_id, 'something', err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne.called.should.equal(false)
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when called without arg', function() {
|
|
|
|
it('should callback with null', function(done) {
|
|
|
|
this.handler.setImageName(project_id, null, err => {
|
|
|
|
expect(err).to.be.undefined
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne.callCount.should.equal(0)
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when mongo update error occurs', function() {
|
|
|
|
beforeEach(function() {
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne = sinon.stub().yields('error')
|
2019-08-08 11:08:14 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should callback with error', function(done) {
|
|
|
|
this.handler.setImageName(project_id, 'texlive-1234.5', err => {
|
|
|
|
err.should.equal('error')
|
|
|
|
done()
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('setting the spellCheckLanguage', function() {
|
|
|
|
it('should perform and update on mongo', function(done) {
|
|
|
|
this.handler.setSpellCheckLanguage(project_id, 'fr', err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
const args = this.projectModel.updateOne.args[0]
|
2019-05-29 05:21:06 -04:00
|
|
|
args[0]._id.should.equal(project_id)
|
|
|
|
args[1].spellCheckLanguage.should.equal('fr')
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not perform and update on mongo if it is not a reconised compiler', function(done) {
|
2019-08-08 11:08:14 -04:00
|
|
|
this.handler.setSpellCheckLanguage(project_id, 'no a lang', err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne.called.should.equal(false)
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should perform and update on mongo if the language is blank (means turn it off)', function(done) {
|
2019-05-29 05:21:06 -04:00
|
|
|
this.handler.setSpellCheckLanguage(project_id, '', err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne.called.should.equal(true)
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when mongo update error occurs', function() {
|
|
|
|
beforeEach(function() {
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne = sinon.stub().yields('error')
|
2019-08-08 11:08:14 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should callback with error', function(done) {
|
|
|
|
this.handler.setSpellCheckLanguage(project_id, 'fr', err => {
|
|
|
|
err.should.equal('error')
|
|
|
|
done()
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('setting the brandVariationId', function() {
|
|
|
|
it('should perform and update on mongo', function(done) {
|
|
|
|
this.handler.setBrandVariationId(project_id, '123', err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
const args = this.projectModel.updateOne.args[0]
|
2019-05-29 05:21:06 -04:00
|
|
|
args[0]._id.should.equal(project_id)
|
|
|
|
args[1].brandVariationId.should.equal('123')
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not perform and update on mongo if there is no brand variation', function(done) {
|
2019-08-08 11:08:14 -04:00
|
|
|
this.handler.setBrandVariationId(project_id, null, err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne.called.should.equal(false)
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-06-21 09:46:09 -04:00
|
|
|
it('should not perform and update on mongo if brand variation is an empty string', function(done) {
|
2019-08-08 11:08:14 -04:00
|
|
|
this.handler.setBrandVariationId(project_id, '', err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne.called.should.equal(false)
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when mongo update error occurs', function() {
|
|
|
|
beforeEach(function() {
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne = sinon.stub().yields('error')
|
2019-08-08 11:08:14 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should callback with error', function(done) {
|
|
|
|
this.handler.setBrandVariationId(project_id, '123', err => {
|
|
|
|
err.should.equal('error')
|
|
|
|
done()
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2019-08-07 10:04:04 -04:00
|
|
|
describe('unsetting the brandVariationId', function() {
|
2019-05-29 05:21:06 -04:00
|
|
|
it('should perform and update on mongo', function(done) {
|
|
|
|
this.handler.unsetBrandVariationId(project_id, err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
const args = this.projectModel.updateOne.args[0]
|
2019-05-29 05:21:06 -04:00
|
|
|
args[0]._id.should.equal(project_id)
|
|
|
|
expect(args[1]).to.deep.equal({ $unset: { brandVariationId: 1 } })
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('when mongo update error occurs', function() {
|
|
|
|
beforeEach(function() {
|
2020-11-03 04:19:05 -05:00
|
|
|
this.projectModel.updateOne = sinon.stub().yields('error')
|
2019-08-08 11:08:14 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should callback with error', function(done) {
|
|
|
|
this.handler.unsetBrandVariationId(project_id, err => {
|
|
|
|
err.should.equal('error')
|
|
|
|
done()
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
2019-08-07 10:04:04 -04:00
|
|
|
})
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|