import dotenv from 'dotenv';
import { MikroORM } from '@mikro-orm/core';
import config from '../../mikro-orm.config';
import { DatabaseSeeder } from '../database/seeds';

// Load environment variables
dotenv.config({ path: '.env.test' });

// Set default environment variables for testing
process.env.NODE_ENV = 'test';
process.env.JWT_SECRET = 'test-secret-key';
process.env.DATABASE_URL = 'postgresql://test:test@localhost:5432/test_db';

let orm: MikroORM;

// Global setup
beforeAll(async () => {
    // Initialize the database connection
    orm = await MikroORM.init(config);

    // Run migrations
    const migrator = orm.getMigrator();
    await migrator.up();

    // Seed the database
    const seeder = new DatabaseSeeder(orm.em);
    await seeder.run();
});

// Global cleanup
afterAll(async () => {
    if (orm) {
        await orm.close();
    }
}); 