mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2026-09-24 19:10:53 +02:00
feat(core): Setup backend modules (no-changelog) (#14084)
Co-authored-by: Guillaume Jacquart <jacquart.guillaume@gmail.com> Co-authored-by: Danny Martini <danny@n8n.io>
This commit is contained in:
co-authored by
Guillaume Jacquart
Danny Martini
parent
c34ffd0e7c
commit
d80b49d6e5
@@ -0,0 +1,33 @@
|
||||
import { Container } from '@n8n/di';
|
||||
import { UnexpectedError } from 'n8n-workflow';
|
||||
|
||||
import { ModulesConfig } from '../modules.config';
|
||||
|
||||
describe('ModulesConfig', () => {
|
||||
beforeEach(() => {
|
||||
jest.resetAllMocks();
|
||||
process.env = {};
|
||||
Container.reset();
|
||||
});
|
||||
|
||||
it('should initialize with empty modules if no environment variable is set', () => {
|
||||
const config = Container.get(ModulesConfig);
|
||||
expect(config.modules).toEqual([]);
|
||||
});
|
||||
|
||||
it('should parse valid module names from environment variable', () => {
|
||||
process.env.N8N_ENABLED_MODULES = 'insights';
|
||||
const config = Container.get(ModulesConfig);
|
||||
expect(config.modules).toEqual(['insights']);
|
||||
});
|
||||
|
||||
it('should throw UnexpectedError for invalid module names', () => {
|
||||
process.env.N8N_ENABLED_MODULES = 'invalidModule';
|
||||
expect(() => Container.get(ModulesConfig)).toThrow(UnexpectedError);
|
||||
});
|
||||
|
||||
it('should throw UnexpectedError if any module name is invalid', () => {
|
||||
process.env.N8N_ENABLED_MODULES = 'insights,invalidModule';
|
||||
expect(() => Container.get(ModulesConfig)).toThrow(UnexpectedError);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,24 @@
|
||||
import { CommaSeperatedStringArray, Config, Env } from '@n8n/config';
|
||||
import { UnexpectedError } from 'n8n-workflow';
|
||||
|
||||
const moduleNames = ['insights'] as const;
|
||||
type ModuleName = (typeof moduleNames)[number];
|
||||
|
||||
class Modules extends CommaSeperatedStringArray<ModuleName> {
|
||||
constructor(str: string) {
|
||||
super(str);
|
||||
|
||||
for (const moduleName of this) {
|
||||
if (!moduleNames.includes(moduleName)) {
|
||||
throw new UnexpectedError(`Unknown module name ${moduleName}`, { level: 'fatal' });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Config
|
||||
export class ModulesConfig {
|
||||
/** Comma-separated list of all enabled modules */
|
||||
@Env('N8N_ENABLED_MODULES')
|
||||
modules: Modules = [];
|
||||
}
|
||||
Reference in New Issue
Block a user