Enhance wagon capacity handling and validation in booking service

- Added default capacities for container and bulk wagons.
- Updated wagonsFor method to consider weight and length for wagon calculations.
- Improved handling of overweight bookings with appropriate warnings.
- Adjusted tests to reflect changes in wagon capacity and validation logic.
This commit is contained in:
Marshal
2026-07-09 13:10:32 +00:00
parent db35b90b45
commit eb819d66a1
6 changed files with 155 additions and 26 deletions

View File

@@ -72,7 +72,7 @@ const makeBooking = (
wagonsRequired,
vgmPerUnitTons: weight / quantity,
isOverweight: false,
containerType: { code: containerCode, label: containerCode },
containerType: { code: containerCode, label: containerCode, wagonTypeId: nw5.id },
},
],
...extra,
@@ -282,7 +282,7 @@ describe('TrainSchedulingService', () => {
expect(result.warnings[0]).toContain('soft hold window');
});
it('flags the overweight booking as invalid', async () => {
it('warns on the overweight booking but still allows scheduling', async () => {
const bookings = [
makeBooking('b6', 'BKG-CONT-006', 3600, 80, '40FT', 80, undefined, undefined, undefined, {
bookingContainers: [
@@ -293,7 +293,7 @@ describe('TrainSchedulingService', () => {
wagonsRequired: 80,
vgmPerUnitTons: 45,
isOverweight: true,
containerType: { code: '40FT', label: '40FT' },
containerType: { code: '40FT', label: '40FT', wagonTypeId: nw5.id },
},
],
}),
@@ -311,8 +311,8 @@ describe('TrainSchedulingService', () => {
destinationStationId: 'yard-destination',
});
expect(result.valid).toBe(false);
expect(result.violations.some((v) => v.includes('overweight'))).toBe(true);
expect(result.violations.some((v) => v.includes('overweight'))).toBe(false);
expect(result.warnings.some((w) => w.includes('overweight'))).toBe(true);
});
it('allows preview when bookings are already on the target schedule', async () => {