feat: add category order rules and read-only sent mail history

This commit is contained in:
abaishu0730 committed 2026-10-19 10:36:32 +08:00
1 parent 388805a8a6
commit efa982a8a1
41 files changed
+1828 -28

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
'use strict';
const {test}=require('node:test');const assert=require('node:assert/strict');
const {windowForCutoff,upcomingWindow,inWindow}=require('../../src/modules/order-rules/window.cjs');
const schedule={times:['11:00','17:00'],timezone:'Asia/Shanghai',weekends:false};
test('normal weekday only includes same-day first interval or interval between send times',()=>{
const morning=windowForCutoff('2026-10-20T03:00:00Z',schedule),afternoon=windowForCutoff('2026-10-20T09:00:00Z',schedule);
assert.equal(morning.start,'2026-10-19T16:00:00.000Z');assert.equal(morning.end,'2026-10-20T03:00:00.000Z');
assert.equal(afternoon.start,'2026-10-20T03:00:00.000Z');assert.equal(afternoon.end,'2026-10-20T09:00:00.000Z');
assert.equal(inWindow('2026-10-19T08:00:00Z',morning),false);
assert.equal(inWindow('2026-10-20T03:00:00Z',morning),false);assert.equal(inWindow('2026-10-20T03:00:00Z',afternoon),true);
});
test('Monday first mail covers last workday final cutoff through Monday morning, never older history',()=>{
const window=windowForCutoff('2026-10-19T03:00:00Z',schedule);
assert.equal(window.start,'2026-10-16T09:00:00.000Z');assert.equal(window.end,'2026-10-19T03:00:00.000Z');
assert.equal(inWindow('2026-10-16T08:59:59Z',window),false);assert.equal(inWindow('2026-10-17T10:00:00Z',window),true);
});
test('business calendar determines previous actual working day across a rest period',()=>{
const window=windowForCutoff('2026-10-19T03:00:00Z',schedule,[{date:'2026-10-16',kind:'restday',send:false,scan:false}]);
assert.equal(window.start,'2026-10-15T09:00:00.000Z');
assert.throws(()=>windowForCutoff('2026-10-18T03:00:00Z',schedule),e=>e.status===400);
assert.throws(()=>windowForCutoff('2026-10-20T04:00:00Z',schedule),e=>e.status===400);
});
test('future preview cannot freeze a mail before its cutoff; missed slots do not reopen old windows',()=>{
const next=upcomingWindow(new Date('2026-10-20T02:00:00Z'),schedule);
assert.equal(next.end,'2026-10-20T03:00:00.000Z');assert.equal(next.available,false);
assert.equal(upcomingWindow(new Date('2026-10-20T03:00:30Z'),schedule).available,true);
const missed=upcomingWindow(new Date('2026-10-20T03:02:00Z'),schedule);
assert.equal(missed.start,'2026-10-20T03:00:00.000Z');assert.equal(missed.available,false);
});