'use strict'; const test=require('node:test'),assert=require('node:assert/strict'); const {extractTitle}=require('../../src/modules/order-rules/title.cjs'); const {buildBatch}=require('../../src/modules/order-rules/batch.cjs'); const {applyBodyTemplate}=require('../../src/modules/order-rules/template.cjs'); const rule={id:'overseas-notice',version:1,categoryId:'overseas-notice',name:'海外订单通知书',intro:'大家好:\n\n以下为海外订单通知书,请查收!',signature:'Best Regards!\n示例团队',to:['team@example.test'],cc:[],attachPdf:false}; const title='订单号:TEST-100机芯号:CORE-A产品型号:MODEL-A客户简称:示例甲出货方式:CBU总数量:0订单号:HA100机芯号:CORE-B产品型号:MODEL-B客户简称:示例乙出货方式:SKD总数量:200'; function order(id,brief=title,directory='\\\\example-nas\\orders\\overseas'){return {id,status:'pending',event:{orderNo:id,brief,receivedAt:'2026-10-20T01:00:00Z'},ruleSnapshot:rule,archive:{archivedAt:'2026-10-20T01:01:00Z',files:[{name:id+'.pdf',path:directory+'\\'+id+'.pdf',size:100,sha256:'a'.repeat(64),kind:'pdf'}]}};} test('title output separates shipping and customer for every summary row and keeps zero and missing distinct',()=>{ const result=extractTitle(title);assert.equal(result.issues.length,0); assert.deepEqual(result.orders.map(({orderNo,coreNo,productModel,customerShort,shippingMethod,totalQuantity})=>({orderNo,coreNo,productModel,customerShort,shippingMethod,totalQuantity})),[ {orderNo:'TEST-100',coreNo:'CORE-A',productModel:'MODEL-A',customerShort:'示例甲',shippingMethod:'CBU',totalQuantity:'0'}, {orderNo:'HA100',coreNo:'CORE-B',productModel:'MODEL-B',customerShort:'示例乙',shippingMethod:'SKD',totalQuantity:'200'}]); assert.equal(extractTitle('订单号:TEST-2客户简称:示例丙总数量:5').orders[0].shippingMethod,undefined);assert.equal(result.brief.includes('出货方式:CBU'),true); }); test('overseas mail has summary paragraphs and one actual directory after the list without per-file clutter',()=>{ const one=order('TEST-100'),two=order('TEST-200','订单号:TEST-200机芯号:C产品型号:M客户简称:示例丙出货方式:CBU总数量:5'); const batch=buildBatch(rule,[one,two],'2026-10-20T03:00:00Z'); assert.equal(batch.text,[rule.intro,title.replace('订单号:HA100','\n订单号:HA100')+'\n'+two.event.brief,'存放地址:\\\\example-nas\\orders\\overseas',rule.signature].join('\n\n')); assert.equal((batch.text.match(/存放地址/g)||[]).length,1);assert.doesNotMatch(batch.text,/\.pdf/);assert.equal(batch.attachments.length,0);assert.deepEqual(batch.orderIds,['TEST-100','TEST-200']); assert.match(batch.html,/file:\/\/example-nas\/orders\/overseas/);assert.doesNotMatch(batch.html,/TEST-100\.pdf/); }); test('overseas directory comes from frozen evidence and all actual directories are retained and escaped',()=>{ const batch=buildBatch({...rule,archiveDirectory:'\\\\wrong\\configured'},[order('A','订单号:A客户简称: