优化
This commit is contained in:
@@ -44,6 +44,10 @@ function payload(suffix, overrides = {}) {
|
||||
function expectedCodes() {
|
||||
return Array.from({ length: 110 }, (_, index) => `FEE_TYPE_${String(index + 1).padStart(3, '0')}`)
|
||||
}
|
||||
export function isAcceptanceFeeItem(row) {
|
||||
return /^ACPT_\d+$/.test(String(row?.feeCode || ''))
|
||||
&& String(row?.feeTypeName || '').startsWith('全量验收费用-')
|
||||
}
|
||||
function fixture(context) {
|
||||
const candidates = [context.createdResources?.orders, context.createdResources?.testInbound,
|
||||
context.createdResources?.inboundMeasurement, context.context?.testInbound]
|
||||
@@ -57,7 +61,26 @@ async function listAll(context) {
|
||||
return { response, page, rows: records(page) }
|
||||
}
|
||||
|
||||
async function cleanupStaleAcceptanceItems(context) {
|
||||
const listed = await listAll(context)
|
||||
const stale = listed.rows.filter(isAcceptanceFeeItem)
|
||||
const failed = []
|
||||
for (const row of stale) {
|
||||
const response = await context.request('DELETE', `${BASE}/${encodeURIComponent(id(row.id))}`)
|
||||
if (!cleanupSucceeded(response)) failed.push({ row, response })
|
||||
}
|
||||
const response = failed[0]?.response || listed.response
|
||||
context.assert(MODULE, '前置清理历史验收临时费用项目', response, failed.length === 0,
|
||||
failed.length === 0
|
||||
? `stale=${stale.length}, cleaned=${stale.length}`
|
||||
: `failed=${failed.map(({ row, response: failure }) => `${row.feeCode}:${failure.body?.code || failure.http}`).join(',')}`,
|
||||
OPTIONS)
|
||||
return failed.length === 0
|
||||
}
|
||||
|
||||
export async function run(context) {
|
||||
if (!await cleanupStaleAcceptanceItems(context)) return
|
||||
|
||||
const initialPageResponse = await context.request('GET', query({ page: 1, size: 20 }))
|
||||
const initialPage = context.apiSuccess(MODULE, '费用项目查看权限与分页查询', initialPageResponse,
|
||||
'page=1,size=20', OPTIONS)
|
||||
|
||||
Reference in New Issue
Block a user