| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- import { vi, expect } from 'vitest'
- const modulePath = '../../../../app/src/infrastructure/Features.mjs'
- describe('Features', function () {
- beforeEach(async function (ctx) {
- vi.doMock('@overleaf/settings', () => ({
- default: (ctx.settings = {
- moduleImportSequence: [],
- enabledLinkedFileTypes: [],
- }),
- }))
- ctx.Features = (await import(modulePath)).default
- })
- describe('externalAuthenticationSystemUsed', function () {
- describe('without any settings', function () {
- it('should return false', function (ctx) {
- expect(ctx.Features.externalAuthenticationSystemUsed()).to.be.false
- })
- })
- describe('with ldap setting', function () {
- beforeEach(function (ctx) {
- ctx.settings.ldap = { enable: true }
- })
- it('should return true', function (ctx) {
- expect(ctx.Features.externalAuthenticationSystemUsed()).to.be.true
- })
- })
- describe('with saml setting', function () {
- beforeEach(function (ctx) {
- ctx.settings.saml = { enable: true }
- })
- it('should return true', function (ctx) {
- expect(ctx.Features.externalAuthenticationSystemUsed()).to.be.true
- })
- })
- describe('with oauth setting', function () {
- beforeEach(function (ctx) {
- ctx.settings.overleaf = { oauth: true }
- })
- it('should return true', function (ctx) {
- expect(ctx.Features.externalAuthenticationSystemUsed()).to.be.true
- })
- })
- })
- describe('hasFeature', function () {
- describe('without any settings', function () {
- it('should return true', function (ctx) {
- expect(ctx.Features.hasFeature('registration-page')).to.be.true
- })
- it('should return false', function (ctx) {
- expect(ctx.Features.hasFeature('registration')).to.be.false
- expect(ctx.Features.hasFeature('affiliations')).to.be.false
- expect(ctx.Features.hasFeature('analytics')).to.be.false
- expect(ctx.Features.hasFeature('git-bridge')).to.be.false
- expect(ctx.Features.hasFeature('github-sync')).to.be.false
- expect(ctx.Features.hasFeature('homepage')).to.be.false
- expect(ctx.Features.hasFeature('link-url')).to.be.false
- expect(ctx.Features.hasFeature('oauth')).to.be.false
- expect(ctx.Features.hasFeature('saas')).to.be.false
- expect(ctx.Features.hasFeature('saml')).to.be.false
- expect(ctx.Features.hasFeature('templates-server-pro')).to.be.false
- })
- })
- describe('with settings', function () {
- describe('empty overleaf object', function () {
- beforeEach(function (ctx) {
- ctx.settings.overleaf = {}
- ctx.settings.apis = {}
- })
- it('should return true', function (ctx) {
- expect(ctx.Features.hasFeature('saas')).to.be.true
- expect(ctx.Features.hasFeature('registration')).to.be.true
- })
- it('should return false', function (ctx) {
- expect(ctx.Features.hasFeature('affiliations')).to.be.false
- expect(ctx.Features.hasFeature('analytics')).to.be.false
- expect(ctx.Features.hasFeature('git-bridge')).to.be.false
- expect(ctx.Features.hasFeature('github-sync')).to.be.false
- expect(ctx.Features.hasFeature('homepage')).to.be.false
- expect(ctx.Features.hasFeature('link-url')).to.be.false
- expect(ctx.Features.hasFeature('oauth')).to.be.false
- expect(ctx.Features.hasFeature('saml')).to.be.false
- expect(ctx.Features.hasFeature('templates-server-pro')).to.be.false
- })
- describe('with APIs', function () {
- beforeEach(function (ctx) {
- ctx.settings.apis = {
- linkedUrlProxy: {
- url: 'https://www.overleaf.com',
- },
- references: {
- url: 'https://www.overleaf.com',
- },
- v1: {
- url: 'https://www.overleaf.com',
- },
- }
- })
- it('should return true', function (ctx) {
- expect(ctx.Features.hasFeature('affiliations')).to.be.true
- expect(ctx.Features.hasFeature('analytics')).to.be.true
- expect(ctx.Features.hasFeature('saas')).to.be.true
- expect(ctx.Features.hasFeature('registration')).to.be.true
- })
- it('should return false', function (ctx) {
- expect(ctx.Features.hasFeature('link-url')).to.be.false
- expect(ctx.Features.hasFeature('git-bridge')).to.be.false
- expect(ctx.Features.hasFeature('github-sync')).to.be.false
- expect(ctx.Features.hasFeature('homepage')).to.be.false
- expect(ctx.Features.hasFeature('oauth')).to.be.false
- expect(ctx.Features.hasFeature('saml')).to.be.false
- expect(ctx.Features.hasFeature('templates-server-pro')).to.be.false
- })
- describe('with all other settings flags', function () {
- beforeEach(function (ctx) {
- ctx.settings.enableHomepage = true
- ctx.settings.enableGitBridge = true
- ctx.settings.enableGithubSync = true
- ctx.settings.enableSaml = true
- ctx.settings.oauth = true
- ctx.settings.enabledLinkedFileTypes = ['url', 'project_file']
- })
- it('should return true or return value', function (ctx) {
- expect(ctx.Features.hasFeature('link-url')).to.be.true
- expect(ctx.Features.hasFeature('affiliations')).to.be.true
- expect(ctx.Features.hasFeature('analytics')).to.be.true
- expect(ctx.Features.hasFeature('github-sync')).to.be.true
- expect(ctx.Features.hasFeature('git-bridge')).to.be.true
- expect(ctx.Features.hasFeature('homepage')).to.be.true
- expect(ctx.Features.hasFeature('link-url')).to.be.true
- expect(ctx.Features.hasFeature('oauth')).to.be.true
- expect(ctx.Features.hasFeature('saas')).to.be.true
- expect(ctx.Features.hasFeature('registration')).to.be.true
- expect(ctx.Features.hasFeature('saml')).to.be.true
- })
- it('should return false', function (ctx) {
- expect(ctx.Features.hasFeature('templates-server-pro')).to.be
- .false
- })
- })
- })
- })
- })
- })
- })
|