This commit is contained in:
2026-08-14 10:09:46 +08:00
parent 0bc752a2be
commit 66089f9b99
31 changed files with 719 additions and 141 deletions
+19 -13
View File
@@ -2,6 +2,9 @@ const MODULE = 'fee-items'
const SCENARIO = 'platform-public-fee-items'
const OPTIONS = { scenario: SCENARIO, deploymentBlocker: true }
const BASE = '/api/platform/v1/fee-items'
const BASELINE_COUNT = 111
const DOMESTIC_COUNT = 84
const INTERNATIONAL_COUNT = 27
const MERCHANT_USERNAME = process.env.MERCHANT_TEST_USERNAME || 'merchant_admin'
const MERCHANT_PASSWORD = process.env.MERCHANT_TEST_PASSWORD || 'ChangeMe123!'
@@ -42,7 +45,10 @@ function payload(suffix, overrides = {}) {
}
}
function expectedCodes() {
return Array.from({ length: 110 }, (_, index) => `FEE_TYPE_${String(index + 1).padStart(3, '0')}`)
return [
'FBA_HEAD_FREIGHT',
...Array.from({ length: 110 }, (_, index) => `FEE_TYPE_${String(index + 1).padStart(3, '0')}`),
].sort()
}
export function isAcceptanceFeeItem(row) {
return /^ACPT_\d+$/.test(String(row?.feeCode || ''))
@@ -84,8 +90,8 @@ export async function run(context) {
const initialPageResponse = await context.request('GET', query({ page: 1, size: 20 }))
const initialPage = context.apiSuccess(MODULE, '费用项目查看权限与分页查询', initialPageResponse,
'page=1,size=20', OPTIONS)
context.assert(MODULE, '分页总数110且默认20条对应6页', initialPageResponse,
records(initialPage).length === 20 && Number(initialPage?.total) === 110
context.assert(MODULE, '正式目录111条且默认20条对应6页', initialPageResponse,
records(initialPage).length === 20 && Number(initialPage?.total) === BASELINE_COUNT
&& Number(initialPage?.pages) === 6 && Number(initialPage?.page) === 1,
`records=${records(initialPage).length}, total=${initialPage?.total ?? 'n/a'}, pages=${initialPage?.pages ?? 'n/a'}`, OPTIONS)
context.assert(MODULE, '费用项目查询不传 accountId 仍成功', initialPageResponse,
@@ -97,13 +103,13 @@ export async function run(context) {
const domestic = initialRows.filter((row) => row.tradeScope === 'DOMESTIC')
const international = initialRows.filter((row) => row.tradeScope === 'INTERNATIONAL')
const actualCodes = initialRows.map((row) => row.feeCode).sort()
context.assert(MODULE, '初始化110条全部属于平台且状态ACTIVE', initial.response,
initialRows.length === 110 && initialRows.every((row) => id(row.tenantId) === '0' && row.status === 'ACTIVE'),
context.assert(MODULE, '正式目录111条全部属于平台且状态ACTIVE', initial.response,
initialRows.length === BASELINE_COUNT && initialRows.every((row) => id(row.tenantId) === '0' && row.status === 'ACTIVE'),
`rows=${initialRows.length}, platform=${initialRows.filter((row) => id(row.tenantId) === '0').length}, active=${initialRows.filter((row) => row.status === 'ACTIVE').length}`, OPTIONS)
context.assert(MODULE, '国内84条、国际26条范围正确', initial.response,
domestic.length === 84 && international.length === 26,
context.assert(MODULE, '国内84条、国际27条范围正确', initial.response,
domestic.length === DOMESTIC_COUNT && international.length === INTERNATIONAL_COUNT,
`DOMESTIC=${domestic.length}, INTERNATIONAL=${international.length}`, OPTIONS)
context.assert(MODULE, '初始化编码完整覆盖 FEE_TYPE_001..FEE_TYPE_110', initial.response,
context.assert(MODULE, '正式编码完整覆盖110条受控项目及系统头程运费', initial.response,
actualCodes.join(',') === expectedCodes().join(','),
`codes=${actualCodes.length}, first=${actualCodes[0] || 'missing'}, last=${actualCodes.at(-1) || 'missing'}`, OPTIONS)
@@ -115,7 +121,7 @@ export async function run(context) {
Boolean(category) && records(categoryPage).length > 0 && records(categoryPage).every((row) => row.category === category),
`records=${records(categoryPage).length}`, OPTIONS)
for (const [scope, expected] of [['DOMESTIC', 84], ['INTERNATIONAL', 26]]) {
for (const [scope, expected] of [['DOMESTIC', DOMESTIC_COUNT], ['INTERNATIONAL', INTERNATIONAL_COUNT]]) {
const response = await context.request('GET', query({ tradeScope: scope, page: 1, size: 200 }))
const page = context.apiSuccess(MODULE, `按 ${scope} 贸易范围筛选`, response, '', OPTIONS)
context.assert(MODULE, `${scope} 筛选数量和范围正确`, response,
@@ -135,8 +141,8 @@ export async function run(context) {
const activeResponse = await context.request('GET', query({ status: 'ACTIVE', page: 1, size: 200 }))
const activePage = context.apiSuccess(MODULE, '按 ACTIVE 状态筛选费用项目', activeResponse, '', OPTIONS)
context.assert(MODULE, 'ACTIVE 筛选返回110条且无停用记录', activeResponse,
Number(activePage?.total) === 110 && records(activePage).every((row) => row.status === 'ACTIVE'),
context.assert(MODULE, 'ACTIVE 筛选返回111条且无停用记录', activeResponse,
Number(activePage?.total) === BASELINE_COUNT && records(activePage).every((row) => row.status === 'ACTIVE'),
`total=${activePage?.total ?? 'n/a'}`, OPTIONS)
const merchantLoginResponse = await context.request('POST', '/api/auth/login', {
@@ -266,8 +272,8 @@ export async function run(context) {
`feeItemId=${feeItemId}`, OPTIONS)
}
const final = await listAll(context)
context.assert(MODULE, '清理后恢复110条基线且无临时编码或名称', final.response,
final.rows.length === 110 && !final.rows.some((row) => row.feeCode === createPayload.feeCode
context.assert(MODULE, '清理后恢复111条正式基线且无临时编码或名称', final.response,
final.rows.length === BASELINE_COUNT && !final.rows.some((row) => row.feeCode === createPayload.feeCode
|| String(row.feeTypeName).includes(suffix)),
`rows=${final.rows.length}, temporary=${final.rows.filter((row) => row.feeCode === createPayload.feeCode).length}`, OPTIONS)
context.createdResources.feeItems = {