mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-28 23:00:57 +00:00
Add a minimal payment mock server for end-to-end testing
This commit is contained in:
@@ -290,6 +290,7 @@ export class ContractBookingService {
|
||||
isHazardous: this.resolveShipmentHandlingFlag(contract, dto, 'hazardousQuantity'),
|
||||
isReefer: this.resolveShipmentHandlingFlag(contract, dto, 'reeferQuantity'),
|
||||
cargoTotalWeightVgm: this.resolveBulkTons(dto),
|
||||
bulkTotalWeightTons: this.resolveBulkWeightTons(dto),
|
||||
firstMilePickupAddress: contract.firstMilePickupAddress ?? null,
|
||||
firstMilePickupLat: contract.firstMilePickupLat ?? null,
|
||||
firstMilePickupLng: contract.firstMilePickupLng ?? null,
|
||||
@@ -773,6 +774,7 @@ export class ContractBookingService {
|
||||
cargoTypeId: this.resolveCargoTypeId(contract, dto),
|
||||
cargoFreeText: dto.cargoFreeText?.trim() || null,
|
||||
cargoTotalWeightVgm: this.resolveBulkTons(dto),
|
||||
bulkTotalWeightTons: this.resolveBulkWeightTons(dto),
|
||||
equipmentReturn: this.resolveShipmentEquipmentReturn(contract, dto),
|
||||
// Completion is where the cargo — and therefore the price — is fixed, so
|
||||
// it is also where the billing currency is chosen. A bare instance was
|
||||
@@ -1253,6 +1255,7 @@ export class ContractBookingService {
|
||||
}
|
||||
|
||||
probe.cargoTotalWeightVgm = this.resolveBulkTons(dto);
|
||||
probe.bulkTotalWeightTons = this.resolveBulkWeightTons(dto);
|
||||
const cargoTypeId = this.resolveCargoTypeId(contract, dto);
|
||||
probe.cargoTypeId = cargoTypeId;
|
||||
if (cargoTypeId) {
|
||||
@@ -1297,11 +1300,7 @@ export class ContractBookingService {
|
||||
return;
|
||||
}
|
||||
|
||||
const requested =
|
||||
(dto.bulkLines ?? []).reduce(
|
||||
(sum, b) => sum + (b.cargoWeightTons ?? b.itemCount ?? 0),
|
||||
0,
|
||||
) || this.resolveBulkTons(dto) || 0;
|
||||
const requested = this.resolveBulkTons(dto);
|
||||
const remaining = outstanding.bulk?.outstanding ?? 0;
|
||||
// 0.001 t tolerance absorbs the 3-decimal rounding applied to split weights.
|
||||
if (Math.abs(requested - remaining) > 0.001) {
|
||||
@@ -1344,8 +1343,10 @@ export class ContractBookingService {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// PER_ITEM contracts are capped in items, so the item count is the
|
||||
// consumption figure — tonnage is only wagon-sizing data.
|
||||
const requested =
|
||||
(lines.bulk?.cargoWeightTons ?? lines.bulk?.itemCount ?? 0) || 0;
|
||||
Number(lines.bulk?.itemCount ?? lines.bulk?.cargoWeightTons ?? 0) || 0;
|
||||
const cap = capacity.find((c) => c.cap != null);
|
||||
if (cap && cap.remaining != null && requested > cap.remaining) {
|
||||
throw new BadRequestException(
|
||||
@@ -1373,11 +1374,7 @@ export class ContractBookingService {
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const requested =
|
||||
(dto.bulkLines ?? []).reduce(
|
||||
(sum, b) => sum + (b.cargoWeightTons ?? b.itemCount ?? 0),
|
||||
0,
|
||||
) || this.resolveBulkTons(dto) || 0;
|
||||
const requested = this.resolveBulkTons(dto);
|
||||
const cap = capacity.find((c) => c.cap != null);
|
||||
if (cap && cap.remaining != null && requested > cap.remaining) {
|
||||
throw new BadRequestException(
|
||||
@@ -1641,11 +1638,27 @@ export class ContractBookingService {
|
||||
private resolveBulkTons(dto: CreateBookingUnderContractDto): number {
|
||||
if (!dto.bulkLines?.length) return 0;
|
||||
return dto.bulkLines.reduce(
|
||||
(sum, l) => sum + Number(l.cargoWeightTons ?? l.itemCount ?? 0),
|
||||
(sum, l) => sum + Number(l.itemCount ?? l.cargoWeightTons ?? 0),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Real tonnage of a PER_ITEM (break-bulk) booking, kept alongside the item
|
||||
* count `cargoTotalWeightVgm` holds. Both are needed: the item count prices
|
||||
* the booking, the tonnage sizes the wagons (`bulkItemWagonsRequired` derives
|
||||
* per-item weight from tonnage ÷ items). Null for PER_TON bulk, where
|
||||
* `cargoTotalWeightVgm` already IS the tonnage.
|
||||
*/
|
||||
private resolveBulkWeightTons(
|
||||
dto: CreateBookingUnderContractDto,
|
||||
): number | null {
|
||||
const lines = dto.bulkLines ?? [];
|
||||
if (!lines.some((l) => Number(l.itemCount) > 0)) return null;
|
||||
const tons = lines.reduce((sum, l) => sum + Number(l.cargoWeightTons ?? 0), 0);
|
||||
return tons > 0 ? tons : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Per-line handling counts. Each physical container carries its own hazardous
|
||||
* / reefer / return switch (entered next to its VGM), so the count is however
|
||||
@@ -1961,6 +1974,7 @@ export class ContractBookingService {
|
||||
originYardId: route?.originYardId ?? null,
|
||||
destinationYardId: route?.destinationYardId ?? null,
|
||||
cargoTotalWeightVgm: this.resolveBulkTons(dto),
|
||||
bulkTotalWeightTons: this.resolveBulkWeightTons(dto),
|
||||
firstMilePickupAddress: contract.firstMilePickupAddress ?? null,
|
||||
lastMileDeliveryAddress: contract.lastMileDeliveryAddress ?? null,
|
||||
bookingContainers: resolved.map(({ line, ct, totalVgmTons }) =>
|
||||
|
||||
Reference in New Issue
Block a user