refactor(core): Add central license mock for integration tests (no-changelog) (#7871)

Github issue / Community forum post (link here to close automatically):
This commit is contained in:
Val
2023-11-30 08:23:09 +00:00
committed by GitHub
parent b16dd21909
commit 5f4a9524ec
12 changed files with 124 additions and 94 deletions

View File

@@ -20,6 +20,7 @@ import * as testDb from '../../shared/testDb';
import { AUTHLESS_ENDPOINTS, PUBLIC_API_REST_PATH_SEGMENT, REST_PATH_SEGMENT } from '../constants';
import type { SetupProps, TestServer } from '../types';
import { InternalHooks } from '@/InternalHooks';
import { LicenseMocker } from '../license';
/**
* Plugin to prefix a path segment into a request URL pathname.
@@ -83,6 +84,7 @@ export const setupTestServer = ({
authAgentFor: (user: User) => createAgent(app, { auth: true, user }),
authlessAgent: createAgent(app),
publicApiAgentFor: (user) => publicApiAgent(app, { user }),
license: new LicenseMocker(),
};
beforeAll(async () => {
@@ -91,8 +93,11 @@ export const setupTestServer = ({
config.set('userManagement.jwtSecret', 'My JWT secret');
config.set('userManagement.isInstanceOwnerSetUp', true);
testServer.license.mock(Container.get(License));
if (enabledFeatures) {
Container.get(License).isFeatureEnabled = (feature) => enabledFeatures.includes(feature);
testServer.license.setDefaults({
features: enabledFeatures,
});
}
const enablePublicAPI = endpointGroups?.includes('publicApi');
@@ -166,7 +171,7 @@ export const setupTestServer = ({
const { LdapManager } = await import('@/Ldap/LdapManager.ee');
const { handleLdapInit } = await import('@/Ldap/helpers');
const { LdapController } = await import('@/controllers/ldap.controller');
Container.get(License).isLdapEnabled = () => true;
testServer.license.enable('feat:ldap');
await handleLdapInit();
const { service, sync } = LdapManager.getInstance();
registerController(
@@ -312,5 +317,9 @@ export const setupTestServer = ({
testServer.httpServer.close();
});
beforeEach(() => {
testServer.license.reset();
});
return testServer;
};