import { describe, expect, it } from 'vitest'; import { buildQuestions, QUESTIONS, toEvidence } from '../src/jev.ts'; const base = { claims_sector: { choice: 'solicitation', probabilities: { financial: 0.05, healthcare: 0, education: 0, solicitation: 0.95 } }, specific_detail: { noul: 0.03 }, official_channel: { noul: 0.04 }, pressure: { noul: 0.2 }, agent_or_credentials: { noul: 0.1 }, sales_pitch: { noul: 0.98 }, self_assertion: { noul: 0.1 }, category: { probabilities: { legit_alert: 0, scam: 0.3, marketing_robocall: 0.7 } }, }; describe('known-script question', () => { it('is omitted when no junk scripts are known', () => expect(buildQuestions([])).toBe(QUESTIONS)); it('lists each known script plus none', () => { const q = buildQuestions([{ id: 1, sample: 'Prime loan approval now' }]) as Record }>; expect(Object.keys(q.known_script.criteria!)).toEqual(['s1', 'none']); }); it('parses a match and a none answer', () => { expect(toEvidence({ ...base, known_script: { choice: 's1', probabilities: { s1: 0.97, none: 0.03 } } }).knownScript).toEqual({ id: 1, p: 0.97 }); expect(toEvidence({ ...base, known_script: { choice: 'none', probabilities: { s1: 0.1, none: 0.9 } } }).knownScript).toBeNull(); expect(toEvidence(base).knownScript).toBeNull(); }); });