import { afterAll, describe, expect, it } from 'vitest'; import { loadConfig } from '../src/config.ts'; import { migrate } from '../src/db/migrate.ts'; import { closeTestPool, getTestPool } from './helpers/db.ts'; afterAll(closeTestPool); describe('database', () => { it('migrate is idempotent', async () => { const pool = await getTestPool(); await migrate(pool); await migrate(pool); const { rows } = await pool.query(`SELECT to_regclass('public.events') AS t`); expect(rows[0].t).toBe('events'); }); }); describe('config', () => { it('loadConfig rejects missing DATABASE_URL', () => { expect(() => loadConfig({ INGEST_HMAC_SECRET: 'x'.repeat(32) })).toThrow(/DATABASE_URL/); }); it('loadConfig applies defaults', () => { const c = loadConfig({ DATABASE_URL: 'postgres://x', INGEST_HMAC_SECRET: 'x'.repeat(32) }); expect(c.PORT).toBe(3001); expect(c.SFTP_INTERVAL_MIN).toBe(15); expect(c.sftp).toBeNull(); }); });