"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const globals_1 = require("@jest/globals");
const environment_generator_1 = require("./environment-generator");
(0, globals_1.describe)('EnvironmentGenerator', () => {
    const generator = new environment_generator_1.EnvironmentGenerator();
    const mockWorkflow = {
        workflow: {
            id: 'test-workflow',
            name: 'Test Workflow',
        },
        stack: {
            'web-app': {
                type: 'frontend',
                technology: 'react',
            },
            'api': {
                type: 'backend',
                technology: 'typescript/express',
            },
            'database': {
                type: 'database',
                technology: 'postgresql',
            },
        },
        environment: {
            development: {
                'web-app': {
                    VITE_API_URL: 'http://localhost:3000',
                },
                'api': {
                    JWT_SECRET: 'dev-secret-key',
                    DATABASE_URL: 'postgresql://localhost:5432/myapp_dev',
                    NODE_ENV: 'development',
                },
                'database': {
                    POSTGRES_DB: 'myapp_dev',
                    POSTGRES_USER: 'dev',
                    POSTGRES_PASSWORD: 'dev',
                },
            },
            production: {
                'web-app': {
                    VITE_API_URL: '{{ secrets.API_URL_PROD }}',
                },
                'api': {
                    JWT_SECRET: '{{ secrets.JWT_SECRET_PROD }}',
                    DATABASE_URL: '{{ secrets.DATABASE_URL_PROD }}',
                    NODE_ENV: 'production',
                },
            },
        },
        deployment: {
            'api': {
                environment_variables: ['JWT_SECRET', 'DATABASE_URL', 'NODE_ENV'],
            },
        },
    };
    const mockContext = {
        workflow: mockWorkflow,
        executionPlan: {},
        outputDirectory: '/test/output',
    };
    (0, globals_1.it)('should have correct metadata', () => {
        (0, globals_1.expect)(generator.id).toBe('environment-config');
        (0, globals_1.expect)(generator.name).toBe('Environment Configuration Generator');
        (0, globals_1.expect)(generator.description).toBe('Generates environment configuration files (.env)');
    });
    (0, globals_1.it)('should generate .env.example for all components', () => {
        const result = generator.generate(mockContext);
        const exampleFiles = result.files.filter(f => f.path.includes('.env.example'));
        (0, globals_1.expect)(exampleFiles.length).toBe(3); // web-app, api, database
        // Check API example file
        const apiExample = exampleFiles.find(f => f.path.includes('api/.env.example'));
        (0, globals_1.expect)(apiExample).toBeDefined();
        (0, globals_1.expect)(apiExample?.content).toContain('JWT_SECRET');
        (0, globals_1.expect)(apiExample?.content).toContain('DATABASE_URL');
        (0, globals_1.expect)(apiExample?.content).toContain('NODE_ENV');
    });
    (0, globals_1.it)('should generate .env.development files', () => {
        const result = generator.generate(mockContext);
        const devFiles = result.files.filter(f => f.path.includes('.env.development'));
        (0, globals_1.expect)(devFiles.length).toBe(3);
        // Check API dev file
        const apiDev = devFiles.find(f => f.path.includes('api/.env.development'));
        (0, globals_1.expect)(apiDev).toBeDefined();
        (0, globals_1.expect)(apiDev?.content).toContain('JWT_SECRET=dev-secret-key');
        (0, globals_1.expect)(apiDev?.content).toContain('DATABASE_URL=postgresql://localhost:5432/myapp_dev');
    });
    (0, globals_1.it)('should generate .env.test files', () => {
        const result = generator.generate(mockContext);
        const testFiles = result.files.filter(f => f.path.includes('.env.test'));
        (0, globals_1.expect)(testFiles.length).toBe(3);
        // Check API test file
        const apiTest = testFiles.find(f => f.path.includes('api/.env.test'));
        (0, globals_1.expect)(apiTest).toBeDefined();
        (0, globals_1.expect)(apiTest?.content).toContain('NODE_ENV=test');
        (0, globals_1.expect)(apiTest?.content).toContain('test_db'); // Database URL should be modified for test
    });
    (0, globals_1.it)('should process secret templates correctly', () => {
        const result = generator.generate(mockContext);
        const webAppExample = result.files.find(f => f.path.includes('web-app/.env.example'));
        (0, globals_1.expect)(webAppExample).toBeDefined();
        (0, globals_1.expect)(webAppExample?.content).toContain('VITE_API_URL=');
    });
    (0, globals_1.it)('should group variables by category', () => {
        const result = generator.generate(mockContext);
        const apiExample = result.files.find(f => f.path.includes('api/.env.example'));
        (0, globals_1.expect)(apiExample?.content).toContain('# Database');
        (0, globals_1.expect)(apiExample?.content).toContain('# Authentication');
        (0, globals_1.expect)(apiExample?.content).toContain('# Server');
    });
    (0, globals_1.it)('should not overwrite existing env files', () => {
        const result = generator.generate(mockContext);
        const devFiles = result.files.filter(f => f.path.includes('.env.development'));
        for (const file of devFiles) {
            (0, globals_1.expect)(file.overwrite).toBe(false);
        }
    });
    (0, globals_1.it)('should return empty result when no environment config', () => {
        const contextWithoutEnv = {
            ...mockContext,
            workflow: {
                ...mockWorkflow,
                environment: undefined,
            },
        };
        const result = generator.generate(contextWithoutEnv);
        (0, globals_1.expect)(result.files.length).toBe(0);
    });
});
//# sourceMappingURL=environment-generator.test.js.map