test(admin): verify weighted Mojia measurement volume

This commit is contained in:
2026-08-08 13:08:24 +08:00
parent 44bae99999
commit dca8c05d33
@@ -13,6 +13,10 @@ function ceiling(value, scale) {
const factor = 10 ** scale
return Math.ceil((value - Number.EPSILON) * factor) / factor
}
function halfUp(value, scale) {
const factor = 10 ** scale
return Math.round((value + Number.EPSILON) * factor) / factor
}
function query(tenantId) { return `tenantId=${encodeURIComponent(tenantId)}` }
function validPdf(response) {
return response.http === 200 && response.contentType.toLowerCase().includes('pdf')
@@ -230,18 +234,24 @@ export async function run(context) {
const measuredResponse = await context.request('GET', measurementPath)
const measured = context.apiSuccess(MODULE, '回查覆盖后的尺寸与体积结果', measuredResponse, '', OPTIONS)
const measuredItem = measured?.items?.find((item) => asId(item.id) === asId(firstScan.itemId))
const unitVolume = ceiling(replacement.length * replacement.width * replacement.height / 1_000_000, 4)
const totalVolume = ceiling(unitVolume * originalPackageCount, 4)
// The verified customer rule maps this scan to EXTRA_LARGE 60x50x50cm and adds 2cm per edge.
const weightedOuter = { length: 64, width: 54, height: 54 }
const unitVolume = halfUp(
weightedOuter.length * weightedOuter.width * weightedOuter.height / 1_000_000, 3)
const totalVolume = unitVolume * originalPackageCount
const volumeWeight = ceiling(totalVolume * 167, 3)
const girth = ceiling(replacement.length + 2 * (replacement.width + replacement.height), 3)
context.assert(MODULE, '覆盖尺寸、箱数和服务端体积公式正确', measuredResponse,
measuredItem && closeTo(measuredItem.lengthCm, replacement.length)
&& closeTo(measuredItem.widthCm, replacement.width) && closeTo(measuredItem.heightCm, replacement.height)
&& Number(measuredItem.confirmedPackageCount) === originalPackageCount
&& closeTo(measuredItem.outerLengthCm, weightedOuter.length)
&& closeTo(measuredItem.outerWidthCm, weightedOuter.width)
&& closeTo(measuredItem.outerHeightCm, weightedOuter.height)
&& closeTo(measuredItem.unitVolumeCbm, unitVolume) && closeTo(measuredItem.totalVolumeCbm, totalVolume)
&& closeTo(measuredItem.volumeWeightKg, volumeWeight) && closeTo(measuredItem.girthCm, girth)
&& closeTo(measured.actualVolumeCbm, totalVolume) && closeTo(measured.volumeWeightKg, volumeWeight),
`unitVolume=${unitVolume}, totalVolume=${totalVolume}, volumeWeight=${volumeWeight}, girth=${girth}`, OPTIONS)
`weightedOuter=${weightedOuter.length}x${weightedOuter.width}x${weightedOuter.height}, unitVolume=${unitVolume}, totalVolume=${totalVolume}, volumeWeight=${volumeWeight}, girth=${girth}`, OPTIONS)
let inboundDetailId = measuredItem?.inboundDetailId
if (!inboundDetailId) {