FeaturesTests.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. const { expect } = require('chai')
  2. const modulePath = '../../../../app/src/infrastructure/Features.js'
  3. const SandboxedModule = require('sandboxed-module')
  4. describe('Features', function () {
  5. beforeEach(function () {
  6. this.Features = SandboxedModule.require(modulePath, {
  7. requires: {
  8. '@overleaf/settings': (this.settings = {
  9. moduleImportSequence: [],
  10. enabledLinkedFileTypes: [],
  11. }),
  12. },
  13. })
  14. })
  15. describe('externalAuthenticationSystemUsed', function () {
  16. describe('without any settings', function () {
  17. it('should return false', function () {
  18. expect(this.Features.externalAuthenticationSystemUsed()).to.be.false
  19. })
  20. })
  21. describe('with ldap setting', function () {
  22. beforeEach(function () {
  23. this.settings.ldap = { enable: true }
  24. })
  25. it('should return true', function () {
  26. expect(this.Features.externalAuthenticationSystemUsed()).to.be.true
  27. })
  28. })
  29. describe('with saml setting', function () {
  30. beforeEach(function () {
  31. this.settings.saml = { enable: true }
  32. })
  33. it('should return true', function () {
  34. expect(this.Features.externalAuthenticationSystemUsed()).to.be.true
  35. })
  36. })
  37. describe('with oauth setting', function () {
  38. beforeEach(function () {
  39. this.settings.overleaf = { oauth: true }
  40. })
  41. it('should return true', function () {
  42. expect(this.Features.externalAuthenticationSystemUsed()).to.be.true
  43. })
  44. })
  45. })
  46. describe('hasFeature', function () {
  47. describe('without any settings', function () {
  48. it('should return true', function () {
  49. expect(this.Features.hasFeature('registration-page')).to.be.true
  50. expect(this.Features.hasFeature('templates-server-pro')).to.be.true
  51. })
  52. it('should return false', function () {
  53. expect(this.Features.hasFeature('registration')).to.be.false
  54. expect(this.Features.hasFeature('affiliations')).to.be.false
  55. expect(this.Features.hasFeature('analytics')).to.be.false
  56. expect(this.Features.hasFeature('custom-togglers')).to.be.false
  57. expect(this.Features.hasFeature('git-bridge')).to.be.false
  58. expect(this.Features.hasFeature('github-sync')).to.be.false
  59. expect(this.Features.hasFeature('homepage')).to.be.false
  60. expect(this.Features.hasFeature('link-url')).to.be.false
  61. expect(this.Features.hasFeature('oauth')).to.be.false
  62. expect(this.Features.hasFeature('overleaf-integration')).to.be.false
  63. expect(this.Features.hasFeature('references')).to.be.false
  64. expect(this.Features.hasFeature('saml')).to.be.false
  65. })
  66. })
  67. describe('with settings', function () {
  68. describe('empty overleaf object', function () {
  69. beforeEach(function () {
  70. this.settings.overleaf = {}
  71. this.settings.apis = {}
  72. })
  73. it('should return true', function () {
  74. expect(this.Features.hasFeature('custom-togglers')).to.be.true
  75. expect(this.Features.hasFeature('overleaf-integration')).to.be.true
  76. expect(this.Features.hasFeature('registration')).to.be.true
  77. })
  78. it('should return false', function () {
  79. expect(this.Features.hasFeature('affiliations')).to.be.false
  80. expect(this.Features.hasFeature('analytics')).to.be.false
  81. expect(this.Features.hasFeature('git-bridge')).to.be.false
  82. expect(this.Features.hasFeature('github-sync')).to.be.false
  83. expect(this.Features.hasFeature('homepage')).to.be.false
  84. expect(this.Features.hasFeature('link-url')).to.be.false
  85. expect(this.Features.hasFeature('oauth')).to.be.false
  86. expect(this.Features.hasFeature('references')).to.be.false
  87. expect(this.Features.hasFeature('saml')).to.be.false
  88. expect(this.Features.hasFeature('templates-server-pro')).to.be.false
  89. })
  90. describe('with APIs', function () {
  91. beforeEach(function () {
  92. this.settings.apis = {
  93. linkedUrlProxy: {
  94. url: 'https://www.overleaf.com',
  95. },
  96. references: {
  97. url: 'https://www.overleaf.com',
  98. },
  99. v1: {
  100. url: 'https://www.overleaf.com',
  101. },
  102. }
  103. })
  104. it('should return true', function () {
  105. expect(this.Features.hasFeature('affiliations')).to.be.true
  106. expect(this.Features.hasFeature('analytics')).to.be.true
  107. expect(this.Features.hasFeature('custom-togglers')).to.be.true
  108. expect(this.Features.hasFeature('overleaf-integration')).to.be.true
  109. expect(this.Features.hasFeature('references')).to.be.true
  110. expect(this.Features.hasFeature('registration')).to.be.true
  111. })
  112. it('should return false', function () {
  113. expect(this.Features.hasFeature('link-url')).to.be.false
  114. expect(this.Features.hasFeature('git-bridge')).to.be.false
  115. expect(this.Features.hasFeature('github-sync')).to.be.false
  116. expect(this.Features.hasFeature('homepage')).to.be.false
  117. expect(this.Features.hasFeature('oauth')).to.be.false
  118. expect(this.Features.hasFeature('saml')).to.be.false
  119. expect(this.Features.hasFeature('templates-server-pro')).to.be.false
  120. })
  121. describe('with all other settings flags', function () {
  122. beforeEach(function () {
  123. this.settings.enableHomepage = true
  124. this.settings.enableGitBridge = true
  125. this.settings.enableGithubSync = true
  126. this.settings.enableSaml = true
  127. this.settings.oauth = true
  128. this.settings.enabledLinkedFileTypes = ['url', 'project_file']
  129. })
  130. it('should return true or return value', function () {
  131. expect(this.Features.hasFeature('link-url')).to.be.true
  132. expect(this.Features.hasFeature('affiliations')).to.be.true
  133. expect(this.Features.hasFeature('analytics')).to.be.true
  134. expect(this.Features.hasFeature('custom-togglers')).to.be.true
  135. expect(this.Features.hasFeature('github-sync')).to.be.true
  136. expect(this.Features.hasFeature('git-bridge')).to.be.true
  137. expect(this.Features.hasFeature('homepage')).to.be.true
  138. expect(this.Features.hasFeature('link-url')).to.be.true
  139. expect(this.Features.hasFeature('oauth')).to.be.true
  140. expect(this.Features.hasFeature('overleaf-integration')).to.be
  141. .true
  142. expect(this.Features.hasFeature('references')).to.be.true
  143. expect(this.Features.hasFeature('registration')).to.be.true
  144. expect(this.Features.hasFeature('saml')).to.be.true
  145. })
  146. it('should return false', function () {
  147. expect(this.Features.hasFeature('templates-server-pro')).to.be
  148. .false
  149. })
  150. })
  151. })
  152. })
  153. })
  154. })
  155. })