import { describe, it, expect } from 'vitest' import { openDb } from '../src/db' import { seedIfEmpty } from '../src/seed' import { createClient } from '../src/repos-clients' import { createInteraction, listInteractions, listInteractionTypes, listOpenFollowUps, updateInteraction, } from '../src/repos-interactions' describe('interactions', () => { it('logs a typed interaction, updates outcome, and surfaces due follow-ups', async () => { const db = openDb(':memory:'); await seedIfEmpty(db) expect((await listInteractionTypes(db)).length).toBeGreaterThanOrEqual(7) const c = await createClient(db, 'u1', { name: 'Acme', stateCode: '32' }) const i = await createInteraction(db, 'u1', { clientId: c.id, typeCode: 'site_visit', onDate: '2026-07-01', notes: 'Installed POS; owner wants training', followUpOn: '2026-07-08', }) expect(await listInteractions(db, c.id)).toHaveLength(1) const up = await updateInteraction(db, 'u1', i.id, { outcome: 'positive' }) expect(up.outcome).toBe('positive') expect((await listOpenFollowUps(db, '2026-07-10')).map((f) => f.id)).toContain(i.id) expect(await listOpenFollowUps(db, '2026-07-05')).toHaveLength(0) // not yet due }) it('rejects an unknown interaction type', async () => { const db = openDb(':memory:'); await seedIfEmpty(db) const c = await createClient(db, 'u1', { name: 'X', stateCode: '32' }) await expect(createInteraction(db, 'u1', { clientId: c.id, typeCode: 'telepathy', onDate: '2026-07-01' })) .rejects.toThrow(/type/i) }) })