"use strict";
/**
 * Tests for SeedDataGenerator
 */
Object.defineProperty(exports, "__esModule", { value: true });
const seed_data_generator_1 = require("./seed-data-generator");
describe('SeedDataGenerator', () => {
    let generator;
    beforeEach(() => {
        generator = new seed_data_generator_1.SeedDataGenerator({ recordsPerTable: 3 });
    });
    it('should generate seed data for a simple table', () => {
        const tables = [
            {
                name: 'users',
                fields: [
                    { name: 'id', type: 'uuid', primaryKey: true },
                    { name: 'email', type: 'string', unique: true },
                    { name: 'name', type: 'string' },
                    { name: 'createdAt', type: 'timestamp' },
                ],
            },
        ];
        const result = generator.generateSeedData(tables);
        expect(result).toContain('import { PrismaClient } from');
        expect(result).toContain('const usersData = [');
        expect(result).toContain('email:');
        expect(result).toContain('name:');
        expect(result).toContain('await prisma.users.createMany');
        expect(result).toContain('skipDuplicates: true');
    });
    it('should generate seed data with foreign keys in correct order', () => {
        const tables = [
            {
                name: 'users',
                fields: [
                    { name: 'id', type: 'uuid', primaryKey: true },
                    { name: 'email', type: 'string' },
                ],
            },
            {
                name: 'posts',
                fields: [
                    { name: 'id', type: 'uuid', primaryKey: true },
                    { name: 'userId', type: 'uuid', foreignKey: 'users.id' },
                    { name: 'title', type: 'string' },
                ],
            },
        ];
        const result = generator.generateSeedData(tables);
        // Users should be seeded before posts
        const usersIndex = result.indexOf('const usersData');
        const postsIndex = result.indexOf('const postsData');
        expect(usersIndex).toBeLessThan(postsIndex);
        // Posts should reference user data
        expect(result).toContain('userId: usersData[');
    });
    it('should generate realistic email values', () => {
        const tables = [
            {
                name: 'users',
                fields: [
                    { name: 'id', type: 'uuid', primaryKey: true },
                    { name: 'email', type: 'string' },
                ],
            },
        ];
        const result = generator.generateSeedData(tables);
        expect(result).toContain('@example.com');
        expect(result).toContain('email: "user');
    });
    it('should generate realistic password hashes', () => {
        const tables = [
            {
                name: 'users',
                fields: [
                    { name: 'id', type: 'uuid', primaryKey: true },
                    { name: 'passwordHash', type: 'string' },
                ],
            },
        ];
        const result = generator.generateSeedData(tables);
        expect(result).toContain('passwordHash:');
        expect(result).toContain('$2b$10$');
    });
    it('should handle multiple field types correctly', () => {
        const tables = [
            {
                name: 'products',
                fields: [
                    { name: 'id', type: 'uuid', primaryKey: true },
                    { name: 'name', type: 'string' },
                    { name: 'price', type: 'decimal' },
                    { name: 'quantity', type: 'integer' },
                    { name: 'active', type: 'boolean' },
                    { name: 'releaseDate', type: 'date' },
                ],
            },
        ];
        const result = generator.generateSeedData(tables);
        expect(result).toContain('name:');
        expect(result).toContain('price:');
        expect(result).toContain('quantity:');
        expect(result).toContain('active:');
        expect(result).toContain('releaseDate:');
    });
    it('should generate seed data for audit logs with foreign keys', () => {
        const tables = [
            {
                name: 'users',
                fields: [
                    { name: 'id', type: 'uuid', primaryKey: true },
                    { name: 'email', type: 'string' },
                    { name: 'name', type: 'string' },
                ],
            },
            {
                name: 'audit_logs',
                fields: [
                    { name: 'id', type: 'uuid', primaryKey: true },
                    { name: 'userId', type: 'uuid', foreignKey: 'users.id' },
                    { name: 'action', type: 'string' },
                    { name: 'ipAddress', type: 'string' },
                    { name: 'timestamp', type: 'timestamp' },
                ],
            },
        ];
        const result = generator.generateSeedData(tables);
        // Check structure
        expect(result).toContain('const usersData');
        expect(result).toContain('const auditLogsData');
        // Check foreign key reference
        expect(result).toContain('userId: usersData[');
        // Check specific field generation
        expect(result).toContain('action:');
        expect(result).toContain('ipAddress:');
    });
    it('should generate data for the user authentication workflow schema', () => {
        const tables = [
            {
                name: 'users',
                fields: [
                    { name: 'id', type: 'uuid', primaryKey: true },
                    { name: 'email', type: 'string', unique: true },
                    { name: 'passwordHash', type: 'string' },
                    { name: 'name', type: 'string' },
                    { name: 'createdAt', type: 'timestamp' },
                ],
            },
            {
                name: 'audit_logs',
                fields: [
                    { name: 'id', type: 'uuid', primaryKey: true },
                    { name: 'userId', type: 'uuid', foreignKey: 'users.id' },
                    { name: 'action', type: 'string' },
                    { name: 'timestamp', type: 'timestamp' },
                    { name: 'ipAddress', type: 'string' },
                ],
            },
        ];
        const result = generator.generateSeedData(tables);
        // Should have proper structure
        expect(result).toContain('import { PrismaClient }');
        expect(result).toContain('async function main()');
        expect(result).toContain('🌱 Seeding database');
        // Users seeded first
        expect(result).toContain('Seed users');
        expect(result).toContain('email: "user');
        expect(result).toContain('@example.com');
        expect(result).toContain('passwordHash:');
        expect(result).toContain('name: "');
        // Audit logs seeded after users
        expect(result).toContain('Seed audit_logs');
        expect(result).toContain('userId: usersData[');
        expect(result).toContain('action:');
        expect(result).toContain('ipAddress: "192.168.1.');
        // Verify order
        const usersIndex = result.indexOf('Seed users');
        const auditIndex = result.indexOf('Seed audit_logs');
        expect(usersIndex).toBeLessThan(auditIndex);
    });
    it('should handle optional foreign keys', () => {
        const tables = [
            {
                name: 'users',
                fields: [
                    { name: 'id', type: 'uuid', primaryKey: true },
                    { name: 'email', type: 'string' },
                ],
            },
            {
                name: 'comments',
                fields: [
                    { name: 'id', type: 'uuid', primaryKey: true },
                    { name: 'userId', type: 'uuid', foreignKey: 'users.id', optional: true },
                    { name: 'content', type: 'string' },
                ],
            },
        ];
        const result = generator.generateSeedData(tables);
        // Some records should have null userId
        expect(result).toContain('userId: null');
        // Some should have actual references
        expect(result).toContain('userId: usersData[');
    });
});
//# sourceMappingURL=seed-data-generator.test.js.map