import assert from 'node:assert/strict' import { readFileSync } from 'node:fs' import test from 'node:test' import { reusablePallets } from './inbound-measurement.mjs' test('固定托盘缺失停止造数,不查询其他托盘;补齐后同仓可重新验证', async () => { const requests = [], gaps = [], checks = [] let complete = false const context = { context: {}, async request(method, path) { requests.push({ method, path }) const query = new URL(path, 'http://offline').searchParams const code = query.get('palletCode') assert.ok(code, '固定模式禁止用无编号列表替换缺失资源') return { records: complete ? [{ id: code === 'TP-001' ? '1' : '2', palletCode: code, warehouseId: 'offline-fixed-pallet' }] : [] } }, apiSuccess(_module, _name, response) { return response }, assert(_module, name, _response, passed) { checks.push({ name, passed }) }, addCoverageGap(...args) { gaps.push(args) }, } assert.equal(await reusablePallets(context, 'offline-fixed-pallet'), null) assert.equal(requests.length, 2) assert.ok(checks.some(row => !row.passed)) assert.equal(gaps[0].at(-1).blocking, true) complete = true assert.deepEqual(await reusablePallets(context, 'offline-fixed-pallet'), [ { id: '1', code: 'TP-001' }, { id: '2', code: 'YW-TP-002' }, ]) assert.equal(requests.length, 4, '失败不得缓存为成功') }) test('指定托盘池仅剩一只时可复用,不要求同时存在两只', async () => { const context = { context: {}, async request(_method, path) { const code = new URL(path, 'http://offline').searchParams.get('palletCode') assert.ok(['TP-001', 'YW-TP-002'].includes(code)) return { records: code === 'YW-TP-002' ? [{ id: '2', palletCode: code, warehouseId: 'offline-single-pallet' }] : [] } }, apiSuccess(_module, _name, response) { return response }, assert(_module, _name, _response, passed) { assert.equal(passed, true) }, } assert.deepEqual(await reusablePallets(context, 'offline-single-pallet'), [{ id: '2', code: 'YW-TP-002' }]) }) const acceptance = readFileSync(new URL('../admin-test-env-acceptance.mjs', import.meta.url), 'utf8') const orders = readFileSync(new URL('./orders.mjs', import.meta.url), 'utf8') const measurement = readFileSync(new URL('./inbound-measurement.mjs', import.meta.url), 'utf8') const runner = readFileSync(new URL('../it-test-wait-split-bulk.mjs', import.meta.url), 'utf8') const warehouseLocationResources = readFileSync(new URL('../../warehouse/src/main/java/com/baiyue/warehouse/service/LocationResourceService.java', import.meta.url), 'utf8') test('Admin 通用单票支持到1000箱且八千票专项入口限制为300箱', () => { assert.match(acceptance, /--wait-split-package-count /) assert.match(acceptance, /wait-split-package-count必须是1-1000的整数或0/) assert.match(acceptance, /packageCounts\.push\(remaining\)/) assert.match(acceptance, /Math\.ceil\(totalPackageCount \/ 30\)/) assert.match(orders, /packageCounts\[index\] \|\| packageCountPerSku/) assert.match(measurement, /detailPackageCounts\.reduce\(\(sum, count\) => sum \+ count, 0\)/) assert.match(measurement, /detailPackageCounts\.slice\(0, detailIndex\)/) assert.match(runner, /boxMax > 300/) }) test('随机线路只固定义乌仓并从客户真实可计价候选选择', () => { assert.match(acceptance, /route-mode /) assert.match(acceptance, /random线路必须固定起运仓名称/) assert.match(orders, /Client 查询固定起运仓随机渠道池/) assert.match(orders, /findPricedOrderRoute\(\{/) assert.match(orders, /Client 登录企业与指定客户名称一致/) assert.doesNotMatch(runner, /channel-name|channel-code/) }) test('称重只随机复用固定托盘且不创建新托盘', () => { assert.match(measurement, /REUSABLE_PALLET_CODES = Object\.freeze\(\['TP-001', 'YW-TP-002'\]\)/) assert.match(measurement, /context\.request\('GET',[\s\S]*\/api\/platform\/v1\/pallets\?page=1&size=20/) assert.match(measurement, /randomlyReusePalletIds\(candidates, palletCount/) assert.match(measurement, /随机复用原有称重托盘/) assert.match(measurement, /指定称重托盘池至少存在一只可复用托盘/) assert.doesNotMatch(measurement, /context\.request\('POST', '\/api\/platform\/v1\/pallets/) assert.doesNotMatch(acceptance, /createPhase3FreshMeasurementPallet/) }) test('称重脚本不新增库位且容量不足由仓库服务复用 A0 公共位', () => { assert.doesNotMatch(measurement, /context\.request\('POST', '\/api\/platform\/v1\/locations/) assert.doesNotMatch(measurement, /创建测量占用库位/) assert.match(measurement, /普通位不足会复用唯一的 A0 共享溢出位/) assert.match(warehouseLocationResources, /selected\.size\(\) < quantity[\s\S]*lockOrCreateSharedOverflow/) }) test('八千票执行器逐票记录且失败后继续', () => { assert.match(runner, /positiveInteger\(values\.get\('count'\), 8000/) assert.match(runner, /positiveInteger\(values\.get\('box-max'\), 300/) assert.match(runner, /randomInt\(boxMin, boxMax \+ 1\)/) assert.match(runner, /Math\.ceil\(packageCount \/ 30\)/) assert.match(runner, /for \(let offset = 0; offset < count; offset \+= 1\)/) assert.match(runner, /event: 'planned'/) assert.match(runner, /event: 'result'/) assert.match(runner, /options\.markerNamespace = workerId/) assert.match(runner, /failureDirectory/) assert.match(runner, /summary\.failed \+= 1/) assert.match(runner, /summary\.attempted % batchSize === 0/) })