mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 20:05:41 +00:00
Implement client-side validation for container and bul
This commit is contained in:
@@ -17,6 +17,8 @@ describe('BookingWindowService — window state machine', () => {
|
||||
expireUnacceptedForRouteDay: jest.Mock;
|
||||
settleDueReservations: jest.Mock;
|
||||
isScheduleFull: jest.Mock;
|
||||
hasLiveReservations: jest.Mock;
|
||||
refreshWindowStatus: jest.Mock;
|
||||
};
|
||||
let trainSchedulesRepository: { findById: jest.Mock; findAll: jest.Mock };
|
||||
let trainSchedulingService: { finalizeSchedule: jest.Mock; getWindowConfig: jest.Mock };
|
||||
@@ -68,6 +70,9 @@ describe('BookingWindowService — window state machine', () => {
|
||||
expireUnacceptedForRouteDay: jest.fn().mockResolvedValue(undefined),
|
||||
settleDueReservations: jest.fn().mockResolvedValue(undefined),
|
||||
isScheduleFull: jest.fn().mockResolvedValue(false),
|
||||
// No reservation is mid-pay-window by default, so the cycle concludes.
|
||||
hasLiveReservations: jest.fn().mockResolvedValue(false),
|
||||
refreshWindowStatus: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
trainSchedulesRepository = {
|
||||
findById: jest.fn().mockResolvedValue(null),
|
||||
@@ -154,6 +159,26 @@ describe('BookingWindowService — window state machine', () => {
|
||||
expect(batch.settleDueReservations).toHaveBeenCalledWith(scheduleId);
|
||||
});
|
||||
|
||||
it('PAYMENT holds the cycle open while a reservation is still inside its pay window', async () => {
|
||||
// `paymentPhaseEndsAt` is stamped when the phase starts; reserve() then sets each
|
||||
// booking's own deadline milliseconds later. So the phase deadline always passes
|
||||
// first, and concluding here would kill customers who still had time to pay — and
|
||||
// leave no cycle for the waiting-list top-up to run in.
|
||||
batch.hasLiveReservations.mockResolvedValue(true);
|
||||
const s = baseSchedule({
|
||||
windowPhase: 'PAYMENT',
|
||||
paymentPhaseEndsAt: new Date('2026-07-01T02:30:00.000Z'),
|
||||
});
|
||||
|
||||
const advanced = await advanceImport(s, new Date('2026-07-01T02:30:01.000Z'));
|
||||
|
||||
expect(advanced).toBe(true);
|
||||
expect(batch.settleDueReservations).toHaveBeenCalledWith(scheduleId);
|
||||
// Still PAYMENT — the cycle was NOT concluded and the window did not reopen.
|
||||
expect(s.windowPhase).toBe('PAYMENT');
|
||||
expect(batch.isScheduleFull).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('conclude: train FULL → window FULL + phase DONE + auto-finalize', async () => {
|
||||
batch.isScheduleFull.mockResolvedValue(true);
|
||||
const s = baseSchedule({ windowPhase: 'PAYMENT' });
|
||||
|
||||
Reference in New Issue
Block a user