fix: separate pending and sent mail batches

This commit is contained in:
abaishu0730 committed 2026-10-26 11:38:44 +08:00
1 parent fd2dd557c7
commit 5fe461c77d
7 files changed
+50 -8

No files matched your search

@@ -0,0 +1,15 @@
'use strict';
const test=require('node:test'),assert=require('node:assert/strict');
const {orderDrivenUI}=require('../fixtures/order-driven-ui.cjs');
test('batch tabs separate sent history, survive reload/back and keep sent content read-only',{timeout:60000},async t=>{
const {page,runtime,base,sample}=await orderDrivenUI(t,'#notification-batches'),s=runtime.orderRules;
s.put('orders',{id:'history-order',categoryId:'bs-change',orderNo:'HISTORY-1',status:'sent',sample:{connectionId:sample.connectionId},event:{connectionId:sample.connectionId}});
for(const [id,status]of [['pending-batch','prepared'],['sent-batch','sent'],['cancelled-batch','cancelled']])s.put('batches',{id,status,version:1,orderIds:['history-order'],orderNos:['HISTORY-1'],categoryId:'bs-change',subject:id,createdAt:'2026-10-26T02:00:00Z',sentAt:status==='sent'?'2026-10-26T03:00:00Z':undefined,text:'Frozen body',to:['2639266652@qq.com'],cc:[],attachments:[]});
await page.getByRole('button',{name:'刷新数据',exact:true}).click();
const pending=page.getByRole('tab',{name:'待发送',exact:true}),sent=page.getByRole('tab',{name:'已发送',exact:true});await pending.waitFor();await page.getByText('pending-batch',{exact:true}).waitFor();assert.equal(await page.getByText('sent-batch',{exact:true}).count(),0);
await sent.click();await page.getByText('sent-batch',{exact:true}).waitFor();assert.match(page.url(),/scope=sent/);assert.equal(await sent.getAttribute('aria-selected'),'true');assert.equal(await page.getByText('pending-batch',{exact:true}).count(),0);
await page.getByRole('button',{name:'查看详情',exact:true}).click();const dialog=page.getByRole('dialog',{name:'业务详情',exact:true});await dialog.getByText('Frozen body',{exact:true}).waitFor();await dialog.getByText('发送时间',{exact:true}).waitFor();assert.equal(await dialog.getByRole('button',{name:'保存批次内容',exact:true}).count(),0);assert.equal(await dialog.getByRole('button',{name:'人工补发原冻结批次',exact:true}).count(),0);await dialog.getByRole('button',{name:'关闭详情',exact:true}).click();
await page.reload();await page.getByText('sent-batch',{exact:true}).waitFor();await page.getByRole('tab',{name:'待发送',exact:true}).click();await page.getByText('pending-batch',{exact:true}).waitFor();await page.goBack();await page.getByText('sent-batch',{exact:true}).waitFor();
await page.goto(base+'/#notification-batches?status=sent');await page.getByText('sent-batch',{exact:true}).waitFor();assert.equal(await page.getByRole('tab',{name:'已发送',exact:true}).getAttribute('aria-selected'),'true');
await page.getByRole('tab',{name:'全部',exact:true}).click();await page.getByText('cancelled-batch',{exact:true}).waitFor();
});
+10
View File
@@ -60,6 +60,16 @@ test('batch pagination covers more than three pages and scope all retains comple
const c=fixture();for(let i=0;i<85;i++)c.orderRules.all('batches').push({id:'b'+i,orderIds:['o0'],status:i===0?'sent':'prepared',subject:'Batch '+i});
const active=queryBatches(c,{page:999,pageSize:25},user);assert.equal(active.page,4);assert.equal(active.total,85);assert.equal(active.items.length,10);assert.equal(queryBatches(c,{scope:'all'},user).total,86);
});
test('sent batches have a dedicated history scope and status-only links never hide sent records',()=>{
const c=fixture(),batches=c.orderRules.all('batches');
batches.push({id:'delivered',orderIds:['o0'],status:'sent',subject:'Sent notice',sentAt:'2026-10-26T03:00:00Z'},{id:'cancelled',orderIds:['o0'],status:'cancelled'},{id:'private-sent',orderIds:['foreign'],status:'sent'});
const history=queryBatches(c,{scope:'sent'},user);assert.deepEqual(history.items.map(b=>b.id),['delivered']);assert.equal(history.items[0].sentAt,'2026-10-26T03:00:00Z');
assert.deepEqual(queryBatches(c,{status:'sent'},user).items.map(b=>b.id),['delivered']);
assert.deepEqual(queryBatches(c,{},user).items.map(b=>b.id),['old']);
assert.equal(queryBatches(c,{scope:'all'},user).total,3);
assert.equal(queryBatches(c,{scope:'sent',status:'unknown'},user).total,0);
});
test('HTTP query routing rejects missing services, invalid parameters and malformed encoding',async()=>{
const {orderRuleQueryApi}=require('../../src/modules/order-rules/query-api.cjs');const c=fixture(),invoke=(route,extra={})=>orderRuleQueryApi({...c,user,route,method:'GET',url:new URL(route,'http://localhost'),reply(){},...extra});
await assert.rejects(()=>invoke('/api/order-rules/orders?unused=1',{route:'/api/order-rules/orders'}),e=>e.status===400||e.statusCode===400);