ProjectOptionsHandlerTests.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /* eslint-disable
  2. camelcase,
  3. handle-callback-err,
  4. max-len,
  5. no-return-assign,
  6. no-unused-vars,
  7. no-useless-constructor,
  8. */
  9. // TODO: This file was created by bulk-decaffeinate.
  10. // Fix any style issues and re-enable lint.
  11. /*
  12. * decaffeinate suggestions:
  13. * DS102: Remove unnecessary code created because of implicit returns
  14. * Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
  15. */
  16. const sinon = require('sinon')
  17. const chai = require('chai')
  18. const { expect } = chai
  19. const should = chai.should()
  20. const modulePath =
  21. '../../../../app/src/Features/Project/ProjectOptionsHandler.js'
  22. const SandboxedModule = require('sandboxed-module')
  23. describe('ProjectOptionsHandler', function() {
  24. const project_id = '4eecaffcbffa66588e000008'
  25. beforeEach(function() {
  26. let Project
  27. this.projectModel = Project = class Project {
  28. constructor(options) {}
  29. }
  30. this.projectModel.update = sinon.spy()
  31. return (this.handler = SandboxedModule.require(modulePath, {
  32. requires: {
  33. '../../models/Project': { Project: this.projectModel },
  34. 'settings-sharelatex': {
  35. languages: [
  36. { name: 'English', code: 'en' },
  37. { name: 'French', code: 'fr' }
  38. ],
  39. imageRoot: 'docker-repo/subdir',
  40. allowedImageNames: [
  41. { imageName: 'texlive-0000.0', imageDesc: 'test image 0' },
  42. { imageName: 'texlive-1234.5', imageDesc: 'test image 1' }
  43. ]
  44. },
  45. 'logger-sharelatex': {
  46. log() {},
  47. err() {}
  48. }
  49. }
  50. }))
  51. })
  52. describe('Setting the compiler', function() {
  53. it('should perform and update on mongo', function(done) {
  54. this.handler.setCompiler(project_id, 'xeLaTeX', err => {
  55. const args = this.projectModel.update.args[0]
  56. args[0]._id.should.equal(project_id)
  57. args[1].compiler.should.equal('xelatex')
  58. return done()
  59. })
  60. return this.projectModel.update.args[0][3]()
  61. })
  62. return it('should not perform and update on mongo if it is not a reconised compiler', function(done) {
  63. return this.handler.setCompiler(project_id, 'something', err => {
  64. this.projectModel.update.called.should.equal(false)
  65. return done()
  66. })
  67. })
  68. })
  69. describe('Setting the imageName', function() {
  70. it('should perform and update on mongo', function(done) {
  71. this.handler.setImageName(project_id, 'texlive-1234.5', err => {
  72. const args = this.projectModel.update.args[0]
  73. args[0]._id.should.equal(project_id)
  74. args[1].imageName.should.equal('docker-repo/subdir/texlive-1234.5')
  75. return done()
  76. })
  77. return this.projectModel.update.args[0][3]()
  78. })
  79. return it('should not perform and update on mongo if it is not a reconised compiler', function(done) {
  80. return this.handler.setImageName(project_id, 'something', err => {
  81. this.projectModel.update.called.should.equal(false)
  82. return done()
  83. })
  84. })
  85. })
  86. describe('setting the spellCheckLanguage', function() {
  87. it('should perform and update on mongo', function(done) {
  88. this.handler.setSpellCheckLanguage(project_id, 'fr', err => {
  89. const args = this.projectModel.update.args[0]
  90. args[0]._id.should.equal(project_id)
  91. args[1].spellCheckLanguage.should.equal('fr')
  92. return done()
  93. })
  94. return this.projectModel.update.args[0][3]()
  95. })
  96. it('should not perform and update on mongo if it is not a reconised compiler', function(done) {
  97. return this.handler.setSpellCheckLanguage(
  98. project_id,
  99. 'no a lang',
  100. err => {
  101. this.projectModel.update.called.should.equal(false)
  102. return done()
  103. }
  104. )
  105. })
  106. return it('should perform and update on mongo if the language is blank (means turn it off)', function(done) {
  107. this.handler.setSpellCheckLanguage(project_id, '', err => {
  108. this.projectModel.update.called.should.equal(true)
  109. return done()
  110. })
  111. return this.projectModel.update.args[0][3]()
  112. })
  113. })
  114. describe('setting the brandVariationId', function() {
  115. it('should perform and update on mongo', function(done) {
  116. this.handler.setBrandVariationId(project_id, '123', err => {
  117. const args = this.projectModel.update.args[0]
  118. args[0]._id.should.equal(project_id)
  119. args[1].brandVariationId.should.equal('123')
  120. return done()
  121. })
  122. return this.projectModel.update.args[0][3]()
  123. })
  124. it('should not perform and update on mongo if there is no brand variation', function(done) {
  125. return this.handler.setBrandVariationId(project_id, null, err => {
  126. this.projectModel.update.called.should.equal(false)
  127. return done()
  128. })
  129. })
  130. return it('should not perform and update on mongo if brand variation is an empty string', function(done) {
  131. return this.handler.setBrandVariationId(project_id, '', err => {
  132. this.projectModel.update.called.should.equal(false)
  133. return done()
  134. })
  135. })
  136. })
  137. return describe('unsetting the brandVariationId', () =>
  138. it('should perform and update on mongo', function(done) {
  139. this.handler.unsetBrandVariationId(project_id, err => {
  140. const args = this.projectModel.update.args[0]
  141. args[0]._id.should.equal(project_id)
  142. expect(args[1]).to.deep.equal({ $unset: { brandVariationId: 1 } })
  143. return done()
  144. })
  145. return this.projectModel.update.args[0][3]()
  146. }))
  147. })