优化
This commit is contained in:
@@ -5,10 +5,10 @@ import { verifyFleetTripCosts, expectedAllocations, TRIP_COST_EXPECTATIONS } fro
|
||||
const copy = value => value === undefined ? undefined : structuredClone(value)
|
||||
const prefix = 'platform:fleet:trip:'
|
||||
function fixture(fault, multiDestination = false) {
|
||||
const trip = { marker: 'fixture-vehicle', tripNo: 'FT-CURRENT' }, calls = [], rows = [], histories = new Map(), keys = new Map()
|
||||
const trip = { marker: 'fixture-vehicle', tripNo: 'FT-CURRENT', dispatchNo: 'DP-OWN' }, calls = [], rows = [], histories = new Map(), keys = new Map()
|
||||
const shares = [
|
||||
{ businessNo: 'DP-OWN', dispatchNo: 'DP-OWN', sourceType: 'OWN', palletSpaces: 2, warehousePalletIds: ['P1'] },
|
||||
{ businessNo: 'BK-EXTERNAL', dispatchNo: 'DP-EXTERNAL', sourceType: 'EXTERNAL', palletSpaces: 1, warehousePalletIds: ['P2'] },
|
||||
{ businessNo: 'BK-EXTERNAL', dispatchNo: 'DP-OWN', sourceType: 'EXTERNAL', palletSpaces: 1, warehousePalletIds: ['P2'] },
|
||||
]
|
||||
const inputs = { shares, listOnlyToken: 'offline-reader', deniedToken: 'offline-denied' }
|
||||
const depart = { recordVersion: 7, action: 'DEPART', snapshot: {
|
||||
@@ -17,8 +17,8 @@ function fixture(fault, multiDestination = false) {
|
||||
confirmedLoad: { manifestHash: 'original-manifest', pallets: [
|
||||
{ warehousePalletId: 'P1', palletSpaces: 2, deliveryIndex: 1 }, { warehousePalletId: 'P2', palletSpaces: 1, deliveryIndex: 1 }],
|
||||
cargo: [{ warehousePalletId: 'P1', dispatchNo: 'DP-OWN', customerId: 'C1', packages: 5, destinationKey: 'FBA:A' },
|
||||
{ warehousePalletId: 'P2', dispatchNo: 'DP-EXTERNAL', customerId: 'C2', packages: 9, destinationKey: 'FBA:A' }] },
|
||||
externalBookings: [{ bookingNo: 'BK-EXTERNAL', dispatchNo: 'DP-EXTERNAL', customerId: 'C2', status: 'BOUND',
|
||||
{ warehousePalletId: 'P2', dispatchNo: 'DP-OWN', customerId: 'C2', packages: 9, destinationKey: 'FBA:A' }] },
|
||||
externalBookings: [{ bookingNo: 'BK-EXTERNAL', dispatchNo: 'DP-OWN', customerId: 'C2', status: 'BOUND',
|
||||
receipt: { source: { receivedPackages: 9, pallets: [{ warehousePalletId: 'P2', packages: 9 }] } } }] } }
|
||||
const load = depart.snapshot.confirmedLoad
|
||||
if (multiDestination) {
|
||||
@@ -57,7 +57,7 @@ function fixture(fault, multiDestination = false) {
|
||||
allocations: fault === 'invented allocation' ? [{ businessNo: 'DP-OWN', amount: amount / 100 }] : [] }
|
||||
return { currency, directCost: amount / 100, ownCost: own / 100, externalCost: external / 100, allocations: [
|
||||
{ businessNo: 'DP-OWN', dispatchNo: 'DP-OWN', sourceType: 'OWN', palletSpaces: 2, amount: own / 100 },
|
||||
{ businessNo: 'BK-EXTERNAL', dispatchNo: 'DP-EXTERNAL', sourceType: fault === 'external counted own' ? 'OWN' : 'EXTERNAL',
|
||||
{ businessNo: 'BK-EXTERNAL', dispatchNo: 'DP-OWN', sourceType: fault === 'external counted own' ? 'OWN' : 'EXTERNAL',
|
||||
palletSpaces: 1, amount: (external + (fault === 'lost cent' ? 1 : 0)) / 100 }] }
|
||||
}) }
|
||||
}
|
||||
@@ -71,7 +71,8 @@ function fixture(fault, multiDestination = false) {
|
||||
}
|
||||
const context = { marker: 'CURRENT-RUN', token: 'offline-writer', createdResources: { fleetTrips: [trip],
|
||||
fleetAcceptance: { marker: 'CURRENT-RUN', tripNo: trip.tripNo,
|
||||
departure: { tripNo: trip.tripNo, status: 'IN_TRANSIT', departedAt: depart.snapshot.trip.departedAt } } },
|
||||
departure: { dispatchNo: trip.dispatchNo, status: 'ACTIVE', stage: 'DELIVERING', action: 'DEPART',
|
||||
result: { departedAt: depart.snapshot.trip.departedAt } } } },
|
||||
assert(_module, label, _response, condition) { assert.ok(condition, label) }, async checkpoint() {},
|
||||
async request(method, path, body, token) {
|
||||
calls.push({ method, path, body: copy(body), actor: token })
|
||||
@@ -178,6 +179,23 @@ test('missing current-run membership or permission session fails before HTTP', a
|
||||
}
|
||||
})
|
||||
|
||||
test('cost execution requires the current single-dispatch native departure, without a legacy Fleet result alias', async () => {
|
||||
for (const mutate of [
|
||||
f => { f.context.createdResources.fleetAcceptance.departure = { tripNo: f.trip.tripNo, status: 'IN_TRANSIT', departedAt: '2026-10-03T01:00:00Z' } },
|
||||
f => { f.context.createdResources.fleetAcceptance.departure.dispatchNo = 'OTHER' },
|
||||
f => { f.context.createdResources.fleetAcceptance.departure.stage = 'AFTER_LOADING' },
|
||||
f => { f.context.createdResources.fleetAcceptance.departure.result.departedAt = null },
|
||||
f => { f.inputs.shares[1].dispatchNo = 'SECOND-DISPATCH' },
|
||||
]) {
|
||||
const f = fixture(); mutate(f)
|
||||
await assert.rejects(verifyFleetTripCosts(f.context, 'fleet', f.trip, f.inputs))
|
||||
assert.equal(f.calls.length, 0)
|
||||
}
|
||||
const f = fixture()
|
||||
f.context.createdResources.fleetAcceptance.departure.result.departedAt = '2026-10-03T01:00:00'
|
||||
assert.equal((await verifyFleetTripCosts(f.context, 'fleet', f.trip, f.inputs)).status, 'VERIFIED')
|
||||
})
|
||||
|
||||
test('unknown HTTP outcome retains original key and does not retry or hide failure', async () => {
|
||||
const f = fixture(), original = f.context.request
|
||||
f.context.request = async (...args) => {
|
||||
|
||||
Reference in New Issue
Block a user