"use strict";
/**
 * Tests for Enhanced Rate Limiting Generator
 */
Object.defineProperty(exports, "__esModule", { value: true });
const enhanced_rate_limiting_generator_1 = require("./enhanced-rate-limiting-generator");
describe('EnhancedRateLimitingGenerator', () => {
    let generator;
    beforeEach(() => {
        generator = new enhanced_rate_limiting_generator_1.EnhancedRateLimitingGenerator();
    });
    describe('Configuration Generation', () => {
        it('should generate rate limiting configuration', () => {
            const workflow = {
                workflow: { id: 'test', version: '1.0', name: 'Test', description: 'Test workflow' },
                stack: {},
                rate_limiting: {
                    middleware: true,
                    storage: {
                        type: 'redis',
                        redis_url: 'redis://localhost:6379',
                    },
                    strategy: 'sliding_window',
                    per_user: {
                        requests: 100,
                        window: '1m',
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
                executionPlan: { components: [], services: [] },
            };
            const result = generator.generate(context);
            expect(result.files.length).toBeGreaterThan(0);
            const configFile = result.files.find(f => f.path.includes('config/rate-limiting.ts'));
            expect(configFile).toBeDefined();
            expect(configFile.content).toContain('sliding_window');
            expect(configFile.content).toContain('redis');
        });
    });
    describe('Middleware Generation', () => {
        it('should generate rate limit middleware', () => {
            const workflow = {
                workflow: { id: 'test', version: '1.0', name: 'Test', description: 'Test workflow' },
                stack: {},
                rate_limiting: {
                    middleware: true,
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
                executionPlan: { components: [], services: [] },
            };
            const result = generator.generate(context);
            const middlewareFile = result.files.find(f => f.path.includes('middleware/rate-limit.ts'));
            expect(middlewareFile).toBeDefined();
            expect(middlewareFile.content).toContain('rateLimit');
            expect(middlewareFile.content).toContain('rateLimitPerUser');
        });
    });
    describe('Storage Backends', () => {
        it('should generate Redis store', () => {
            const workflow = {
                workflow: { id: 'test', version: '1.0', name: 'Test', description: 'Test workflow' },
                stack: {},
                rate_limiting: {
                    storage: {
                        type: 'redis',
                        redis_url: 'redis://localhost:6379',
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
                executionPlan: { components: [], services: [] },
            };
            const result = generator.generate(context);
            const storeFile = result.files.find(f => f.path.includes('rate-limit-store.ts'));
            expect(storeFile).toBeDefined();
            expect(storeFile.content).toContain('Redis');
            expect(storeFile.content).toContain('ioredis');
        });
        it('should generate memory store', () => {
            const workflow = {
                workflow: { id: 'test', version: '1.0', name: 'Test', description: 'Test workflow' },
                stack: {},
                rate_limiting: {
                    storage: {
                        type: 'memory',
                    },
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
                executionPlan: { components: [], services: [] },
            };
            const result = generator.generate(context);
            const storeFile = result.files.find(f => f.path.includes('rate-limit-store.ts'));
            expect(storeFile).toBeDefined();
            expect(storeFile.content).toContain('Map<string, StoreEntry>');
        });
    });
    describe('Strategies', () => {
        it('should generate rate limit strategies', () => {
            const workflow = {
                workflow: { id: 'test', version: '1.0', name: 'Test', description: 'Test workflow' },
                stack: {},
                rate_limiting: {
                    strategy: 'sliding_window',
                },
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
                executionPlan: { components: [], services: [] },
            };
            const result = generator.generate(context);
            const strategiesFile = result.files.find(f => f.path.includes('rate-limit-strategies.ts'));
            expect(strategiesFile).toBeDefined();
            expect(strategiesFile.content).toContain('SlidingWindowStrategy');
            expect(strategiesFile.content).toContain('FixedWindowStrategy');
            expect(strategiesFile.content).toContain('TokenBucketStrategy');
        });
    });
    describe('Edge Cases', () => {
        it('should return empty array when rate_limiting not configured', () => {
            const workflow = {
                workflow: { id: 'test', version: '1.0', name: 'Test', description: 'Test workflow' },
                stack: {},
            };
            const context = {
                workflow,
                outputDirectory: '/tmp/test',
                executionPlan: { components: [], services: [] },
            };
            const result = generator.generate(context);
            expect(result.files).toEqual([]);
        });
    });
});
//# sourceMappingURL=enhanced-rate-limiting-generator.test.js.map