38 lines
3.2 KiB
JavaScript
38 lines
3.2 KiB
JavaScript
'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('five minute intake deadline partitions arrivals without a gap across send times and weekends',()=>{
|
|
const morning=windowForCutoff('2026-10-26T03:00:00Z',schedule),afternoon=windowForCutoff('2026-10-26T09:00:00Z',schedule),next=windowForCutoff('2026-10-27T03:00:00Z',schedule);
|
|
assert.equal(morning.end,'2026-10-26T03:00:00.000Z');assert.equal(morning.collectionEnd,'2026-10-26T02:55:00.000Z');assert.equal(morning.collectionStart,'2026-10-23T08:55:00.000Z');
|
|
for(const [at,want]of [['2026-10-26T02:54:59.999Z',true],['2026-10-26T02:55:00Z',false],['2026-10-26T02:59:59Z',false]])assert.equal(inWindow(at,morning),want);
|
|
assert.equal(inWindow('2026-10-26T02:55:00Z',afternoon),true);assert.equal(inWindow('2026-10-26T02:59:59Z',afternoon),true);assert.equal(inWindow('2026-10-26T08:55:00Z',afternoon),false);assert.equal(inWindow('2026-10-26T08:55:00Z',next),true);
|
|
const legacy={start:'2026-10-26T03:00:00Z',end:'2026-10-26T09:00:00Z'};assert.equal(inWindow('2026-10-26T08:59:59Z',legacy),true);
|
|
});
|
|
test('normal weekday first interval continuously covers prior evening',()=>{
|
|
const morning=windowForCutoff('2026-10-20T03:00:00Z',schedule),afternoon=windowForCutoff('2026-10-20T09:00:00Z',schedule);
|
|
assert.equal(morning.start,'2026-10-19T09: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:54: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);
|
|
});
|