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', () => { const db = openDb(':memory:'); seedIfEmpty(db) expect(listInteractionTypes(db).length).toBeGreaterThanOrEqual(7) const c = createClient(db, 'u1', { name: 'Acme', stateCode: '32' }) const i = createInteraction(db, 'u1', { clientId: c.id, typeCode: 'site_visit', onDate: '2026-07-01', notes: 'Installed POS; owner wants training', followUpOn: '2026-07-08', }) expect(listInteractions(db, c.id)).toHaveLength(1) const up = updateInteraction(db, 'u1', i.id, { outcome: 'positive' }) expect(up.outcome).toBe('positive') expect(listOpenFollowUps(db, '2026-07-10').map((f) => f.id)).toContain(i.id) expect(listOpenFollowUps(db, '2026-07-05')).toHaveLength(0) // not yet due }) it('rejects an unknown interaction type', () => { const db = openDb(':memory:'); seedIfEmpty(db) const c = createClient(db, 'u1', { name: 'X', stateCode: '32' }) expect(() => createInteraction(db, 'u1', { clientId: c.id, typeCode: 'telepathy', onDate: '2026-07-01' })) .toThrow(/type/i) }) })