mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 21:08:12 +00:00
auto allocation and batch managemnt, tracking the train
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import {
|
||||
getBatchWindowForTimestamp,
|
||||
listBatchWindowsForDate,
|
||||
listBatchWindowsForBookings,
|
||||
BATCH_WINDOW_START_HOURS,
|
||||
} from './batch-window.util';
|
||||
|
||||
describe('batch-window.util', () => {
|
||||
it('maps 20:15 EAT to the 19:00–22:00 window', () => {
|
||||
// 20:15 EAT = 17:15 UTC on 11 Jun 2026
|
||||
const ts = new Date('2026-06-11T17:15:00.000Z');
|
||||
const window = getBatchWindowForTimestamp(ts);
|
||||
|
||||
expect(window.label).toContain('19:00');
|
||||
expect(window.label).toContain('22:00');
|
||||
expect(window.label).toContain('11 Jun 2026');
|
||||
});
|
||||
|
||||
it('maps 08:30 EAT to the 07:00–10:00 window', () => {
|
||||
const ts = new Date('2026-06-11T05:30:00.000Z'); // 08:30 EAT
|
||||
const window = getBatchWindowForTimestamp(ts);
|
||||
expect(window.label).toContain('07:00');
|
||||
expect(window.label).toContain('10:00');
|
||||
});
|
||||
|
||||
it('maps 02:00 EAT to the previous day 22:00–07:00 window', () => {
|
||||
const ts = new Date('2026-06-11T23:00:00.000Z'); // 02:00 EAT on 12 Jun
|
||||
const window = getBatchWindowForTimestamp(ts);
|
||||
expect(window.label).toContain('22:00');
|
||||
expect(window.label).toContain('07:00');
|
||||
expect(window.label).toContain('11 Jun 2026');
|
||||
});
|
||||
|
||||
it('lists six windows for a calendar day', () => {
|
||||
const ref = new Date('2026-06-11T12:00:00.000Z');
|
||||
const windows = listBatchWindowsForDate(ref);
|
||||
expect(windows).toHaveLength(BATCH_WINDOW_START_HOURS.length);
|
||||
expect(windows[0].label).toContain('07:00');
|
||||
expect(windows[windows.length - 1].label).toContain('22:00');
|
||||
});
|
||||
|
||||
it('includes cross-day overnight window when booking signed at 00:02 EAT', () => {
|
||||
// 21:02 UTC = 00:02 EAT on 12 Jun → belongs to 11 Jun 22:00–07:00 window
|
||||
const fullyExecutedAt = new Date('2026-06-11T21:02:05.153Z');
|
||||
const scheduleDate = new Date('2026-06-12T06:00:00.000Z');
|
||||
const windows = listBatchWindowsForBookings([fullyExecutedAt], scheduleDate);
|
||||
const overnight = windows.find((w) => w.label.includes('22:00') && w.label.includes('07:00'));
|
||||
expect(overnight).toBeDefined();
|
||||
expect(overnight!.label).toContain('11 Jun 2026');
|
||||
expect(getBatchWindowForTimestamp(fullyExecutedAt).key).toBe(overnight!.key);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user