Files
baiyue-firstleg/scripts/admin-test-env-modules/inbound-measurement-box-code-contract.test.mjs
T

87 lines
5.1 KiB
JavaScript

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
const source = readFileSync(new URL('inbound-measurement.mjs', import.meta.url), 'utf8')
const read = (relativeUrl) => readFileSync(new URL(relativeUrl, import.meta.url), 'utf8')
const labelTests = read('../../firstleg/src/test/java/com/baiyue/firstleg/service/InboundCartonLabelServiceTest.java')
const measurementTests = read('../../firstleg/src/test/java/com/baiyue/firstleg/service/InboundMeasurementServiceTest.java')
const cartonTests = read('../../firstleg/src/test/java/com/baiyue/firstleg/service/CartonMeasurementServiceTest.java')
const reviewTests = read('../../firstleg/src/test/java/com/baiyue/firstleg/service/MeasurementReviewServiceTest.java')
test('measurement acceptance scans the stable box code frozen by first print', () => {
assert.match(source, /const boxCode = `\$\{inboundCode\}#\$\{originalPackageCount\}-1`/)
assert.doesNotMatch(source, /#V\d+#/)
})
test('reprint and Mojia scan share the same frozen box code variable', () => {
assert.match(source, /重复整单打印复用已冻结箱码映射[\s\S]*boxCode=\$\{boxCode\}/)
assert.match(source, /const firstScanResponse = await multipartRequest[\s\S]*boxCode, \.\.\.firstDimensions/)
})
test('measurement submission confirms weight evidence before submit', () => {
assert.match(source, /files\/measurements\/\$\{tenantId\}\/\$\{inboundId\}/)
assert.match(source, /\/weight-results\?\$\{query\(tenantId\)\}/)
assert.match(source, /\/weight-results\/\$\{created\.id\}\/confirm\?\$\{query\(tenantId\)\}/)
assert.match(source, /createConfirmedWeightEvidence[\s\S]*\/measurement\/submit/)
})
test('measurement fixture derives pallet resources from confirmed image count', () => {
assert.match(source, /waitSplitVariant\?\.palletCount \|\| 1/)
assert.match(source, /palletIds: warehouseResourcesReady\.palletIds/)
assert.match(source, /confirmedRows\.length === palletIds\.length/)
assert.doesNotMatch(source, /Math\.ceil\(Number\(totalVolumeCbm\)/)
assert.doesNotMatch(source, /Math\.ceil\(totalVolume \/ DEFAULT_PALLET_CAPACITY_CBM\)/)
})
test('volume ceiling removes binary floating point noise before scaling', () => {
assert.match(source, /Number\.EPSILON \* Math\.max\(1, Math\.abs\(value\)\) \* 4/)
})
test('demo package freezes repeated label printing and Mojia dimension replacement', () => {
assert.match(labelTests, /repeatedAndPartialPrintsReadFrozenMappingWithoutReallocation/)
assert.match(labelTests, /changedCargoKeepsTheFirstFrozenBoxCodes/)
assert.match(cartonTests, /repeatedScanReplacesDeviceValuesButPreservesManualCountAndOldImageIsDeleted/)
assert.match(source, /增量 fixture 形成动态真实独立货物测量明细/)
})
test('demo package covers OCR failure, manual confirmation, aggregation and stale versions', () => {
assert.match(source, /OCR无有效重量时转人工确认/)
assert.match(source, /称重旧版本确认被拒绝且不覆盖已确认结果/)
assert.match(source, /图片张数决定托数且净重汇总已落地/)
assert.match(measurementTests, /ocrFailureCreatesManualWeightThatCanBeAdjustedAndConfirmed/)
assert.match(measurementTests, /confirmingFifthPalletSeparatelyAggregatesGrossAndCargoNetWeight/)
assert.match(measurementTests, /confirmingWithStaleVersionDoesNotTreatRequestAsIdempotent/)
})
test('demo package keeps pallet pages bounded and historical snapshots read-only', () => {
assert.match(source, /weight-pallet-options[^\n]+page=1&size=20&keyword=/)
assert.match(source, /records\.length <= 20/)
assert.match(measurementTests, /detailUsesStoredPalletSnapshotAfterCandidateBecomesUnavailable/)
})
test('opt-in HTTP acceptance verifies whole-ticket slot identity and delete-to-empty semantics', () => {
assert.match(source, /verifyPalletLocationGuide/)
assert.match(source, /expectedWeightResultIds\.every/)
assert.match(source, /asId\(row\.reservationId\) === asId\(slot\.reservationId\)/)
assert.match(source, /\['RESERVED_EMPTY', 'BOUND', 'TRANSFERRED', 'RELEASED'\]/)
assert.match(source, /deleteSucceeded/)
assert.match(source, /retainedSlot\?\.slotStatus === 'RESERVED_EMPTY'/)
assert.match(source, /recreateConfirmedWeightEvidence/)
assert.match(source, /reboundSlot\?\.slotStatus === 'BOUND'/)
assert.match(source, /replacementWeightResultId/)
assert.match(source, /不批量停用普通库位制造容量不足/)
})
test('approval freezes measurement and requires quantity weight and volume conservation', () => {
assert.match(source, /审核进入WAIT_SPLIT后箱码尺寸与图片快照不可再覆盖/)
assert.match(measurementTests, /approvedMeasurementCannotBeResubmittedOrMutateFrozenTotals/)
assert.match(reviewTests, /shouldApproveMultipleCargoLinesOnlyWhenAllFrozenTotalsMatch/)
assert.match(reviewTests, /shouldRejectApprovalWhenVolumeSnapshotDoesNotConserve/)
assert.match(source, /actualPackageCount[^\n]+originalPackageCount/)
assert.match(source, /actualGrossWeightKg[^\n]+weightEvidence\.grossWeightKg/)
assert.match(source, /actualNetWeightKg[^\n]+weightEvidence\.netWeightKg/)
assert.match(source, /actualVolumeCbm[^\n]+totalVolume/)
assert.match(source, /volumeWeightKg[^\n]+volumeWeight/)
})