"use strict";
/**
 * Tests for Event Bus Generator
 */
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 path = __importStar(require("path"));
const event_bus_generator_1 = require("./event-bus-generator");
describe('Event Bus Generator', () => {
    let baseWorkflow;
    let baseContext;
    const testOutputDir = '/tmp/test-output';
    beforeEach(() => {
        baseWorkflow = {
            workflow: {
                id: 'test-app',
                version: '1.0.0',
                name: 'Test Application',
                description: 'Test application for event bus',
            },
            models: {},
            stack: {},
        };
        baseContext = {
            workflow: baseWorkflow,
            extendedWorkflow: undefined,
            outputDirectory: testOutputDir,
        };
    });
    // ========================================================================
    // Configuration Detection Tests
    // ========================================================================
    describe('Configuration Detection', () => {
        it('should skip generation when no extended workflow', async () => {
            const result = await (0, event_bus_generator_1.generateEventBus)(baseContext);
            expect(result.files).toHaveLength(0);
        });
        it('should skip generation when no events defined', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            expect(result.files).toHaveLength(0);
        });
        it('should skip generation when events is empty object', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {},
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            expect(result.files).toHaveLength(0);
        });
        it('should skip generation when no Redis cache configured', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            expect(result.files).toHaveLength(0);
        });
        it('should skip generation when cache provider is not Redis', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'memcached',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            expect(result.files).toHaveLength(0);
        });
        it('should generate event bus when events and Redis are configured', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            expect(result.files).toHaveLength(4);
        });
        it('should generate event bus with Upstash Redis', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'upstash-redis',
                        use: 'cloud',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            expect(result.files).toHaveLength(4);
        });
    });
    // ========================================================================
    // File Generation Tests
    // ========================================================================
    describe('File Generation', () => {
        it('should generate all 4 required files with absolute paths', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            expect(result.files).toHaveLength(4);
            // Verify all paths are absolute
            const paths = result.files.map(f => f.path);
            paths.forEach(p => {
                expect(path.isAbsolute(p)).toBe(true);
            });
            // Verify expected file paths (absolute)
            expect(paths).toContain(path.join(testOutputDir, 'backend', 'src', 'events', 'event-bus.ts'));
            expect(paths).toContain(path.join(testOutputDir, 'backend', 'src', 'events', 'event-emitter.ts'));
            expect(paths).toContain(path.join(testOutputDir, 'backend', 'src', 'events', 'event-subscriber.ts'));
            expect(paths).toContain(path.join(testOutputDir, 'backend', 'src', 'middleware', 'event-middleware.ts'));
        });
        it('should include DO NOT EDIT warnings in all files', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            for (const file of result.files) {
                expect(file.content).toContain('DO NOT EDIT MANUALLY');
            }
        });
    });
    // ========================================================================
    // Event Bus Core Tests
    // ========================================================================
    describe('Event Bus Core', () => {
        it('should generate EventBus class with required methods', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const eventBusFile = result.files.find(f => f.path.includes('event-bus.ts'));
            expect(eventBusFile).toBeDefined();
            expect(eventBusFile.content).toContain('export class EventBus');
            expect(eventBusFile.content).toContain('async initialize()');
            expect(eventBusFile.content).toContain('async publish');
            expect(eventBusFile.content).toContain('async subscribe');
            expect(eventBusFile.content).toContain('async unsubscribe');
            expect(eventBusFile.content).toContain('async close()');
        });
        it('should import ioredis for Redis connection', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const eventBusFile = result.files.find(f => f.path.includes('event-bus.ts'));
            expect(eventBusFile.content).toContain("import { Redis } from 'ioredis'");
        });
        it('should import event types from events.ts', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const eventBusFile = result.files.find(f => f.path.includes('event-bus.ts'));
            expect(eventBusFile.content).toContain("import { Event, EventType, EventPayloadMap } from '../types/events'");
        });
        it('should include EventBusConfig interface', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const eventBusFile = result.files.find(f => f.path.includes('event-bus.ts'));
            expect(eventBusFile.content).toContain('export interface EventBusConfig');
            expect(eventBusFile.content).toContain('redis:');
            expect(eventBusFile.content).toContain('host: string');
            expect(eventBusFile.content).toContain('port: number');
            expect(eventBusFile.content).toContain('password?: string');
        });
        it('should include singleton pattern with getEventBus function', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const eventBusFile = result.files.find(f => f.path.includes('event-bus.ts'));
            expect(eventBusFile.content).toContain('let eventBusInstance: EventBus | null = null');
            expect(eventBusFile.content).toContain('export function getEventBus');
            expect(eventBusFile.content).toContain('export async function closeEventBus');
        });
        it('should handle message parsing and error handling', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const eventBusFile = result.files.find(f => f.path.includes('event-bus.ts'));
            expect(eventBusFile.content).toContain('private async handleMessage');
            expect(eventBusFile.content).toContain('JSON.parse(message)');
            expect(eventBusFile.content).toContain('catch (error)');
        });
    });
    // ========================================================================
    // Event Emitter Tests
    // ========================================================================
    describe('Event Emitter', () => {
        it('should generate event emitter utility functions', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const emitterFile = result.files.find(f => f.path.includes('event-emitter.ts'));
            expect(emitterFile).toBeDefined();
            expect(emitterFile.content).toContain('export async function emitEvent');
            expect(emitterFile.content).toContain('export function eventContextMiddleware');
            expect(emitterFile.content).toContain('export async function emitEventWithContext');
        });
        it('should include EmitEventOptions interface', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const emitterFile = result.files.find(f => f.path.includes('event-emitter.ts'));
            expect(emitterFile.content).toContain('export interface EmitEventOptions');
            expect(emitterFile.content).toContain('correlationId?: string');
            expect(emitterFile.content).toContain('userId?: string');
        });
        it('should implement correlation ID generation in middleware', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const emitterFile = result.files.find(f => f.path.includes('event-emitter.ts'));
            expect(emitterFile.content).toContain('req.correlationId');
            expect(emitterFile.content).toContain('x-correlation-id');
        });
        it('should handle errors gracefully without throwing', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const emitterFile = result.files.find(f => f.path.includes('event-emitter.ts'));
            expect(emitterFile.content).toContain('try {');
            expect(emitterFile.content).toContain('catch (error)');
            expect(emitterFile.content).toContain("// Don't throw");
        });
    });
    // ========================================================================
    // Event Subscriber Tests
    // ========================================================================
    describe('Event Subscriber', () => {
        it('should generate subscriber utility functions', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const subscriberFile = result.files.find(f => f.path.includes('event-subscriber.ts'));
            expect(subscriberFile).toBeDefined();
            expect(subscriberFile.content).toContain('export async function subscribeToEvent');
            expect(subscriberFile.content).toContain('export async function initializeEventSubscribers');
            expect(subscriberFile.content).toContain('export async function shutdownEventSubscribers');
        });
        it('should include SubscriberConfig interface', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const subscriberFile = result.files.find(f => f.path.includes('event-subscriber.ts'));
            expect(subscriberFile.content).toContain('export interface SubscriberConfig');
            expect(subscriberFile.content).toContain('eventType: EventType');
            expect(subscriberFile.content).toContain('handler: EventHandler');
            expect(subscriberFile.content).toContain('name?: string');
        });
        it('should initialize subscribers in a loop', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const subscriberFile = result.files.find(f => f.path.includes('event-subscriber.ts'));
            expect(subscriberFile.content).toContain('for (const subscriber of subscribers)');
            expect(subscriberFile.content).toContain('await subscribeToEvent(subscriber)');
        });
    });
    // ========================================================================
    // Event Middleware Tests
    // ========================================================================
    describe('Event Middleware', () => {
        it('should generate Express middleware functions', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const middlewareFile = result.files.find(f => f.path.includes('event-middleware.ts'));
            expect(middlewareFile).toBeDefined();
            expect(middlewareFile.content).toContain('export function eventContextMiddleware');
            expect(middlewareFile.content).toContain('export function eventErrorHandler');
        });
        it('should import Express types', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const middlewareFile = result.files.find(f => f.path.includes('event-middleware.ts'));
            expect(middlewareFile.content).toContain("import { Request, Response, NextFunction } from 'express'");
        });
        it('should set correlation ID in response headers', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const middlewareFile = result.files.find(f => f.path.includes('event-middleware.ts'));
            expect(middlewareFile.content).toContain("res.setHeader('x-correlation-id'");
        });
        it('should implement non-blocking error handler', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            const middlewareFile = result.files.find(f => f.path.includes('event-middleware.ts'));
            expect(middlewareFile.content).toContain('eventErrorHandler');
            expect(middlewareFile.content).toContain("// Don't send error response");
        });
    });
    // ========================================================================
    // Code Quality Tests
    // ========================================================================
    describe('Code Quality', () => {
        it('should generate syntactically valid TypeScript in all files', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            for (const file of result.files) {
                expect(file.content).toContain('export');
                expect(file.content).not.toContain('undefined;');
                expect(file.content).not.toContain('[object Object]');
            }
        });
        it('should include comprehensive JSDoc comments', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            for (const file of result.files) {
                expect(file.content).toContain('/**');
                expect(file.content).toContain('*/');
            }
        });
        it('should use consistent code formatting', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            for (const file of result.files) {
                // Check for consistent async/await usage
                if (file.content.includes('async function')) {
                    expect(file.content).toContain('Promise<');
                }
            }
        });
    });
    // ========================================================================
    // Edge Cases
    // ========================================================================
    describe('Edge Cases', () => {
        it('should handle custom backend directory with absolute paths', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                        directory: 'server',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            // All paths should be absolute and contain the custom 'server' directory
            for (const file of result.files) {
                expect(path.isAbsolute(file.path)).toBe(true);
                expect(file.path).toContain(path.join(testOutputDir, 'server'));
            }
        });
        it('should work with minimal event configuration', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    ping: {
                        description: 'Ping',
                        payload: {},
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            expect(result.files).toHaveLength(4);
        });
        it('should handle multiple events', async () => {
            const extendedWorkflow = {
                ...baseWorkflow.workflow,
                technology: {
                    backend: {
                        framework: 'express',
                        language: 'typescript',
                    },
                    cache: {
                        provider: 'redis',
                        use: 'local',
                    },
                },
                events: {
                    user_created: {
                        description: 'User created',
                        payload: { user_id: 'string' },
                    },
                    user_updated: {
                        description: 'User updated',
                        payload: { user_id: 'string' },
                    },
                    user_deleted: {
                        description: 'User deleted',
                        payload: { user_id: 'string' },
                    },
                },
            };
            const context = {
                ...baseContext,
                extendedWorkflow,
            };
            const result = await (0, event_bus_generator_1.generateEventBus)(context);
            expect(result.files).toHaveLength(4);
            // Event bus should work with any number of events
        });
    });
});
//# sourceMappingURL=event-bus-generator.test.js.map