内部备注最少改为3个字符并明确井号计数

This commit is contained in:
summer committed 2026-12-01 00:52:33 +08:00
1 parent c5883351c1
commit 67678d73c6
4 files changed
+15 -15

No files matched your search

@@ -74,8 +74,8 @@ test('普通开单收集内部备注并恢复本地草稿,仅填内部备注
assert.throws(()=>h.run('validateOrderIdentity({customer:"客户",salesperson:"麦麦",internal_note:"字".repeat(501)})'),/内部备注最多填写500字/);
});
test('内部备注必填且至少5字,空格不能补长度;新建和修改共用字段支持标签入口',()=>{
const h=harness();for(const note of ['', '一二三四', ' 一 二 三 四\n']){h.context.__draft=draft({internal_note:note});assert.throws(()=>h.run('validateIssueDraft(__draft)'),/至少填写5个字/);}
h.context.__draft=draft({internal_note:' 一二三四五 '});assert.equal(h.run('validateIssueDraft(__draft).internal_note'),'一二三四五');
const html=h.run('orderInternalNoteField()');assert.match(html,/<textarea[^>]*required[^>]*minlength="5"/);assert.match(html,/data-order-note-tags/);
test('内部备注必填且至少3字符含井号,空格不能补长度;新建和修改共用字段支持标签入口',()=>{
const h=harness();for(const note of ['', '一二', '#字', ' 一 二\n']){h.context.__draft=draft({internal_note:note});assert.throws(()=>h.run('validateIssueDraft(__draft)'),/至少填写3个字符/);}
h.context.__draft=draft({internal_note:' #补货 '});assert.equal(h.run('validateIssueDraft(__draft).internal_note'),'#补货');
const html=h.run('orderInternalNoteField()');assert.match(html,/<textarea[^>]*required[^>]*minlength="3"/);assert.match(html,/data-order-note-tags/);
});
+8 -8
View File
@@ -4,7 +4,7 @@ const {Ledger,today}=require('../ledger'),{createApp,createUser}=require('../ser
test('标签按井号提取中文英文词语,去重并排除普通文本和HTML',()=>{
assert.deepEqual(Notes.tags('客户备注 #补货 #客户自提,#补货\n#VIP_2 #<script>'),['#补货','#客户自提','#VIP_2']);
});
test('内部备注5字校验覆盖开单和修改,标签持久复用且按订单归属隔离',async t=>{
test('内部备注3字符含井号校验覆盖开单和修改,标签持久复用且按订单归属隔离',async t=>{
const dir=fs.mkdtempSync(path.join(os.tmpdir(),'maimai-note-tags-')),ledger=new Ledger(':memory:'),password='synthetic-tags-password';
for(const [member,role] of [['owner','owner'],['assistant','assistant'],['assistant2','assistant']])createUser(ledger,member,role,password,member);
const app=createApp({mode:'trial',dataDir:dir,ledger,port:0,feishuConfig:{enabled:false}});await new Promise(r=>app.server.listen(0,'127.0.0.1',r));
@@ -13,15 +13,15 @@ test('内部备注5字校验覆盖开单和修改,标签持久复用且按订
async function call(member,route,input){const res=await fetch(base+route,{method:input===undefined?'GET':'POST',headers:{Cookie:cookies[member]||'',...(input===undefined?{}:{'Content-Type':'application/json','X-Requested-With':'maimai-ledger',Origin:base,'Idempotency-Key':randomUUID()})},...(input===undefined?{}:{body:JSON.stringify(input)})});return {status:res.status,body:await res.json(),headers:res.headers};}
for(const member of ['owner','assistant','assistant2']){const login=await call(member,'/api/login',{name:member,password});assert.equal(login.status,200);cookies[member]=login.headers.get('set-cookie').split(';')[0];}
const draft={date:today(),customer:'合成客户',salesperson:'开单人员',fee_items:[],payment_account:'助理微信',lines:[{name:'合成银饰',unit:'件',quantity:'1',pocket:'',payer:'owner',cost:'10',sale:'20'}]};
for(const note of [undefined,'',' ','一二三四',' 一 二 三 四\n','字'.repeat(501)]){const r=await call('assistant','/api/orders/issue',{...draft,internal_note:note});assert.equal(r.status,400);assert.match(r.body.error,/内部备注/);}
for(const note of [undefined,'',' ','一二','#字',' 一 二\n','字'.repeat(501)]){const r=await call('assistant','/api/orders/issue',{...draft,internal_note:note});assert.equal(r.status,400);assert.match(r.body.error,/内部备注/);}
assert.equal(ledger.one('SELECT COUNT(*) AS n FROM orders').n,0);
const created=await call('assistant','/api/orders/issue',{...draft,internal_note:' #补货 客户尺寸已核对 '});assert.equal(created.status,200,JSON.stringify(created.body));const id=created.body.id;
assert.equal(ledger.detail(id).internal_note,'#补货 客户尺寸已核对');
const created=await call('assistant','/api/orders/issue',{...draft,internal_note:' #补货 '});assert.equal(created.status,200,JSON.stringify(created.body));const id=created.body.id;
assert.equal(ledger.detail(id).internal_note,'#补货');
await call('assistant2','/api/orders/issue',{...draft,internal_note:'小昊专用 #单独标签'});
assert.deepEqual((await call('assistant','/api/order-note-tags')).body.tags,['#补货']);assert.deepEqual((await call('assistant2','/api/order-note-tags')).body.tags,['#单独标签']);assert.deepEqual(new Set((await call('owner','/api/order-note-tags')).body.tags),new Set(['#补货','#单独标签']));
const edit=(await call('assistant','/api/orders/'+id+'/edit')).body,payload={...edit.inputs,revision:edit.revision,reason:'更新内部跟进',verified:true,internal_note:'短备注'};
for(const route of ['edit','change']){const denied=await call('assistant','/api/orders/'+id+'/'+route,payload);assert.equal(denied.status,400);assert.match(denied.body.error,/至少填写5个字/);}
assert.equal(ledger.detail(id).internal_note,'#补货 客户尺寸已核对');
const accepted=await call('assistant','/api/orders/'+id+'/edit',{...payload,internal_note:'#客户自提 已核实尺寸'});assert.equal(accepted.status,200,JSON.stringify(accepted.body));assert.deepEqual((await call('assistant','/api/order-note-tags')).body.tags,['#客户自提']);
const edit=(await call('assistant','/api/orders/'+id+'/edit')).body,payload={...edit.inputs,revision:edit.revision,reason:'更新内部跟进',verified:true,internal_note:'#字'};
for(const route of ['edit','change']){const denied=await call('assistant','/api/orders/'+id+'/'+route,payload);assert.equal(denied.status,400);assert.match(denied.body.error,/至少填写3个字符/);}
assert.equal(ledger.detail(id).internal_note,'#补货');
const accepted=await call('assistant','/api/orders/'+id+'/edit',{...payload,internal_note:'#自提'});assert.equal(accepted.status,200,JSON.stringify(accepted.body));assert.deepEqual((await call('assistant','/api/order-note-tags')).body.tags,['#自提']);
assert.equal((await call('assistant2','/api/orders/'+id+'/edit',payload)).status,404);
});