Skip to main content
Glama
server-config.test.ts11.2 kB
/** * Server Configuration Unit Tests */ import { getServerConfig, ServerConfig, CONFIGURATION_MODES } from '../../src/config/server-config.js'; // Mock environment variables const originalEnv = process.env; describe('Server Configuration', () => { beforeEach(() => { // Reset environment variables process.env = { ...originalEnv }; }); afterAll(() => { // Restore original environment process.env = originalEnv; }); describe('getServerConfig', () => { it('should return default configuration when no environment variables are set', () => { delete process.env.MCP_MODE; delete process.env.ELEMENTOR_MINIMAL_MODE; delete process.env.ELEMENTOR_MCP_MODE; delete process.env.ELEMENTOR_ENABLE_ALL; const config = getServerConfig(); expect(config.mode).toBe('standard'); expect(config.basicWordPressOperations).toBe(true); expect(config.basicElementorOperations).toBe(true); }); it('should use MCP_MODE environment variable', () => { process.env.MCP_MODE = 'full'; const config = getServerConfig(); expect(config.mode).toBe('full'); expect(config.basicWordPressOperations).toBe(true); expect(config.basicElementorOperations).toBe(true); expect(config.sectionContainerCreation).toBe(true); expect(config.widgetAddition).toBe(true); expect(config.elementManagement).toBe(true); expect(config.pageStructure).toBe(true); expect(config.performanceOptimization).toBe(true); expect(config.advancedElementOperations).toBe(true); expect(config.templateManagement).toBe(true); expect(config.globalSettings).toBe(true); }); it('should use ELEMENTOR_MINIMAL_MODE environment variable', () => { process.env.ELEMENTOR_MINIMAL_MODE = 'true'; const config = getServerConfig(); expect(config.mode).toBe('essential'); expect(config.basicWordPressOperations).toBe(true); expect(config.basicElementorOperations).toBe(true); expect(config.sectionContainerCreation).toBe(false); }); it('should use ELEMENTOR_MCP_MODE environment variable', () => { process.env.ELEMENTOR_MCP_MODE = 'advanced'; const config = getServerConfig(); expect(config.mode).toBe('advanced'); expect(config.basicWordPressOperations).toBe(true); expect(config.basicElementorOperations).toBe(true); expect(config.sectionContainerCreation).toBe(true); expect(config.widgetAddition).toBe(true); expect(config.elementManagement).toBe(true); expect(config.pageStructure).toBe(true); expect(config.performanceOptimization).toBe(true); expect(config.advancedElementOperations).toBe(true); expect(config.templateManagement).toBe(false); }); it('should use ELEMENTOR_ENABLE_ALL environment variable', () => { process.env.ELEMENTOR_ENABLE_ALL = 'true'; const config = getServerConfig(); expect(config.mode).toBe('full'); expect(config.templateManagement).toBe(true); expect(config.globalSettings).toBe(true); }); it('should override individual features with environment variables', () => { process.env.MCP_MODE = 'standard'; process.env.ELEMENTOR_SECTION_CONTAINER_CREATION = 'false'; process.env.ELEMENTOR_WIDGET_ADDITION = 'true'; const config = getServerConfig(); expect(config.mode).toBe('standard'); expect(config.sectionContainerCreation).toBe(false); expect(config.widgetAddition).toBe(true); }); }); describe('ServerConfig methods', () => { let config: ServerConfig; beforeEach(() => { config = getServerConfig(); }); describe('getEnabledFeatures', () => { it('should return list of enabled features', () => { process.env.MCP_MODE = 'full'; const fullConfig = getServerConfig(); const enabledFeatures = fullConfig.getEnabledFeatures(); expect(enabledFeatures).toContain('basicWordPressOperations'); expect(enabledFeatures).toContain('basicElementorOperations'); expect(enabledFeatures).toContain('sectionContainerCreation'); expect(enabledFeatures).toContain('widgetAddition'); expect(enabledFeatures).toContain('elementManagement'); expect(enabledFeatures).toContain('pageStructure'); expect(enabledFeatures).toContain('performanceOptimization'); expect(enabledFeatures).toContain('advancedElementOperations'); expect(enabledFeatures).toContain('templateManagement'); expect(enabledFeatures).toContain('globalSettings'); }); it('should return minimal features for essential mode', () => { process.env.MCP_MODE = 'essential'; const essentialConfig = getServerConfig(); const enabledFeatures = essentialConfig.getEnabledFeatures(); expect(enabledFeatures).toContain('basicWordPressOperations'); expect(enabledFeatures).toContain('basicElementorOperations'); expect(enabledFeatures).not.toContain('sectionContainerCreation'); expect(enabledFeatures).not.toContain('templateManagement'); }); }); describe('getDisabledFeatures', () => { it('should return list of disabled features', () => { process.env.MCP_MODE = 'essential'; const essentialConfig = getServerConfig(); const disabledFeatures = essentialConfig.getDisabledFeatures(); expect(disabledFeatures).toContain('sectionContainerCreation'); expect(disabledFeatures).toContain('widgetAddition'); expect(disabledFeatures).toContain('templateManagement'); expect(disabledFeatures).toContain('globalSettings'); }); }); describe('getTotalEnabledFeatures', () => { it('should return correct count of enabled features', () => { process.env.MCP_MODE = 'standard'; const standardConfig = getServerConfig(); expect(standardConfig.getTotalEnabledFeatures()).toBe(6); }); it('should return correct count for full mode', () => { process.env.MCP_MODE = 'full'; const fullConfig = getServerConfig(); expect(fullConfig.getTotalEnabledFeatures()).toBe(10); }); }); describe('toJSON', () => { it('should serialize configuration to JSON', () => { const json = config.toJSON(); expect(json).toHaveProperty('mode'); expect(json).toHaveProperty('basicWordPressOperations'); expect(json).toHaveProperty('basicElementorOperations'); expect(json).toHaveProperty('sectionContainerCreation'); expect(json).toHaveProperty('widgetAddition'); expect(json).toHaveProperty('elementManagement'); expect(json).toHaveProperty('pageStructure'); expect(json).toHaveProperty('performanceOptimization'); expect(json).toHaveProperty('advancedElementOperations'); expect(json).toHaveProperty('templateManagement'); expect(json).toHaveProperty('globalSettings'); }); }); }); describe('CONFIGURATION_MODES', () => { it('should have correct mode definitions', () => { expect(CONFIGURATION_MODES).toHaveProperty('essential'); expect(CONFIGURATION_MODES).toHaveProperty('standard'); expect(CONFIGURATION_MODES).toHaveProperty('advanced'); expect(CONFIGURATION_MODES).toHaveProperty('full'); }); it('should have correct feature sets for each mode', () => { const essential = CONFIGURATION_MODES.essential; const standard = CONFIGURATION_MODES.standard; const advanced = CONFIGURATION_MODES.advanced; const full = CONFIGURATION_MODES.full; // Essential mode should have minimal features expect(essential.basicWordPressOperations).toBe(true); expect(essential.basicElementorOperations).toBe(true); expect(essential.sectionContainerCreation).toBe(false); expect(essential.templateManagement).toBe(false); // Standard mode should have basic page building features expect(standard.basicWordPressOperations).toBe(true); expect(standard.basicElementorOperations).toBe(true); expect(standard.sectionContainerCreation).toBe(true); expect(standard.widgetAddition).toBe(true); expect(standard.templateManagement).toBe(false); // Advanced mode should have performance and advanced features expect(advanced.basicWordPressOperations).toBe(true); expect(advanced.basicElementorOperations).toBe(true); expect(advanced.sectionContainerCreation).toBe(true); expect(advanced.performanceOptimization).toBe(true); expect(advanced.advancedElementOperations).toBe(true); expect(advanced.templateManagement).toBe(false); // Full mode should have all features expect(full.basicWordPressOperations).toBe(true); expect(full.basicElementorOperations).toBe(true); expect(full.sectionContainerCreation).toBe(true); expect(full.widgetAddition).toBe(true); expect(full.elementManagement).toBe(true); expect(full.pageStructure).toBe(true); expect(full.performanceOptimization).toBe(true); expect(full.advancedElementOperations).toBe(true); expect(full.templateManagement).toBe(true); expect(full.globalSettings).toBe(true); }); }); describe('feature validation', () => { it('should validate that essential mode has required features', () => { process.env.MCP_MODE = 'essential'; const config = getServerConfig(); expect(config.basicWordPressOperations).toBe(true); expect(config.basicElementorOperations).toBe(true); }); it('should validate that standard mode includes essential features', () => { process.env.MCP_MODE = 'standard'; const config = getServerConfig(); expect(config.basicWordPressOperations).toBe(true); expect(config.basicElementorOperations).toBe(true); expect(config.sectionContainerCreation).toBe(true); expect(config.widgetAddition).toBe(true); }); it('should validate that advanced mode includes standard features', () => { process.env.MCP_MODE = 'advanced'; const config = getServerConfig(); expect(config.basicWordPressOperations).toBe(true); expect(config.basicElementorOperations).toBe(true); expect(config.sectionContainerCreation).toBe(true); expect(config.widgetAddition).toBe(true); expect(config.performanceOptimization).toBe(true); expect(config.advancedElementOperations).toBe(true); }); it('should validate that full mode has all features', () => { process.env.MCP_MODE = 'full'; const config = getServerConfig(); const allFeatures = [ 'basicWordPressOperations', 'basicElementorOperations', 'sectionContainerCreation', 'widgetAddition', 'elementManagement', 'pageStructure', 'performanceOptimization', 'advancedElementOperations', 'templateManagement', 'globalSettings' ]; allFeatures.forEach(feature => { expect(config[feature as keyof ServerConfig]).toBe(true); }); }); }); });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mbrown1837/Ultimate-Elementor-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server