import { describe, it, expect } from 'vitest' import { openDb } from '../src/db' import { createModule, updateModule, getModule, listModules, setPrice, priceOn } from '../src/repos-modules' import { listAudit } from '../src/audit' describe('module catalog', () => { it('resolves the dated price row', async () => { const db = openDb(':memory:') const m = await createModule(db, 'u1', { code: 'POS', name: 'POS Billing' }) await setPrice(db, 'u1', { moduleId: m.id, kind: 'yearly', pricePaise: 1_20_000_00, effectiveFrom: '2026-04-01' }) await setPrice(db, 'u1', { moduleId: m.id, kind: 'yearly', pricePaise: 1_50_000_00, effectiveFrom: '2026-08-01' }) expect(await priceOn(db, m.id, 'yearly', 'standard', '2026-07-10')).toBe(1_20_000_00) expect(await priceOn(db, m.id, 'yearly', 'standard', '2026-09-01')).toBe(1_50_000_00) expect(await priceOn(db, m.id, 'monthly', 'standard', '2026-09-01')).toBeNull() }) it('round-trips quote content and defaults it to an empty list', async () => { const db = openDb(':memory:') const plain = await createModule(db, 'u1', { code: 'POS', name: 'POS Billing' }) expect(plain.quoteContent).toEqual([]) const sms = await createModule(db, 'u1', { code: 'SMS', name: 'SMS Gateway', quoteContent: ['Bulk SMS gateway', 'DLT template registration'], }) expect(sms.quoteContent).toEqual(['Bulk SMS gateway', 'DLT template registration']) expect((await getModule(db, sms.id))!.quoteContent).toEqual(['Bulk SMS gateway', 'DLT template registration']) expect((await listModules(db)).find((m) => m.id === sms.id)!.quoteContent).toEqual([ 'Bulk SMS gateway', 'DLT template registration', ]) }) it('updateModule edits quote content and writes an audit row', async () => { const db = openDb(':memory:') const m = await createModule(db, 'u1', { code: 'SMS', name: 'SMS Gateway' }) const updated = await updateModule(db, 'u1', m.id, { quoteContent: ['Two-way SMS', 'Delivery reports'] }) expect(updated.quoteContent).toEqual(['Two-way SMS', 'Delivery reports']) expect((await getModule(db, m.id))!.quoteContent).toEqual(['Two-way SMS', 'Delivery reports']) const audit = (await listAudit(db)).find((a) => a.action === 'update' && a.entity === 'module' && a.entity_id === m.id) expect(audit).toBeDefined() }) })