import { describe, expect, it } from 'vitest'; import { addChinaDateKeyDays, isInConfiguredTickWindow, parseHHmmToMinutes, shouldRunOrderAutoAdvanceTick, } from '../src/services/orderAutoAdvanceSchedule'; describe('定时强推调度闸门', () => { it('只在配置时刻起 15 分钟窗口内为真,过点不补跑', () => { expect(parseHHmmToMinutes('05:00')).toBe(5 * 60); expect(isInConfiguredTickWindow(5 * 60 + 7, 5 * 60)).toBe(true); expect(isInConfiguredTickWindow(5 * 60 + 15, 5 * 60)).toBe(false); expect(isInConfiguredTickWindow(21 * 60 + 25, 5 * 60)).toBe(false); }); it('跨午夜窗口可命中次日凌晨', () => { expect(isInConfiguredTickWindow(23 * 60 + 55, 23 * 60 + 50)).toBe(true); expect(isInConfiguredTickWindow(4, 23 * 60 + 50)).toBe(true); expect(isInConfiguredTickWindow(20, 23 * 60 + 50)).toBe(false); }); it('当天改配置 earliest 为次日则当天不跑', () => { const base = { enabled: true, time: '05:00', earliestRunDate: '2026-09-03', lastRunDate: null as string | null, nowMinutes: 5 * 60 + 3, dateKey: '2026-09-02', }; expect(shouldRunOrderAutoAdvanceTick(base)).toBe(false); expect(shouldRunOrderAutoAdvanceTick({ ...base, dateKey: '2026-09-03' })).toBe(true); }); it('同一日历日已跑过则不再跑', () => { expect( shouldRunOrderAutoAdvanceTick({ enabled: true, time: '05:00', lastRunDate: '2026-09-03', nowMinutes: 5 * 60 + 3, dateKey: '2026-09-03', }) ).toBe(false); }); it('addChinaDateKeyDays 跨月', () => { expect(addChinaDateKeyDays('2026-09-02', 1)).toBe('2026-09-03'); expect(addChinaDateKeyDays('2026-01-31', 1)).toBe('2026-02-01'); }); });