Files
baiyue-firstleg/scripts/admin-test-env-modules/manual-pda-batch-contract.test.mjs
T

44 lines
2.5 KiB
JavaScript
Raw Normal View History

2026-08-26 16:50:22 +08:00
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { parseArguments, validateExecutionOptions } from '../admin-test-env-acceptance.mjs'
const entry = readFileSync(new URL('../admin-test-env-acceptance.mjs', import.meta.url), 'utf8')
const fixture = readFileSync(new URL('./manual-pda-batch-fixture.mjs', import.meta.url), 'utf8')
const verify = readFileSync(new URL('./manual-pda-batch-verify.mjs', import.meta.url), 'utf8')
test('manual PDA batch modules are optional and require a source report', () => {
assert.match(entry, /OPTIONAL_MODULES\s*=\s*\[[^\]]*'manual-pda-batch-fixture'[^\]]*'manual-pda-batch-verify'/s)
const defaults = parseArguments([]).modules
assert.equal(defaults.includes('manual-pda-batch-fixture'), false)
assert.equal(defaults.includes('manual-pda-batch-verify'), false)
for (const module of ['manual-pda-batch-fixture', 'manual-pda-batch-verify']) {
const options = parseArguments(['--gateway', 'http://127.0.0.1:9000', '--username', 'admin',
'--password', 'password-value', '--modules', module, '--manual-pda-batch-source-report', 'source.json'])
assert.deepEqual(options.modules, [module])
assert.equal(validateExecutionOptions(options), options)
assert.throws(() => validateExecutionOptions({ ...options, manualPdaBatchSourceReport: '' }),
/manual-pda-batch-source-report/)
}
})
test('PDA batch preparation is read only and preserves stable carton scan instructions', () => {
assert.match(fixture, /manualPdaReadyVerification/)
assert.match(fixture, /boxCodes\.length >= item\.plannedPackageCount/)
assert.match(fixture, /scanBoxCodes: rows\(item\.boxCodes\)/)
assert.match(fixture, /inventory-snapshot/)
assert.match(fixture, /不存在 CLAIM、BATCH、REVIEW 或 COMPLETE_LOADING/)
assert.match(fixture, /逐次扫码动作需保留真机人工证据/)
assert.doesNotMatch(fixture, /context\.request\(['"](?:POST|PATCH|PUT|DELETE)/)
})
test('post-batch verifier proves one claim, one batch and AWAITING_REVIEW without writes', () => {
assert.match(verify, /workflowStatus === 'AWAITING_REVIEW'/)
assert.match(verify, /itemStatus === 'PICKED'/)
assert.match(verify, /claimOperations\.length === 1 && batchOperations\.length === 1/)
assert.match(verify, /pendingItemCount\) === 0/)
assert.match(verify, /expectedCount\) === Number\(projection\?\.pickedCount\)/)
assert.match(verify, /HTTP 不记录逐次扫码轨迹/)
assert.doesNotMatch(verify, /context\.request\(['"](?:POST|PATCH|PUT|DELETE)/)
})