From 7b2b2084673dfdce1aa162ea74352ca6e2fa9f64 Mon Sep 17 00:00:00 2001 From: ouyangxq <775153912@qq.com> Date: Sat, 8 Aug 2026 15:14:28 +0800 Subject: [PATCH] test: expand overseas storage fee acceptance --- .../overseas-storage-fees.mjs | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/scripts/admin-test-env-modules/overseas-storage-fees.mjs b/scripts/admin-test-env-modules/overseas-storage-fees.mjs index 529cba3c0..d8dd8b606 100644 --- a/scripts/admin-test-env-modules/overseas-storage-fees.mjs +++ b/scripts/admin-test-env-modules/overseas-storage-fees.mjs @@ -105,6 +105,14 @@ export async function run(context) { initial.id && initial.customerId === tenantId && initial.currency === 'USD' && defaultShape(view), `ruleId=${initial.id || 'missing'}, customerId=${initial.customerId}, currency=${initial.currency}, tiers=${tiersOf(view).length}`, OPTIONS) + const listPath = `/api/platform/v1/overseas-storage-fees?page=1&size=10&customerId=${encodeURIComponent(tenantId)}` + const initialListResponse = await context.request('GET', listPath) + const initialList = context.apiSuccess(MODULE, '按客户查询海外仓费用规则', initialListResponse, `tenantId=${tenantId}`, OPTIONS) + context.assert(MODULE, '每个客户恰好一条规则且规则内恰好9档', initialListResponse, + Number(initialList?.total) === 1 && initialList?.records?.length === 1 + && id(initialList.records[0]?.id) === initial.id && tiersOf(initialList.records[0]).length === 9, + `total=${initialList?.total}, records=${initialList?.records?.length}, tiers=${tiersOf(initialList?.records?.[0]).length}`, OPTIONS) + const wrongCustomerResponse = await context.request('PUT', activePath, { customerId: `${BigInt(tenantId) + 1n}`, customerName: initial.customerName, currency: initial.currency, tiers: initial.tiers, version: initial.version, @@ -112,7 +120,37 @@ export async function run(context) { context.addStep(MODULE, '请求体客户 ID 与路径不一致时安全失败', wrongCustomerResponse, businessFailure(wrongCustomerResponse), `HTTP=${wrongCustomerResponse.http}, code=${codeOf(wrongCustomerResponse)}`, OPTIONS) - const editedTiers = initial.tiers.map((tier, index) => ({ ...tier, unitPrice: Number((tier.unitPrice + 0.125 + index / 1000).toFixed(3)) })) + const invalidPayloads = [ + ['非法费用类型', initial.tiers.map((tier, index) => index === 0 ? { ...tier, feeType: 'INVALID' } : tier)], + ['费用类型与计费单位不匹配', initial.tiers.map((tier, index) => index === 0 ? { ...tier, billingUnit: 'PALLET' } : tier)], + ['阶梯区间重叠', initial.tiers.map((tier) => tier.feeType === 'STORAGE' && tier.startDay === 8 ? { ...tier, startDay: 7 } : tier)], + ['阶梯区间断档', initial.tiers.map((tier) => tier.feeType === 'STORAGE' && tier.startDay === 8 ? { ...tier, startDay: 9 } : tier)], + ['非9档整组提交', initial.tiers.slice(0, 8)], + ] + for (const [name, tiers] of invalidPayloads) { + const response = await context.request('PUT', activePath, { + customerId: tenantId, customerName: initial.customerName, currency: initial.currency, + tiers, version: initial.version, + }) + context.addStep(MODULE, `${name}安全失败`, response, businessFailure(response), + `HTTP=${response.http}, code=${codeOf(response)}`, OPTIONS) + } + const afterInvalidResponse = await context.request('GET', activePath) + const afterInvalid = context.apiSuccess(MODULE, '负向请求后回查客户费用配置', afterInvalidResponse, '', OPTIONS) + context.assert(MODULE, '所有非法整组请求均未造成部分更新', afterInvalidResponse, + Number(afterInvalid?.version) === initial.version + && tierSnapshot(afterInvalid).every((row, index) => row.join('|') === initial.snapshot[index]?.join('|')), + `version=${afterInvalid?.version}, tiers=${tiersOf(afterInvalid).length}`, OPTIONS) + + const editedTiers = initial.tiers.map((tier, index) => { + let startDay = tier.startDay + let endDay = tier.endDay + if (tier.feeType === 'STORAGE' && tier.startDay === 1) endDay = 6 + if (tier.feeType === 'STORAGE' && tier.startDay === 8) startDay = 7 + if (tier.feeType === 'RETURN_STORAGE' && tier.startDay === 1) endDay = 29 + if (tier.feeType === 'RETURN_STORAGE' && tier.startDay === 31) startDay = 30 + return { ...tier, startDay, endDay, unitPrice: Number((tier.unitPrice + 0.125 + index / 1000).toFixed(3)) } + }) const updatePayload = { customerId: tenantId, customerName: `${initial.customerName}-${context.marker.slice(-8)}`, currency: 'EUR', tiers: editedTiers, version: initial.version, @@ -125,6 +163,15 @@ export async function run(context) { && Number(afterUpdate?.version) === initial.version + 1 && tierSnapshot(afterUpdate).every((row, index) => row.join('|') === tierSnapshot({ tiers: editedTiers })[index].join('|')) context.assert(MODULE, '修改后币种、价格、9档及版本整体回显', afterUpdateResponse, editedCorrect, `currency=${afterUpdate?.currency}, version=${afterUpdate?.version}, tiers=${tiersOf(afterUpdate).length}`, OPTIONS) + const repeatedListResponse = await context.request('GET', listPath) + const repeatedList = context.apiSuccess(MODULE, '编辑后再次按客户查询唯一规则', repeatedListResponse, '', OPTIONS) + context.assert(MODULE, '重复初始化结果保持幂等且编辑值未被覆盖', repeatedListResponse, + Number(repeatedList?.total) === 1 && repeatedList?.records?.length === 1 + && id(repeatedList.records[0]?.id) === initial.id + && repeatedList.records[0]?.currency === 'EUR' + && Number(repeatedList.records[0]?.version) === initial.version + 1 + && tierSnapshot(repeatedList.records[0]).every((row, index) => row.join('|') === tierSnapshot({ tiers: editedTiers })[index].join('|')), + `total=${repeatedList?.total}, ruleId=${id(repeatedList?.records?.[0]?.id)}, version=${repeatedList?.records?.[0]?.version}`, OPTIONS) const staleResponse = await context.request('PUT', activePath, { ...updatePayload, customerName: `${updatePayload.customerName}-STALE`, version: initial.version }) const staleRejected = staleResponse.http === 200 && ['A0409', '409'].includes(codeOf(staleResponse))