2019-05-29 05:21:06 -04:00
|
|
|
/* eslint-disable
|
2022-05-16 10:25:49 -04:00
|
|
|
n/handle-callback-err,
|
2019-05-29 05:21:06 -04:00
|
|
|
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')
|
2021-03-31 08:20:55 -04:00
|
|
|
const { expect } = require('chai')
|
2019-05-29 05:21:06 -04:00
|
|
|
const modulePath =
|
|
|
|
'../../../../app/src/Features/Project/ProjectOptionsHandler.js'
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('ProjectOptionsHandler', function () {
|
2023-03-21 09:21:57 -04:00
|
|
|
const projectId = '4eecaffcbffa66588e000008'
|
2019-05-29 05:21:06 -04:00
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
beforeEach(function () {
|
2019-05-29 05:21:06 -04:00
|
|
|
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-05-29 05:21:06 -04:00
|
|
|
requires: {
|
|
|
|
'../../models/Project': { Project: this.projectModel },
|
2021-07-07 05:38:56 -04:00
|
|
|
'@overleaf/settings': {
|
2019-05-29 05:21:06 -04:00
|
|
|
languages: [
|
|
|
|
{ name: 'English', code: 'en' },
|
2021-04-27 03:52:58 -04:00
|
|
|
{ name: 'French', code: 'fr' },
|
2019-05-29 05:21:06 -04:00
|
|
|
],
|
|
|
|
imageRoot: 'docker-repo/subdir',
|
|
|
|
allowedImageNames: [
|
|
|
|
{ imageName: 'texlive-0000.0', imageDesc: 'test image 0' },
|
2021-04-27 03:52:58 -04:00
|
|
|
{ imageName: 'texlive-1234.5', imageDesc: 'test image 1' },
|
|
|
|
],
|
|
|
|
},
|
|
|
|
},
|
2019-08-08 11:08:14 -04:00
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('Setting the compiler', function () {
|
|
|
|
it('should perform and update on mongo', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setCompiler(projectId, 'xeLaTeX', err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
const args = this.projectModel.updateOne.args[0]
|
2023-03-21 09:21:57 -04:00
|
|
|
args[0]._id.should.equal(projectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
args[1].compiler.should.equal('xelatex')
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should not perform and update on mongo if it is not a recognised compiler', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setCompiler(projectId, '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()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when called without arg', function () {
|
|
|
|
it('should callback with null', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setCompiler(projectId, null, err => {
|
2019-08-08 11:08:14 -04:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
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
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should callback with error', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setCompiler(projectId, 'xeLaTeX', err => {
|
2019-08-08 11:08:14 -04:00
|
|
|
err.should.equal('error')
|
|
|
|
done()
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('Setting the imageName', function () {
|
|
|
|
it('should perform and update on mongo', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setImageName(projectId, 'texlive-1234.5', err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
const args = this.projectModel.updateOne.args[0]
|
2023-03-21 09:21:57 -04:00
|
|
|
args[0]._id.should.equal(projectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
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
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should not perform and update on mongo if it is not a reconised compiler', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setImageName(projectId, '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()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('when called without arg', function () {
|
|
|
|
it('should callback with null', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setImageName(projectId, null, err => {
|
2019-08-08 11:08:14 -04:00
|
|
|
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()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
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
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should callback with error', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setImageName(projectId, 'texlive-1234.5', err => {
|
2019-08-08 11:08:14 -04:00
|
|
|
err.should.equal('error')
|
|
|
|
done()
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('setting the spellCheckLanguage', function () {
|
|
|
|
it('should perform and update on mongo', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setSpellCheckLanguage(projectId, 'fr', err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
const args = this.projectModel.updateOne.args[0]
|
2023-03-21 09:21:57 -04:00
|
|
|
args[0]._id.should.equal(projectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
args[1].spellCheckLanguage.should.equal('fr')
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should not perform and update on mongo if it is not a reconised compiler', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setSpellCheckLanguage(projectId, '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
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should perform and update on mongo if the language is blank (means turn it off)', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setSpellCheckLanguage(projectId, '', 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()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
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
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should callback with error', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setSpellCheckLanguage(projectId, 'fr', err => {
|
2019-08-08 11:08:14 -04:00
|
|
|
err.should.equal('error')
|
|
|
|
done()
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('setting the brandVariationId', function () {
|
|
|
|
it('should perform and update on mongo', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setBrandVariationId(projectId, '123', err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
const args = this.projectModel.updateOne.args[0]
|
2023-03-21 09:21:57 -04:00
|
|
|
args[0]._id.should.equal(projectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
args[1].brandVariationId.should.equal('123')
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should not perform and update on mongo if there is no brand variation', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setBrandVariationId(projectId, 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
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should not perform and update on mongo if brand variation is an empty string', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setBrandVariationId(projectId, '', 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()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
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
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should callback with error', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.setBrandVariationId(projectId, '123', err => {
|
2019-08-08 11:08:14 -04:00
|
|
|
err.should.equal('error')
|
|
|
|
done()
|
|
|
|
})
|
2019-05-29 05:21:06 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
describe('unsetting the brandVariationId', function () {
|
|
|
|
it('should perform and update on mongo', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.unsetBrandVariationId(projectId, err => {
|
2020-11-03 04:19:05 -05:00
|
|
|
const args = this.projectModel.updateOne.args[0]
|
2023-03-21 09:21:57 -04:00
|
|
|
args[0]._id.should.equal(projectId)
|
2019-05-29 05:21:06 -04:00
|
|
|
expect(args[1]).to.deep.equal({ $unset: { brandVariationId: 1 } })
|
2019-08-08 11:08:14 -04:00
|
|
|
done()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
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
|
|
|
})
|
|
|
|
|
2021-04-14 09:17:21 -04:00
|
|
|
it('should callback with error', function (done) {
|
2023-03-21 09:21:57 -04:00
|
|
|
this.handler.unsetBrandVariationId(projectId, err => {
|
2019-08-08 11:08:14 -04:00
|
|
|
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
|
|
|
})
|