mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-09-07 22:25:42 +00:00
enhance shipment form and booking process
This commit is contained in:
@@ -1187,6 +1187,7 @@ describe('BookingBatchService — built-train wagon capacity', () => {
|
||||
reserved: Booking[];
|
||||
maxWagons?: number;
|
||||
routeStops?: string[];
|
||||
yardCountries?: Record<string, string>;
|
||||
}) => {
|
||||
const schedule = {
|
||||
id: scheduleId,
|
||||
@@ -1218,10 +1219,21 @@ describe('BookingBatchService — built-train wagon capacity', () => {
|
||||
find: jest.fn().mockResolvedValue([]),
|
||||
update: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
const yardRepo = {
|
||||
find: jest
|
||||
.fn()
|
||||
.mockResolvedValue(
|
||||
Object.entries(opts.yardCountries ?? {}).map(([id, country]) => ({
|
||||
id,
|
||||
country,
|
||||
})),
|
||||
),
|
||||
};
|
||||
const dataSource = {
|
||||
getRepository: jest.fn((entity: { name?: string }) => {
|
||||
if (entity?.name === 'Wagon') return wagonRepo;
|
||||
if (entity?.name === 'RouteMilestone') return milestoneRepo;
|
||||
if (entity?.name === 'Yard') return yardRepo;
|
||||
return genericRepo;
|
||||
}),
|
||||
transaction: jest.fn(),
|
||||
@@ -1264,11 +1276,11 @@ describe('BookingBatchService — built-train wagon capacity', () => {
|
||||
await expect(service.isScheduleFull(scheduleId)).resolves.toBe(false);
|
||||
});
|
||||
|
||||
it('is FULL when sub-leg bookings hold every physical wagon of a milestone route', async () => {
|
||||
// Regression: 50 wagons sold Negad→Mojo on a Doraleh→…→Dire Dawa corridor
|
||||
// left the pass-through edges reading "free" in the per-edge budget, so the
|
||||
// full train's window cycled OPEN forever and the day pool never expired.
|
||||
// A wagon is committed for the whole trip — leg-free edges are not capacity.
|
||||
it('is NOT full when only a middle leg is sold and other edges run free (domestic route)', async () => {
|
||||
// Leg-aware allocation (planWagonsWithStock legs) made mid-leg wagons real
|
||||
// capacity on the edges they don't ride: a domestic corridor with cargo
|
||||
// only on m1→m2 still boards bookings on the free first/last edges, so the
|
||||
// window must stay open for them.
|
||||
const { service } = buildService({
|
||||
physicalWagons: 2,
|
||||
routeStops: ['yard-a', 'yard-m1', 'yard-m2', 'yard-b'],
|
||||
@@ -1277,9 +1289,48 @@ describe('BookingBatchService — built-train wagon capacity', () => {
|
||||
reservedBooking('b2', { origin: 'yard-m1', dest: 'yard-m2' }),
|
||||
],
|
||||
});
|
||||
await expect(service.isScheduleFull(scheduleId)).resolves.toBe(false);
|
||||
});
|
||||
|
||||
it('is FULL for the trade direction once the border edge is sold out, even with home legs free', async () => {
|
||||
// Export b→c holds every wagon of the border crossing: no further export
|
||||
// can board anywhere (they all must ride that edge), so the window closes —
|
||||
// while intercity keeps booking the free a→b leg through the per-leg budget.
|
||||
const { service } = buildService({
|
||||
physicalWagons: 2,
|
||||
routeStops: ['yard-a', 'yard-b', 'yard-dj'],
|
||||
yardCountries: {
|
||||
'yard-a': 'ETHIOPIA',
|
||||
'yard-b': 'ETHIOPIA',
|
||||
'yard-dj': 'DJIBOUTI',
|
||||
},
|
||||
reserved: [
|
||||
reservedBooking('b1', { origin: 'yard-b', dest: 'yard-dj' }),
|
||||
reservedBooking('b2', { origin: 'yard-b', dest: 'yard-dj' }),
|
||||
],
|
||||
});
|
||||
await expect(service.isScheduleFull(scheduleId)).resolves.toBe(true);
|
||||
});
|
||||
|
||||
it('is NOT full while the border edge still has room, even with a home leg sold out', async () => {
|
||||
// Intercity rode a→b on both wagons; the border edge b→dj is still free,
|
||||
// so exports can still board — the window stays open.
|
||||
const { service } = buildService({
|
||||
physicalWagons: 2,
|
||||
routeStops: ['yard-a', 'yard-b', 'yard-dj'],
|
||||
yardCountries: {
|
||||
'yard-a': 'ETHIOPIA',
|
||||
'yard-b': 'ETHIOPIA',
|
||||
'yard-dj': 'DJIBOUTI',
|
||||
},
|
||||
reserved: [
|
||||
reservedBooking('b1', { origin: 'yard-a', dest: 'yard-b' }),
|
||||
reservedBooking('b2', { origin: 'yard-a', dest: 'yard-b' }),
|
||||
],
|
||||
});
|
||||
await expect(service.isScheduleFull(scheduleId)).resolves.toBe(false);
|
||||
});
|
||||
|
||||
it('reports over-allocation when the consist is trimmed below committed bookings', async () => {
|
||||
const { service } = buildService({
|
||||
physicalWagons: 1,
|
||||
|
||||
Reference in New Issue
Block a user