FeaturesTests.js 6.7 KB

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