mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-30 13:28:11 +00:00
chore: update package overrides in pnpm-workspace.yaml for dependencies
This commit is contained in:
@@ -1646,4 +1646,92 @@ describe('TrainSchedulingService', () => {
|
||||
).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('maintenanceReschedule — window reopens when it had already finished', () => {
|
||||
const { TrainSchedule } = jest.requireActual(
|
||||
'../../train-schedules/entities/train-schedule.entity',
|
||||
);
|
||||
|
||||
const doneExportSchedule = (extra: Record<string, unknown> = {}) => ({
|
||||
id: 'sch-done',
|
||||
status: 'SCHEDULED',
|
||||
direction: 'EXPORT',
|
||||
windowPhase: 'DONE',
|
||||
bookingWindowStatus: 'CLOSED',
|
||||
scheduledDepartureDate: new Date('2027-06-20T05:00:00.000Z'),
|
||||
scheduledArrivalDate: null,
|
||||
originStationId: 'yard-origin',
|
||||
destinationStationId: 'yard-destination',
|
||||
scheduleBookings: [],
|
||||
// Frozen rule snapshot: desk 8–17 EAT, 24h lead, close 120min before departure.
|
||||
ruleWindowOpenHour: 8,
|
||||
ruleWindowCloseHour: 17,
|
||||
ruleExportBookingLeadHours: 24,
|
||||
ruleExportCloseOffsetMinutes: 120,
|
||||
...extra,
|
||||
});
|
||||
|
||||
let scheduleUpdate: jest.Mock;
|
||||
|
||||
beforeEach(() => {
|
||||
scheduleUpdate = jest.fn().mockResolvedValue({ affected: 1 });
|
||||
dataSource.getRepository.mockImplementation((entity: unknown) => {
|
||||
if (entity === TrainSchedulingGlobalRules) {
|
||||
return { find: jest.fn().mockResolvedValue([]) };
|
||||
}
|
||||
if (entity === TrainSchedule) {
|
||||
return { update: scheduleUpdate, find: jest.fn().mockResolvedValue([]) };
|
||||
}
|
||||
return {
|
||||
find: jest.fn().mockResolvedValue([]),
|
||||
findOne: jest.fn().mockResolvedValue(null),
|
||||
update: jest.fn(),
|
||||
};
|
||||
});
|
||||
trainSchedulesRepository.findById.mockResolvedValue(null);
|
||||
});
|
||||
|
||||
it('reopens a DONE export window against the new departure', async () => {
|
||||
trainSchedulesRepository.findByIdWithFullGraph.mockResolvedValue(
|
||||
doneExportSchedule(),
|
||||
);
|
||||
|
||||
// New departure 12:00 EAT → window opens 24h earlier (12:00 EAT, inside
|
||||
// the desk) and closes at departure − 120min = 10:00 EAT.
|
||||
await service.maintenanceReschedule('sch-done', {
|
||||
newDepartureDate: '2027-06-20T09:00:00.000Z',
|
||||
} as never);
|
||||
|
||||
expect(scheduleUpdate).toHaveBeenCalledWith(
|
||||
'sch-done',
|
||||
expect.objectContaining({
|
||||
scheduledDepartureDate: new Date('2027-06-20T09:00:00.000Z'),
|
||||
windowPhase: 'PRE_WINDOW',
|
||||
bookingWindowStatus: 'CLOSED',
|
||||
windowOpensAt: new Date('2027-06-19T09:00:00.000Z'),
|
||||
windowClosesAt: new Date('2027-06-20T07:00:00.000Z'),
|
||||
docReviewCompletedAt: null,
|
||||
docReviewEndsAt: null,
|
||||
paymentPhaseEndsAt: null,
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps a FULL train closed — nothing left to sell', async () => {
|
||||
trainSchedulesRepository.findByIdWithFullGraph.mockResolvedValue(
|
||||
doneExportSchedule({ bookingWindowStatus: 'FULL' }),
|
||||
);
|
||||
|
||||
await service.maintenanceReschedule('sch-done', {
|
||||
newDepartureDate: '2027-06-20T09:00:00.000Z',
|
||||
} as never);
|
||||
|
||||
const written = scheduleUpdate.mock.calls[0][1];
|
||||
expect(written.scheduledDepartureDate).toEqual(
|
||||
new Date('2027-06-20T09:00:00.000Z'),
|
||||
);
|
||||
expect(written.windowPhase).toBeUndefined();
|
||||
expect(written.windowOpensAt).toBeUndefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user