import { describe, it, expect } from 'vitest' import { openDb } from '../src/db' describe('hq3 schema', () => { it('creates the aws_usage table', async () => { const db = openDb(':memory:') const names = (await db.all<{ name: string }>(`SELECT name FROM sqlite_master WHERE type='table'`)).map((r) => r.name) expect(names).toContain('aws_usage') }) it('has the expected columns', async () => { const db = openDb(':memory:') const cols = (await db.all<{ name: string }>(`PRAGMA table_info(aws_usage)`)).map((c) => c.name) for (const c of ['id', 'client_id', 'month', 'storage_gb', 'transfer_gb', 'cost_paise', 'source', 'updated_at']) expect(cols, `missing column ${c}`).toContain(c) }) it('enforces one row per (client, month)', async () => { const db = openDb(':memory:') const ins = `INSERT INTO aws_usage (id, client_id, month, storage_gb, transfer_gb, cost_paise, source, updated_at) VALUES (?, 'c1', '2026-06', 0, 0, 0, 'auto', '2026-07-01T00:00:00Z')` expect((await db.run(ins, 'a1')).changes).toBe(1) await expect(db.run(ins, 'a2')).rejects.toThrow() // UNIQUE (client_id, month) }) })