import test from 'node:test'; import assert from 'node:assert/strict'; import { ContactLeadValidationError, normalizeContactLeadInput } from '../src/contact-leads.js'; test('规范化有效咨询表单并允许称呼和企业名为空', () => { const result = normalizeContactLeadInput({ phone: '13800138000', needs: ['IT数字化部署', 'AI智能体部署'] }); assert.equal(result.name, ''); assert.equal(result.company, ''); assert.equal(result.phone, '13800138000'); assert.equal(result.need, 'IT数字化部署;AI智能体部署'); }); test('拒绝不合法的中国大陆手机号', () => { for (const phone of ['12800138000', '1380013800', '23800138000', '138001380000']) { assert.throws( () => normalizeContactLeadInput({ phone, needs: ['经营体系建设'] }), ContactLeadValidationError ); } }); test('核心诉求至少选择一项且只接受预设选项', () => { assert.throws( () => normalizeContactLeadInput({ phone: '13800138000', needs: [] }), /至少选择一项/ ); assert.throws( () => normalizeContactLeadInput({ phone: '13800138000', needs: ['未知选项'] }), /无效选项/ ); }); test('选择其他个性需求时必须填写说明', () => { assert.throws( () => normalizeContactLeadInput({ phone: '13800138000', needs: ['其他个性需求'] }), /填写其他个性需求/ ); const result = normalizeContactLeadInput({ phone: '13800138000', needs: ['其他个性需求'], otherNeed: '希望先进行现场访谈' }); assert.equal(result.need, '其他个性需求:希望先进行现场访谈'); });