"use strict";
/**
 * E2E Tests for Enhanced Error Handling Generator
 * Generated by Bangstack
 */
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
const fs = __importStar(require("fs"));
require("../generators/index");
const path = __importStar(require("path"));
const generation_orchestrator_1 = require("../generators/generation-orchestrator");
describe('Enhanced Error Handling E2E Tests', () => {
    const testOutputDir = path.join(__dirname, '../../.e2e-output/enhanced-error-handling');
    beforeAll(() => {
        if (fs.existsSync(testOutputDir)) {
            fs.rmSync(testOutputDir, { recursive: true, force: true });
        }
    });
    afterAll(() => {
        if (fs.existsSync(testOutputDir)) {
            fs.rmSync(testOutputDir, { recursive: true, force: true });
        }
    });
    it('should generate complete error handling infrastructure', async () => {
        const workflow = {
            workflow: {
                id: 'test-error-handling',
                version: '1.0.0',
                name: 'Test Error Handling',
                description: 'Testing error handling',
            },
            stack: {},
            error_handling: {
                middleware: true,
                logging: {
                    provider: 'winston',
                    level: 'error',
                },
                tracking: {
                    provider: 'sentry',
                    frontend: true,
                    backend: true,
                },
                error_boundaries: {
                    enabled: true,
                },
            },
        };
        const orchestrator = new generation_orchestrator_1.GenerationOrchestrator();
        const _result = await orchestrator.generate(workflow, { outputDirectory: testOutputDir, dryRun: false });
        // Verify config file
        const configPath = path.join(testOutputDir, 'api/src/config/error-handling.ts');
        expect(fs.existsSync(configPath)).toBe(true);
        const configContent = fs.readFileSync(configPath, 'utf-8');
        expect(configContent).toContain('winston');
        expect(configContent).toContain('sentry');
        // Verify custom errors
        const errorsPath = path.join(testOutputDir, 'api/src/errors/custom-errors.ts');
        expect(fs.existsSync(errorsPath)).toBe(true);
        const errorsContent = fs.readFileSync(errorsPath, 'utf-8');
        expect(errorsContent).toContain('ValidationError');
        expect(errorsContent).toContain('AuthenticationError');
        // Verify middleware
        const middlewarePath = path.join(testOutputDir, 'api/src/middleware/error-handler.ts');
        expect(fs.existsSync(middlewarePath)).toBe(true);
        const middlewareContent = fs.readFileSync(middlewarePath, 'utf-8');
        expect(middlewareContent).toContain('errorHandler');
        // Verify error boundary
        const boundaryPath = path.join(testOutputDir, 'web/src/components/ErrorBoundary.tsx');
        expect(fs.existsSync(boundaryPath)).toBe(true);
    });
    it('should generate custom error classes', async () => {
        const workflow = {
            workflow: {
                id: 'test-custom-errors',
                version: '1.0.0',
                name: 'Test Custom Errors',
                description: 'Testing custom error classes',
            },
            stack: {},
            error_handling: {
                custom_errors: [
                    {
                        name: 'PaymentError',
                        status_code: 402,
                        default_message: 'Payment required',
                    },
                ],
            },
        };
        const orchestrator = new generation_orchestrator_1.GenerationOrchestrator();
        const _result = await orchestrator.generate(workflow, { outputDirectory: testOutputDir, dryRun: false });
        const errorsPath = path.join(testOutputDir, 'api/src/errors/custom-errors.ts');
        expect(fs.existsSync(errorsPath)).toBe(true);
        const errorsContent = fs.readFileSync(errorsPath, 'utf-8');
        expect(errorsContent).toContain('PaymentError');
    });
    it('should generate error recovery strategies', async () => {
        const workflow = {
            workflow: {
                id: 'test-recovery',
                version: '1.0.0',
                name: 'Test Error Recovery',
                description: 'Testing error recovery',
            },
            stack: {},
            error_handling: {
                recovery_strategies: [
                    {
                        error_type: 'NetworkError',
                        strategy: 'retry',
                    },
                ],
            },
        };
        const orchestrator = new generation_orchestrator_1.GenerationOrchestrator();
        const _result = await orchestrator.generate(workflow, { outputDirectory: testOutputDir, dryRun: false });
        const recoveryPath = path.join(testOutputDir, 'api/src/utils/error-recovery.ts');
        expect(fs.existsSync(recoveryPath)).toBe(true);
        const recoveryContent = fs.readFileSync(recoveryPath, 'utf-8');
        expect(recoveryContent).toContain('retry');
        expect(recoveryContent).toContain('CircuitBreaker');
    });
    it('should handle Pino logger', async () => {
        const workflow = {
            workflow: {
                id: 'test-pino',
                version: '1.0.0',
                name: 'Test Pino Logger',
                description: 'Testing Pino logging',
            },
            stack: {},
            error_handling: {
                logging: {
                    provider: 'pino',
                    level: 'info',
                },
            },
        };
        const orchestrator = new generation_orchestrator_1.GenerationOrchestrator();
        const _result = await orchestrator.generate(workflow, { outputDirectory: testOutputDir, dryRun: false });
        const loggerPath = path.join(testOutputDir, 'api/src/middleware/error-logger.ts');
        expect(fs.existsSync(loggerPath)).toBe(true);
        const loggerContent = fs.readFileSync(loggerPath, 'utf-8');
        expect(loggerContent).toContain('pino');
    });
    it('should generate Problem JSON formatter', async () => {
        const workflow = {
            workflow: {
                id: 'test-problem-json',
                version: '1.0.0',
                name: 'Test Problem JSON',
                description: 'Testing Problem JSON format',
            },
            stack: {},
            error_handling: {
                api_formatting: {
                    format: 'problem_json',
                },
            },
        };
        const orchestrator = new generation_orchestrator_1.GenerationOrchestrator();
        const _result = await orchestrator.generate(workflow, { outputDirectory: testOutputDir, dryRun: false });
        const formatterPath = path.join(testOutputDir, 'api/src/middleware/error-formatter.ts');
        expect(fs.existsSync(formatterPath)).toBe(true);
        const formatterContent = fs.readFileSync(formatterPath, 'utf-8');
        expect(formatterContent).toContain('Problem JSON');
    });
});
//# sourceMappingURL=enhanced-error-handling.e2e.test.js.map