"use strict";
/**
 * Tests for EnhancedTestingGenerator
 */
Object.defineProperty(exports, "__esModule", { value: true });
const enhanced_testing_generator_1 = require("./enhanced-testing-generator");
const workflow_engine_1 = require("../../engine/workflow-engine");
describe('EnhancedTestingGenerator', () => {
    let generator;
    beforeEach(() => {
        generator = new enhanced_testing_generator_1.EnhancedTestingGenerator();
    });
    it('should have correct metadata', () => {
        expect(generator.id).toBe('enhanced-testing');
        expect(generator.name).toBe('Enhanced Testing Generator');
        expect(generator.description).toBe('Generates comprehensive test configurations from enhanced testing schema');
    });
    it('should return empty result when no testing config', () => {
        const workflow = {
            workflow: {
                id: 'test',
                name: 'Test',
                version: '1.0.0',
            },
            stack: {
                api: {
                    type: 'backend',
                    technology: 'typescript/express',
                },
            },
        };
        const engine = new workflow_engine_1.WorkflowEngine();
        const executionPlan = engine.analyze(workflow);
        const result = generator.generate({
            workflow,
            executionPlan,
            outputDirectory: '/test',
        });
        expect(result.files).toHaveLength(0);
    });
    it('should skip legacy testing format', () => {
        const workflow = {
            workflow: {
                id: 'test',
                name: 'Test',
                version: '1.0.0',
            },
            stack: {
                api: {
                    type: 'backend',
                    technology: 'typescript/express',
                },
            },
            testing: {
                unit_tests: [{ component: 'api', scenarios: ['test'] }],
            },
        };
        const engine = new workflow_engine_1.WorkflowEngine();
        const executionPlan = engine.analyze(workflow);
        const result = generator.generate({
            workflow,
            executionPlan,
            outputDirectory: '/test',
        });
        expect(result.files).toHaveLength(0);
    });
    describe('Backend Testing (Vitest)', () => {
        it('should generate Vitest config with coverage thresholds', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    name: 'Test',
                    version: '1.0.0',
                },
                stack: {
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                    },
                },
                testing: {
                    frameworks: {
                        unit: {
                            framework: 'vitest',
                            config: { coverage: true },
                        },
                    },
                    coverage: {
                        threshold: {
                            global: {
                                statements: 80,
                                branches: 75,
                                functions: 80,
                                lines: 80,
                            },
                        },
                    },
                },
            };
            const engine = new workflow_engine_1.WorkflowEngine();
            const executionPlan = engine.analyze(workflow);
            const result = generator.generate({
                workflow,
                executionPlan,
                outputDirectory: '/test',
            });
            const vitestConfig = result.files.find(f => f.path.includes('vitest.config.ts'));
            expect(vitestConfig).toBeDefined();
            expect(vitestConfig?.content).toContain('defineConfig');
            expect(vitestConfig?.content).toContain('statements: 80');
            expect(vitestConfig?.content).toContain('branches: 75');
            expect(vitestConfig?.content).toContain('functions: 80');
            expect(vitestConfig?.content).toContain('lines: 80');
        });
        it('should generate Jest config when framework is jest', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    name: 'Test',
                    version: '1.0.0',
                },
                stack: {
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                    },
                },
                testing: {
                    frameworks: {
                        unit: {
                            framework: 'jest',
                        },
                    },
                    coverage: {
                        threshold: {
                            global: {
                                statements: 90,
                                branches: 85,
                                functions: 90,
                                lines: 90,
                            },
                        },
                    },
                },
            };
            const engine = new workflow_engine_1.WorkflowEngine();
            const executionPlan = engine.analyze(workflow);
            const result = generator.generate({
                workflow,
                executionPlan,
                outputDirectory: '/test',
            });
            const jestConfig = result.files.find(f => f.path.includes('jest.config.js'));
            expect(jestConfig).toBeDefined();
            expect(jestConfig?.content).toContain('ts-jest');
            expect(jestConfig?.content).toContain('statements: 90');
            expect(jestConfig?.content).toContain('branches: 85');
        });
    });
    describe('Database Testing', () => {
        it('should generate testcontainers helpers', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    name: 'Test',
                    version: '1.0.0',
                },
                stack: {
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                    },
                },
                testing: {
                    frameworks: {
                        unit: { framework: 'vitest' },
                    },
                    database: {
                        strategy: 'testcontainers',
                        reset_strategy: 'truncate',
                    },
                },
            };
            const engine = new workflow_engine_1.WorkflowEngine();
            const executionPlan = engine.analyze(workflow);
            const result = generator.generate({
                workflow,
                executionPlan,
                outputDirectory: '/test',
            });
            const dbHelper = result.files.find(f => f.path.includes('test/helpers/database.ts'));
            expect(dbHelper).toBeDefined();
            expect(dbHelper?.content).toContain('testcontainers');
            expect(dbHelper?.content).toContain('PostgreSqlContainer');
            expect(dbHelper?.content).toContain('setupTestDatabase');
            expect(dbHelper?.content).toContain('teardownTestDatabase');
            expect(dbHelper?.content).toContain('truncateAllTables');
        });
        it('should generate SQLite in-memory helpers', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    name: 'Test',
                    version: '1.0.0',
                },
                stack: {
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                    },
                },
                testing: {
                    frameworks: {
                        unit: { framework: 'vitest' },
                    },
                    database: {
                        strategy: 'sqlite_memory',
                        reset_strategy: 'recreate',
                    },
                },
            };
            const engine = new workflow_engine_1.WorkflowEngine();
            const executionPlan = engine.analyze(workflow);
            const result = generator.generate({
                workflow,
                executionPlan,
                outputDirectory: '/test',
            });
            const dbHelper = result.files.find(f => f.path.includes('test/helpers/database.ts'));
            expect(dbHelper).toBeDefined();
            expect(dbHelper?.content).toContain('Strategy: sqlite_memory');
            expect(dbHelper?.content).toContain('Mock database');
        });
    });
    describe('Frontend Testing (Playwright)', () => {
        it('should generate Playwright config with specified browsers', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    name: 'Test',
                    version: '1.0.0',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                testing: {
                    frameworks: {
                        e2e: {
                            framework: 'playwright',
                            browsers: ['chromium', 'firefox'],
                        },
                    },
                },
            };
            const engine = new workflow_engine_1.WorkflowEngine();
            const executionPlan = engine.analyze(workflow);
            const result = generator.generate({
                workflow,
                executionPlan,
                outputDirectory: '/test',
            });
            const playwrightConfig = result.files.find(f => f.path.includes('playwright.config.ts'));
            expect(playwrightConfig).toBeDefined();
            expect(playwrightConfig?.content).toContain('chromium');
            expect(playwrightConfig?.content).toContain('firefox');
            expect(playwrightConfig?.content).toContain('@playwright/test');
        });
        it('should generate Cypress config when framework is cypress', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    name: 'Test',
                    version: '1.0.0',
                },
                stack: {
                    web: {
                        type: 'frontend',
                        technology: 'react',
                    },
                },
                testing: {
                    frameworks: {
                        e2e: {
                            framework: 'cypress',
                        },
                    },
                },
            };
            const engine = new workflow_engine_1.WorkflowEngine();
            const executionPlan = engine.analyze(workflow);
            const result = generator.generate({
                workflow,
                executionPlan,
                outputDirectory: '/test',
            });
            const cypressConfig = result.files.find(f => f.path.includes('cypress.config.ts'));
            expect(cypressConfig).toBeDefined();
            expect(cypressConfig?.content).toContain('cypress');
            expect(cypressConfig?.content).toContain('defineConfig');
        });
    });
    describe('CI/CD Integration', () => {
        it('should generate GitHub Actions workflow with coverage checks', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    name: 'Test',
                    version: '1.0.0',
                },
                stack: {
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                    },
                },
                testing: {
                    frameworks: {
                        unit: { framework: 'vitest' },
                    },
                    ci_cd: {
                        provider: 'github_actions',
                        test_on_pr: true,
                        test_requirements: {
                            require_passing: true,
                            minimum_coverage: 80,
                        },
                    },
                },
            };
            const engine = new workflow_engine_1.WorkflowEngine();
            const executionPlan = engine.analyze(workflow);
            const result = generator.generate({
                workflow,
                executionPlan,
                outputDirectory: '/test',
            });
            const ghActions = result.files.find(f => f.path.includes('.github/workflows/test.yml'));
            expect(ghActions).toBeDefined();
            expect(ghActions?.content).toContain('pull_request');
            expect(ghActions?.content).toContain('Test');
        });
        it('should generate GitLab CI config when provider is gitlab_ci', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    name: 'Test',
                    version: '1.0.0',
                },
                stack: {
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                    },
                },
                testing: {
                    frameworks: {
                        unit: { framework: 'vitest' },
                    },
                    ci_cd: {
                        provider: 'gitlab_ci',
                        test_on_pr: true,
                    },
                },
            };
            const engine = new workflow_engine_1.WorkflowEngine();
            const executionPlan = engine.analyze(workflow);
            const result = generator.generate({
                workflow,
                executionPlan,
                outputDirectory: '/test',
            });
            const gitlabCi = result.files.find(f => f.path.includes('.gitlab-ci.yml'));
            expect(gitlabCi).toBeDefined();
            expect(gitlabCi?.content).toContain('test:');
            expect(gitlabCi?.content).toContain('script:');
        });
    });
    describe('Complete Enhanced Schema', () => {
        it('should generate all files for complete enhanced testing config', () => {
            const workflow = {
                workflow: {
                    id: 'test',
                    name: 'Test Enhanced',
                    version: '1.0.0',
                },
                stack: {
                    api: {
                        type: 'backend',
                        technology: 'typescript/express',
                        config: { port: 3000 },
                    },
                    web: {
                        type: 'frontend',
                        technology: 'react',
                        config: { port: 5173 },
                    },
                },
                testing: {
                    frameworks: {
                        unit: {
                            framework: 'vitest',
                            config: { coverage: true },
                        },
                        e2e: {
                            framework: 'playwright',
                            browsers: ['chromium', 'firefox'],
                        },
                    },
                    coverage: {
                        threshold: {
                            global: {
                                statements: 80,
                                branches: 75,
                                functions: 80,
                                lines: 80,
                            },
                        },
                    },
                    database: {
                        strategy: 'testcontainers',
                        reset_strategy: 'truncate',
                    },
                    ci_cd: {
                        provider: 'github_actions',
                        test_on_pr: true,
                        test_requirements: {
                            require_passing: true,
                            minimum_coverage: 80,
                        },
                    },
                },
            };
            const engine = new workflow_engine_1.WorkflowEngine();
            const executionPlan = engine.analyze(workflow);
            const result = generator.generate({
                workflow,
                executionPlan,
                outputDirectory: '/test',
            });
            // Should generate multiple files (at least 5)
            expect(result.files.length).toBeGreaterThanOrEqual(5);
            // Backend test files
            expect(result.files.find(f => f.path.includes('api/vitest.config.ts'))).toBeDefined();
            expect(result.files.find(f => f.path.includes('api/src/test/setup.ts'))).toBeDefined();
            expect(result.files.find(f => f.path.includes('api/src/test/helpers/database.ts'))).toBeDefined();
            // Frontend test files
            expect(result.files.find(f => f.path.includes('web/playwright.config.ts'))).toBeDefined();
            // CI/CD
            expect(result.files.find(f => f.path.includes('.github/workflows/test.yml'))).toBeDefined();
            // All files should have absolute paths
            result.files.forEach(file => {
                expect(file.path.startsWith('/test/')).toBe(true);
            });
        });
    });
});
//# sourceMappingURL=enhanced-testing-generator.test.js.map