UNPKG

@simonecoelhosfo/optimizely-mcp-server

Version:

Optimizely MCP Server for AI assistants with integrated CLI tools

156 lines โ€ข 5.84 kB
import { TemplateValidator } from './TemplateValidator'; import * as fs from 'fs'; import * as path from 'path'; import { fileURLToPath } from 'url'; const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); console.log('๐Ÿงช Testing Comprehensive Template Validator\n'); const validator = new TemplateValidator(); // Test cases const testCases = [ { name: 'Metrics Scope - Invalid Campaign', file: '../poc/test-invalid-campaign.json', expectedErrors: ['CAMPAIGN_METRICS_SCOPE'] }, { name: 'Metrics Scope - Valid Campaign', file: '../poc/test-valid-campaign.json', expectedErrors: [] }, { name: 'Metrics Scope - Mixed Entities', file: '../poc/test-mixed-entities.json', expectedErrors: ['CAMPAIGN_METRICS_SCOPE', 'EXPERIMENT_METRICS_SCOPE'] }, { name: 'Audience Complexity', file: './test-templates/audience-complexity.json', expectedErrors: ['AUDIENCE_COMPLEXITY_ACK'] }, { name: 'Platform Mismatch', file: './test-templates/platform-mismatch.json', expectedErrors: ['PLATFORM_MISMATCH'] }, { name: 'Invalid References', file: './test-templates/invalid-references.json', expectedErrors: ['UNKNOWN_STEP_REFERENCE', 'INVALID_STEP_REFERENCE'] } ]; // Run tests async function runTests() { let passedTests = 0; let failedTests = 0; for (const testCase of testCases) { console.log(`\n๐Ÿ“„ Testing: ${testCase.name}`); console.log(` File: ${testCase.file}`); console.log(' ' + 'โ”€'.repeat(60)); try { const templatePath = path.join(__dirname, testCase.file); const template = JSON.parse(fs.readFileSync(templatePath, 'utf8')); const result = await validator.validate(template); // Check if expected errors match const actualErrorCodes = result.errors.map(e => e.code); const expectedErrorCodes = testCase.expectedErrors; const passed = expectedErrorCodes.length === actualErrorCodes.length && expectedErrorCodes.every(code => actualErrorCodes.includes(code)); if (passed) { console.log(` โœ… PASSED - Found expected errors: ${actualErrorCodes.join(', ') || 'None'}`); passedTests++; } else { console.log(` โŒ FAILED`); console.log(` Expected errors: ${expectedErrorCodes.join(', ') || 'None'}`); console.log(` Actual errors: ${actualErrorCodes.join(', ') || 'None'}`); failedTests++; } // Show detailed results if (result.errors.length > 0) { console.log('\n Error Details:'); for (const error of result.errors) { console.log(` - [${error.code}] ${error.message}`); if (error.fix) { console.log(` Fix: ${error.fix.description}`); } } } if (result.warnings.length > 0) { console.log('\n Warnings:'); for (const warning of result.warnings) { console.log(` - [${warning.code}] ${warning.message}`); } } } catch (error) { console.error(` โŒ Error: ${error.message}`); failedTests++; } } // Summary console.log('\n' + '='.repeat(70)); console.log('TEST SUMMARY'); console.log('='.repeat(70)); console.log(`Total tests: ${testCases.length}`); console.log(`Passed: ${passedTests} โœ…`); console.log(`Failed: ${failedTests} โŒ`); if (failedTests === 0) { console.log('\n๐ŸŽ‰ All tests passed! The comprehensive validator is working correctly.'); } else { console.log('\nโš ๏ธ Some tests failed. Please check the implementation.'); } } // Test a complete multi-rule template async function testCompleteTemplate() { console.log('\n\n๐Ÿ“‹ Testing Complete Template with Multiple Rules\n'); console.log('='.repeat(70)); const completeTemplate = { id: 'complete_test', name: 'Complete Test Template', version: '1.0.0', platform: 'web', steps: [ { id: 'create_audience', type: 'template', template: { system_template_id: 'optimizely_audience_complex', inputs: { name: 'VIP Users', conditions: { browser: 'chrome' }, // Missing _acknowledged_complexity } } }, { id: 'create_campaign', type: 'template', template: { system_template_id: 'optimizely_campaign_basic', inputs: { name: 'Test Campaign', metrics: [{ event_id: '123', scope: 'visitor' }] // Wrong scope } } }, { id: 'create_flag', // Wrong platform type: 'template', template: { system_template_id: 'optimizely_flag_simple', inputs: { name: 'Feature Flag', key: 'feature_flag' } } } ] }; const result = await validator.validate(completeTemplate); console.log(validator.formatResults(result)); } // Run all tests runTests().then(() => testCompleteTemplate()); //# sourceMappingURL=test-validator.js.map