FeaturesTests.js 7.0 KB

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