FeaturesTests.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. })
  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('git-bridge')).to.be.false
  56. expect(this.Features.hasFeature('github-sync')).to.be.false
  57. expect(this.Features.hasFeature('homepage')).to.be.false
  58. expect(this.Features.hasFeature('link-url')).to.be.false
  59. expect(this.Features.hasFeature('oauth')).to.be.false
  60. expect(this.Features.hasFeature('saas')).to.be.false
  61. expect(this.Features.hasFeature('references')).to.be.false
  62. expect(this.Features.hasFeature('saml')).to.be.false
  63. expect(this.Features.hasFeature('templates-server-pro')).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('saas')).to.be.true
  74. expect(this.Features.hasFeature('registration')).to.be.true
  75. })
  76. it('should return false', function () {
  77. expect(this.Features.hasFeature('affiliations')).to.be.false
  78. expect(this.Features.hasFeature('analytics')).to.be.false
  79. expect(this.Features.hasFeature('git-bridge')).to.be.false
  80. expect(this.Features.hasFeature('github-sync')).to.be.false
  81. expect(this.Features.hasFeature('homepage')).to.be.false
  82. expect(this.Features.hasFeature('link-url')).to.be.false
  83. expect(this.Features.hasFeature('oauth')).to.be.false
  84. expect(this.Features.hasFeature('references')).to.be.false
  85. expect(this.Features.hasFeature('saml')).to.be.false
  86. expect(this.Features.hasFeature('templates-server-pro')).to.be.false
  87. })
  88. describe('with APIs', function () {
  89. beforeEach(function () {
  90. this.settings.apis = {
  91. linkedUrlProxy: {
  92. url: 'https://www.overleaf.com',
  93. },
  94. references: {
  95. url: 'https://www.overleaf.com',
  96. },
  97. v1: {
  98. url: 'https://www.overleaf.com',
  99. },
  100. }
  101. })
  102. it('should return true', function () {
  103. expect(this.Features.hasFeature('affiliations')).to.be.true
  104. expect(this.Features.hasFeature('analytics')).to.be.true
  105. expect(this.Features.hasFeature('saas')).to.be.true
  106. expect(this.Features.hasFeature('references')).to.be.true
  107. expect(this.Features.hasFeature('registration')).to.be.true
  108. })
  109. it('should return false', function () {
  110. expect(this.Features.hasFeature('link-url')).to.be.false
  111. expect(this.Features.hasFeature('git-bridge')).to.be.false
  112. expect(this.Features.hasFeature('github-sync')).to.be.false
  113. expect(this.Features.hasFeature('homepage')).to.be.false
  114. expect(this.Features.hasFeature('oauth')).to.be.false
  115. expect(this.Features.hasFeature('saml')).to.be.false
  116. expect(this.Features.hasFeature('templates-server-pro')).to.be.false
  117. })
  118. describe('with all other settings flags', function () {
  119. beforeEach(function () {
  120. this.settings.enableHomepage = true
  121. this.settings.enableGitBridge = true
  122. this.settings.enableGithubSync = true
  123. this.settings.enableSaml = true
  124. this.settings.oauth = true
  125. this.settings.enabledLinkedFileTypes = ['url', 'project_file']
  126. })
  127. it('should return true or return value', function () {
  128. expect(this.Features.hasFeature('link-url')).to.be.true
  129. expect(this.Features.hasFeature('affiliations')).to.be.true
  130. expect(this.Features.hasFeature('analytics')).to.be.true
  131. expect(this.Features.hasFeature('github-sync')).to.be.true
  132. expect(this.Features.hasFeature('git-bridge')).to.be.true
  133. expect(this.Features.hasFeature('homepage')).to.be.true
  134. expect(this.Features.hasFeature('link-url')).to.be.true
  135. expect(this.Features.hasFeature('oauth')).to.be.true
  136. expect(this.Features.hasFeature('saas')).to.be.true
  137. expect(this.Features.hasFeature('references')).to.be.true
  138. expect(this.Features.hasFeature('registration')).to.be.true
  139. expect(this.Features.hasFeature('saml')).to.be.true
  140. })
  141. it('should return false', function () {
  142. expect(this.Features.hasFeature('templates-server-pro')).to.be
  143. .false
  144. })
  145. })
  146. })
  147. })
  148. })
  149. })
  150. })