Files
baiyue-firstleg/scripts/admin-test-env-modules/firstleg-container-fee-allocation-contract.test.mjs
T

53 lines
2.8 KiB
JavaScript
Raw Normal View History

import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import test from 'node:test'
import {
candidateLoadingPlanIds,
ownershipAllocations,
withoutInbound,
} from './firstleg-container-fee-allocation.mjs'
const source = readFileSync(new URL('./firstleg-container-fee-allocation.mjs', import.meta.url), 'utf8')
test('candidate plans only come from resources created by the current acceptance run', () => {
assert.deepEqual(candidateLoadingPlanIds({
phase3ContainerLoading: { loadingPlanId: '101' },
coloadGroupAcceptance: { fullPlanId: '102', planId: '103' },
manualLoadingComplete: { loadingPlanId: '101' },
financeFullFixtures: { feeSources: [{ loadingPlanId: '104' }] },
}), ['101', '102', '103', '104'])
assert.doesNotMatch(source, /pageSize=\d+.*smart-loading|containers\?page|历史柜/)
})
test('allocation builder selects one real order per distinct customer and preserves exact cents', () => {
const allocations = ownershipAllocations([
{ accountId: '11', orderId: '21', orderNo: 'FL-21', inboundId: '31', inboundCode: 'IN-31' },
{ accountId: '11', orderId: '22', orderNo: 'FL-22', inboundId: '32', inboundCode: 'IN-32' },
{ accountId: '12', orderId: '23', orderNo: 'FL-23', inboundId: '33', inboundCode: 'IN-33' },
{ accountId: '13', orderId: '24', orderNo: 'FL-24', inboundId: '34', inboundCode: 'IN-34' },
], 100)
assert.equal(allocations.length, 3)
assert.equal(new Set(allocations.map((item) => item.customerId)).size, 3)
assert.equal(allocations.reduce((sum, item) => sum + Number(item.amount), 0), 100)
assert.deepEqual(withoutInbound(allocations[0]), {
customerId: '11', orderId: '21', orderNo: 'FL-21', amount: '33.33',
})
})
test('module freezes all required real HTTP invariants and provisions a formal cross-customer fixture', async () => {
for (const token of [
'/allocation-groups', '分摊金额合计不一致被拒绝', '分摊客户必填', '分摊订单必填',
'伪造非柜内订单归属被拒绝', '伪造非柜内入仓码被拒绝', '不填写入仓码原子创建跨客户分摊组',
'单行审核不能破坏分摊组一致性', '整组审核原子成功', '缺少组成员的调整被拒绝',
'整组调整原子成功', '整组作废原子成功', '已作废冻结分摊组拒绝继续调整',
'非柜内客户不能读取柜次费用', 'requestId=', 'traceId=', 'deploymentBlocker: true',
]) assert.ok(source.includes(token), token)
for (const token of [
'createMerchant(context)', 'createCustomerWaitSplit', 'provisionCrossCustomerPlan',
'originalUsername', 'originalPassword', 'delete process.env.MERCHANT_TEST_USERNAME',
'delete process.env.MERCHANT_TEST_PASSWORD',
]) assert.ok(source.includes(token), token)
assert.doesNotMatch(source, /\bfetch\s*\(|\/internal\/|mysql|SELECT\s/i)
})