import { describe, it, expect } from 'vitest' import { openDb } from '../src/db' describe('hq3 schema', () => { it('creates the aws_usage table', () => { const db = openDb(':memory:') const names = (db.prepare(`SELECT name FROM sqlite_master WHERE type='table'`).all() as { name: string }[]).map((r) => r.name) expect(names).toContain('aws_usage') }) it('has the expected columns', () => { const db = openDb(':memory:') const cols = (db.prepare(`PRAGMA table_info(aws_usage)`).all() as { name: string }[]).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)', () => { const db = openDb(':memory:') const ins = db.prepare( `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(ins.run('a1').changes).toBe(1) expect(() => ins.run('a2')).toThrow() // UNIQUE (client_id, month) }) })