mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
feat: full wagon cancel, leg board, wagon dates
feat(freight): editable train leg times, SL invoice payer
This commit is contained in:
@@ -94,6 +94,7 @@ describe('TrainSchedulingService', () => {
|
||||
let wagonBookingAllocationsRepository: Record<string, jest.Mock>;
|
||||
let wagonAllocationContainerItemsRepository: Record<string, jest.Mock>;
|
||||
let wagonAllocationBulkLoadsRepository: Record<string, jest.Mock>;
|
||||
let trainCheckpointEventsRepository: Record<string, jest.Mock>;
|
||||
|
||||
beforeEach(() => {
|
||||
// findGroupSiblings runs a query builder off dataSource.manager; default it
|
||||
@@ -127,6 +128,7 @@ describe('TrainSchedulingService', () => {
|
||||
findByIdWithFullGraph: jest.fn(),
|
||||
findAll: jest.fn(),
|
||||
updateStatus: jest.fn(),
|
||||
update: jest.fn(),
|
||||
maxReferenceSequence: jest.fn().mockResolvedValue(0),
|
||||
};
|
||||
trainScheduleBookingsRepository = {
|
||||
@@ -150,7 +152,7 @@ describe('TrainSchedulingService', () => {
|
||||
findAll: jest.fn().mockResolvedValue([]),
|
||||
};
|
||||
|
||||
const trainCheckpointEventsRepository = {
|
||||
trainCheckpointEventsRepository = {
|
||||
findBySchedule: jest.fn().mockResolvedValue([]),
|
||||
findAll: jest.fn().mockResolvedValue([]),
|
||||
create: jest.fn(),
|
||||
@@ -1638,6 +1640,61 @@ describe('TrainSchedulingService', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('updateCheckpoint — leg time correction', () => {
|
||||
const t = (h: number) => new Date(Date.UTC(2026, 0, 1, h));
|
||||
const schedule = {
|
||||
id: 'sch-track',
|
||||
status: 'ARRIVED',
|
||||
routeId: null,
|
||||
originStationId: 'y0',
|
||||
destinationStationId: 'y1',
|
||||
actualDepartureAt: t(8),
|
||||
};
|
||||
const events = () => [
|
||||
{ id: 'e0', yardId: 'y0', sequenceNo: 0, kind: 'DEPARTED', occurredAt: t(8) },
|
||||
{ id: 'e1', yardId: 'y1', sequenceNo: 1, kind: 'ARRIVED', occurredAt: t(12) },
|
||||
];
|
||||
|
||||
beforeEach(() => {
|
||||
trainSchedulesRepository.findByIdWithFullGraph.mockResolvedValue(schedule);
|
||||
trainCheckpointEventsRepository.findBySchedule.mockImplementation(async () => events());
|
||||
});
|
||||
|
||||
it('rejects a leg time earlier than the previous leg', async () => {
|
||||
await expect(
|
||||
service.updateCheckpoint('sch-track', 1, { occurredAt: t(7).toISOString() }),
|
||||
).rejects.toThrow(/cannot be earlier than/);
|
||||
expect(trainCheckpointEventsRepository.update).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('rejects a leg time later than the next leg', async () => {
|
||||
await expect(
|
||||
service.updateCheckpoint('sch-track', 0, { occurredAt: t(13).toISOString() }),
|
||||
).rejects.toThrow(/cannot be later than/);
|
||||
});
|
||||
|
||||
it('rejects a future time', async () => {
|
||||
const future = new Date(Date.now() + 3_600_000).toISOString();
|
||||
await expect(
|
||||
service.updateCheckpoint('sch-track', 1, { occurredAt: future }),
|
||||
).rejects.toThrow(/future/);
|
||||
});
|
||||
|
||||
it('accepts an in-order past time and re-stamps arrival for the final leg', async () => {
|
||||
await service.updateCheckpoint('sch-track', 1, {
|
||||
occurredAt: t(11).toISOString(),
|
||||
note: 'late log',
|
||||
});
|
||||
expect(trainCheckpointEventsRepository.update).toHaveBeenCalledWith('e1', {
|
||||
occurredAt: t(11),
|
||||
note: 'late log',
|
||||
});
|
||||
expect(trainSchedulesRepository.update).toHaveBeenCalledWith('sch-track', {
|
||||
actualArrivalAt: t(11),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('effectiveWagonsRequired', () => {
|
||||
const effective = (booking: unknown): number =>
|
||||
(service as never as { effectiveWagonsRequired(b: unknown): number })
|
||||
|
||||
Reference in New Issue
Block a user