import * as v from 'valibot' import { describe, expect, test } from 'vitest' import { conversationStarterSchema, latestVersionedConfigSchema } from './webchat' describe('conversationStarterSchema', () => { test('accepts a fully-specified starter', () => { const starter = { id: 'abc123', text: 'Track my order', title: 'Track my order', description: 'Check status & delivery date', icon: 'package', enabled: true, } expect(v.parse(conversationStarterSchema, starter)).toEqual(starter) }) test('accepts a minimal starter (only id + text)', () => { const starter = { id: 'abc123', text: 'Talk to a human' } expect(v.parse(conversationStarterSchema, starter)).toEqual(starter) }) test('accepts any lucide icon name (free-form string)', () => { const result = v.safeParse(conversationStarterSchema, { id: 'abc123', text: 'Track my order', icon: 'rocket', }) expect(result.success).toBe(true) }) test('rejects a starter without text', () => { const result = v.safeParse(conversationStarterSchema, { id: 'abc123' }) expect(result.success).toBe(false) }) }) describe('latestVersionedConfigSchema with conversation starters', () => { test('round-trips starters, display style, and the enabled flag', () => { const config = { version: 'v2' as const, conversationStartersEnabled: true, conversationStartersDisplayStyle: 'cards' as const, conversationStarters: [ { id: '1', text: 'Track my order', description: 'Check status & delivery date', icon: 'package' }, { id: '2', text: 'Strongest coffee?', enabled: false }, ], } const parsed = v.parse(latestVersionedConfigSchema, config) expect(parsed.conversationStartersEnabled).toBe(true) expect(parsed.conversationStartersDisplayStyle).toBe('cards') expect(parsed.conversationStarters).toEqual(config.conversationStarters) }) test('parses a config with no starters fields (backward compatible)', () => { const parsed = v.parse(latestVersionedConfigSchema, { version: 'v2' as const }) expect(parsed.conversationStarters).toBeUndefined() expect(parsed.conversationStartersDisplayStyle).toBeUndefined() }) test('rejects an invalid display style', () => { const result = v.safeParse(latestVersionedConfigSchema, { version: 'v2', conversationStartersDisplayStyle: 'carousel', }) expect(result.success).toBe(false) }) })