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', () => { const db = openDb(':memory:') const m = createModule(db, 'u1', { code: 'POS', name: 'POS Billing' }) setPrice(db, 'u1', { moduleId: m.id, kind: 'yearly', pricePaise: 1_20_000_00, effectiveFrom: '2026-04-01' }) setPrice(db, 'u1', { moduleId: m.id, kind: 'yearly', pricePaise: 1_50_000_00, effectiveFrom: '2026-08-01' }) expect(priceOn(db, m.id, 'yearly', 'standard', '2026-07-10')).toBe(1_20_000_00) expect(priceOn(db, m.id, 'yearly', 'standard', '2026-09-01')).toBe(1_50_000_00) expect(priceOn(db, m.id, 'monthly', 'standard', '2026-09-01')).toBeNull() }) it('round-trips quote content and defaults it to an empty list', () => { const db = openDb(':memory:') const plain = createModule(db, 'u1', { code: 'POS', name: 'POS Billing' }) expect(plain.quoteContent).toEqual([]) const sms = 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(getModule(db, sms.id)!.quoteContent).toEqual(['Bulk SMS gateway', 'DLT template registration']) expect(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', () => { const db = openDb(':memory:') const m = createModule(db, 'u1', { code: 'SMS', name: 'SMS Gateway' }) const updated = updateModule(db, 'u1', m.id, { quoteContent: ['Two-way SMS', 'Delivery reports'] }) expect(updated.quoteContent).toEqual(['Two-way SMS', 'Delivery reports']) expect(getModule(db, m.id)!.quoteContent).toEqual(['Two-way SMS', 'Delivery reports']) const audit = listAudit(db).find((a) => a.action === 'update' && a.entity === 'module' && a.entity_id === m.id) expect(audit).toBeDefined() }) })