mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 03:40:56 +00:00
fix issue
This commit is contained in:
@@ -315,3 +315,131 @@ describe('planWagonsWithStock — leg-aware stock (intercity ride-along)', () =>
|
||||
expect(result.plan).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('planWagonsWithStock — break-bulk (PER_ITEM) item-aware packing', () => {
|
||||
const pw2: WagonType = {
|
||||
id: 'wt-pw2',
|
||||
code: 'PW2',
|
||||
capacityTons: 70,
|
||||
lengthMeters: 17,
|
||||
supportedLoadTypes: ['BULK'],
|
||||
isActive: true,
|
||||
supportsContainer: false,
|
||||
} as WagonType;
|
||||
const nw5: WagonType = {
|
||||
id: 'wt-nw5',
|
||||
code: 'NW5',
|
||||
capacityTons: 70,
|
||||
lengthMeters: 14,
|
||||
supportedLoadTypes: ['BULK'],
|
||||
isActive: true,
|
||||
supportsContainer: false,
|
||||
} as WagonType;
|
||||
|
||||
// 20 machinery items, 100T total (5T each). NW5 fits 4/wagon, PW2 fits 3.
|
||||
const machineryBooking = (): Booking =>
|
||||
({
|
||||
id: 'BULK-ITEMS',
|
||||
reference: 'BULK-ITEMS',
|
||||
freightType: 'BULK',
|
||||
cargoTypeId: 'ct-machinery',
|
||||
cargoTotalWeightVgm: 20,
|
||||
bulkTotalWeightTons: 100,
|
||||
cargoType: {
|
||||
id: 'ct-machinery',
|
||||
cargoTypeName: 'Machinery',
|
||||
itemsPerWagonMap: { 'wt-nw5': 4, 'wt-pw2': 3 },
|
||||
wagonTypes: [pw2, nw5],
|
||||
},
|
||||
}) as unknown as Booking;
|
||||
|
||||
const allowed = {
|
||||
byContainerTypeId: new Map<string, WagonType[]>(),
|
||||
byCargoTypeId: new Map([['ct-machinery', [pw2, nw5]]]),
|
||||
};
|
||||
|
||||
it('packs whole items per wagon by the items-fit map, not raw tonnage', () => {
|
||||
const result = planWagonsWithStock({
|
||||
bookings: [machineryBooking()],
|
||||
allowed,
|
||||
stock: {
|
||||
mode: 'YARD',
|
||||
remainingByTypeId: new Map([
|
||||
[pw2.id, 50],
|
||||
[nw5.id, 50],
|
||||
]),
|
||||
codesByTypeId: new Map([
|
||||
[pw2.id, pw2.code],
|
||||
[nw5.id, nw5.code],
|
||||
]),
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.deferred).toHaveLength(0);
|
||||
// Best fit: NW5 at 4 items/wagon → ceil(20/4) = 5 wagons, 20T each.
|
||||
expect(result.plan).toHaveLength(5);
|
||||
expect(result.plan.every((s) => s.wagonTypeCode === 'NW5')).toBe(true);
|
||||
expect(result.plan.map((s) => s.assignedWeightTons)).toEqual([20, 20, 20, 20, 20]);
|
||||
});
|
||||
|
||||
it('weight cap binds before items-fit when items are heavy', () => {
|
||||
// 14 items of 10T on 70T wagons with a 100-item floor fit → 7 items/wagon.
|
||||
const heavy = {
|
||||
...machineryBooking(),
|
||||
cargoTotalWeightVgm: 14,
|
||||
bulkTotalWeightTons: 140,
|
||||
cargoType: {
|
||||
id: 'ct-machinery',
|
||||
cargoTypeName: 'Machinery',
|
||||
itemsPerWagonMap: { 'wt-nw5': 100, 'wt-pw2': 100 },
|
||||
wagonTypes: [pw2, nw5],
|
||||
},
|
||||
} as unknown as Booking;
|
||||
const result = planWagonsWithStock({
|
||||
bookings: [heavy],
|
||||
allowed,
|
||||
stock: {
|
||||
mode: 'YARD',
|
||||
remainingByTypeId: new Map([
|
||||
[pw2.id, 50],
|
||||
[nw5.id, 50],
|
||||
]),
|
||||
codesByTypeId: new Map([
|
||||
[pw2.id, pw2.code],
|
||||
[nw5.id, nw5.code],
|
||||
]),
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.deferred).toHaveLength(0);
|
||||
expect(result.plan).toHaveLength(2);
|
||||
expect(result.plan.map((s) => s.assignedWeightTons)).toEqual([70, 70]);
|
||||
});
|
||||
|
||||
it('PER_TON bulk (no bulkTotalWeightTons) still packs by weight', () => {
|
||||
const loose = {
|
||||
...machineryBooking(),
|
||||
cargoTotalWeightVgm: 100,
|
||||
bulkTotalWeightTons: null,
|
||||
} as unknown as Booking;
|
||||
const result = planWagonsWithStock({
|
||||
bookings: [loose],
|
||||
allowed,
|
||||
stock: {
|
||||
mode: 'YARD',
|
||||
remainingByTypeId: new Map([
|
||||
[pw2.id, 50],
|
||||
[nw5.id, 50],
|
||||
]),
|
||||
codesByTypeId: new Map([
|
||||
[pw2.id, pw2.code],
|
||||
[nw5.id, nw5.code],
|
||||
]),
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.deferred).toHaveLength(0);
|
||||
expect(result.plan).toHaveLength(2);
|
||||
expect(result.plan.map((s) => s.assignedWeightTons)).toEqual([70, 30]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user