Features.test.mjs 6.2 KB

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