Files
baiyue-firstleg/scripts/admin-test-env-modules/phase4-overseas-wallet-and-pallet-cost-contract.test.mjs
T

79 lines
3.9 KiB
JavaScript

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import { beijingDate, matchesProcurementNo } from './phase4-overseas-wallet-and-pallet-cost.mjs'
const source = readFileSync(new URL('./phase4-overseas-wallet-and-pallet-cost.mjs', import.meta.url), 'utf8')
const entry = readFileSync(new URL('../admin-test-env-acceptance.mjs', import.meta.url), 'utf8')
const pda = readFileSync(new URL('./phase4-overseas-pda.mjs', import.meta.url), 'utf8')
test('采购单号按北京时间日期执行精确合同', () => {
const instant = new Date('2026-09-05T16:30:00.000Z')
assert.equal(beijingDate(instant), '20260906')
assert.equal(matchesProcurementNo('QLYSXDKH202609060001', 'QLYSXDKH', instant), true)
assert.equal(matchesProcurementNo('QLYSXDKH202609050001', 'QLYSXDKH', instant), false)
assert.equal(matchesProcurementNo('QLYSXDKH20260906001', 'QLYSXDKH', instant), false)
})
test('钱包闭环覆盖充值、授信、采购冻结结算和换标结算释放', () => {
for (const token of [
'/accounts/${encodeURIComponent(customerId)}/credit-limit',
'creditExpiresOn',
'/accounts/${encodeURIComponent(customerId)}/adjustments',
"const CLIENT_FINANCE = '/api/client/finance/v1'",
"['VOUCHER', 'RECEIPT']",
"walletStatus === 'FROZEN'",
"walletStatus === 'SETTLED'",
"['FREEZE_PENDING', 'FROZEN']",
"['FREEZE', 'CONSUMPTION', 'UNFREEZE']",
'item.sourceNo === businessNo',
"'RELEASED'",
"terminalStatus === 'COMPLETED'",
"status: 'CUSTOMER_CONFIRM_PENDING'",
"status: 'READY_FOR_OUTBOUND'",
"'CANCELLED'",
'relabelPayload(context, warehouseId, source, suffix, 0.01)',
'/relabel-applications/inventory-candidates',
'operationWarehouseId: id(warehouseId)',
'sourceInventoryBalanceId:',
'sourceInventoryPositionId:',
'sourceInboundOrderId:',
'destinationFbaWarehouseCode: source.destinationFbaWarehouseCode',
'cartonMark:',
'fbaCartonMark:',
"deliveryMethod: 'TRUCK'",
]) assert.ok(source.includes(token), token)
assert.match(source, /actualBalance[\s\S]*frozenBalance[\s\S]*availableBalance[\s\S]*creditLimit[\s\S]*creditUsed[\s\S]*availableCredit/)
assert.match(source, /voucherFileId: id\(files\.find\(\(item\) => item\.category === 'VOUCHER'\)\?\.fileId\)/)
assert.doesNotMatch(source, /voucherFileId:\s*Number\(/)
assert.doesNotMatch(source, /customerOrderNo:[^\n]+overseasWarehouseId:/)
assert.doesNotMatch(source, /internal\/finance|jdbc|mysql|process\.env|https?:\/\//i)
})
test('托盘汇总和拆柜成本验证总数、分摊及跨区金额守恒', () => {
for (const token of [
'/api/platform/v1/pallets/summary',
'/api/platform/v1/overseas-warehouse-resources/pallets/summary',
'/pallets/summary?page=1&size=20',
'OVERSEAS_CONTAINER',
'DESTUFF_PALLET',
'expectedPalletCost',
'sourceFeeId',
'pollRequests=',
]) assert.ok(source.includes(token), token)
assert.doesNotMatch(source, /\/warehouse-admin\/pallets\/summary/)
assert.match(source, /Number\(d\.totalCount\) === Number\(d\.idleCount\) \+ Number\(d\.occupiedCount\)/)
assert.match(source, /allocated === money\(fact\.expectedPalletCost\)/)
assert.match(source, /delivered\.reduce[\s\S]*fact\.expectedPalletCost/)
assert.match(pda, /unitPrice: Number\(pallet\?\.unitPrice \|\| 0\)/)
assert.match(pda, /Number\(stored\.unitPrice \|\| pallet\.unitPrice \|\| 0\)/)
assert.match(pda, /completedContainerFacts\.push/)
})
test('模块进入默认全量并绑定真实商户和海外PDA生产链', () => {
assert.match(entry, /CONFIGURED_MODULES[^\n]*'phase4-overseas-wallet-and-pallet-cost'/)
assert.match(entry, /\['phase4-overseas-wallet-and-pallet-cost', \['phase4-overseas-business', 'phase4-overseas-pda-operations'\]\]/)
assert.match(source, /OPTIONS = \{ scenario: SCENARIO, deploymentBlocker: true \}/)
assert.match(source, /completedFacts\.length > 0/)
})