const {test}=require('node:test'); const assert=require('node:assert/strict'); const {readFileSync}=require('node:fs'); const {mapRecords, normalizeContactPhone, submitTicket}=require('../utils/service-desk'); test('工单列表只保留用户可见字段并区分不同结单状态',()=>{ const deleted={ id:'deleted',createdAt:new Date(),get:k=>({isDeleted:true,progress:'已完成',resolutionSummary:'deleted'})[k], }; const row={ id:'synthetic',createdAt:new Date(),get:k=>({ticketNo:'AR-01',progress:'已受理',resolutionStatus:'不予处理', resolutionSummary:'用户可见结论',internalNote:'synthetic private',contactPhone:'synthetic redacted'})[k], }; const items=mapRecords([row,deleted],'ai_reply_report'); assert.equal(items.length,1); assert.equal(items[0].status,'不予处理'); assert.equal(items[0].result,'用户可见结论'); assert.ok(!JSON.stringify(items).includes('synthetic private')); assert.ok(!JSON.stringify(items).includes('synthetic redacted')); assert.doesNotMatch(readFileSync(require.resolve('../yuban/pages/service-desk/index.wxml'),'utf8'),/internalNote/); }); test('AI 举报页只查看进度,可打开正式对话页且不传账号凭据', () => { const {buildConversationWebViewPath, requestedTarget}=require('../utils/web-view-target'); const markup=readFileSync(require.resolve('../yuban/pages/service-desk/index.wxml'),'utf8'); assert.match(markup,/bindtap="openConversation"/); assert.match(markup,/举报此回复/); assert.doesNotMatch(markup,/{page=definition;}; global.wx={navigateTo:({url})=>{lastPath=url;}}; try { require('../yuban/pages/service-desk/index.js'); page.openConversation(); assert.equal(lastPath,buildConversationWebViewPath()); const opts=new URL(lastPath,'https://local.invalid').searchParams; assert.equal(opts.get('skipAuth'),'true'); assert.equal(requestedTarget(Object.fromEntries(opts)), 'https://www.yuban.co/home?fromStartup=1&source=wechat-miniprogram'); } finally { delete global.Page; delete global.wx; } }); test('原生提交入口拒绝 AI 举报写入,机构和问题反馈仍校验电话', async () => { assert.equal(normalizeContactPhone(' 138-0000-1234 '),'13800001234'); assert.equal(normalizeContactPhone('foo123'),''); const scope={parse:{Object(){throw Error('must not contact server');}}}; await assert.rejects(submitTicket(scope,'ai_reply_report',{}), /请在对话里举报此回复/); await assert.rejects(submitTicket(scope,'cooperation',{}), /请填写有效联系电话/); await assert.rejects(submitTicket(scope,'feedback',{}), /请填写有效联系电话/); });