test(admin): accept explicit duplicate import rejection
This commit is contained in:
@@ -209,16 +209,25 @@ export async function run(context) {
|
|||||||
{ scenario: 'valid-import', deploymentBlocker: first.http === 404 || first.http === 405 || first.http === 503 })
|
{ scenario: 'valid-import', deploymentBlocker: first.http === 404 || first.http === 405 || first.http === 503 })
|
||||||
const second = await uploadTemplate(context, importPath, fixtureBytes, `${context.marker}-${name}-replay.xlsx`)
|
const second = await uploadTemplate(context, importPath, fixtureBytes, `${context.marker}-${name}-replay.xlsx`)
|
||||||
const secondData = second.body?.data
|
const secondData = second.body?.data
|
||||||
|
const replayCode = String(second.body?.code ?? '')
|
||||||
|
const replayMessage = String(second.body?.message ?? '')
|
||||||
|
const idempotentSuccess = replayCode === '200'
|
||||||
|
&& (importedCount(secondData) < 1 || (Array.isArray(secondData?.errors) && secondData.errors.length > 0))
|
||||||
|
const explicitValidationConflict = replayCode === 'A0422'
|
||||||
|
&& replayMessage === `${name}导入文件校验失败`
|
||||||
context.addStep(module, `${name}重复导入返回明确冲突`, second,
|
context.addStep(module, `${name}重复导入返回明确冲突`, second,
|
||||||
second.http === 200 && String(second.body?.code) === '200' && (importedCount(secondData) < 1 || (Array.isArray(secondData?.errors) && secondData.errors.length > 0)),
|
second.http === 200 && (idempotentSuccess || explicitValidationConflict),
|
||||||
`firstImported=${importedCount(firstData)}, replayImported=${importedCount(secondData)}, errors=${secondData?.errors?.length ?? 'n/a'}`,
|
`HTTP=${second.http}, code=${replayCode || 'missing'}, message=${replayMessage || 'missing'}, firstImported=${importedCount(firstData)}, replayImported=${importedCount(secondData)}, errors=${secondData?.errors?.length ?? 'n/a'}`,
|
||||||
{ scenario: 'valid-import', deploymentBlocker: second.http === 404 || second.http === 405 || second.http === 503 })
|
{ scenario: 'valid-import', deploymentBlocker: second.http === 404 || second.http === 405 || second.http === 503 })
|
||||||
const key = name === '仓库' ? 'warehouseCode' : name === '快递公司' ? 'companyCode' : 'partnerCode'
|
const key = name === '仓库' ? 'warehouseCode' : name === '快递公司' ? 'companyCode' : 'partnerCode'
|
||||||
const value = fixture.values[0]
|
const value = fixture.values[0]
|
||||||
const listPath = name === '仓库' ? `/api/platform/v1/warehouse-admin?page=1&size=20&keyword=${encodeURIComponent(value)}` : name === '快递公司' ? `/api/platform/v1/express-companies?page=1&size=20&keyword=${encodeURIComponent(value)}` : `/api/platform/v1/partners?page=1&size=20&keyword=${encodeURIComponent(value)}`
|
const listPath = name === '仓库' ? `/api/platform/v1/warehouse-admin?page=1&size=20&keyword=${encodeURIComponent(value)}` : name === '快递公司' ? `/api/platform/v1/express-companies?page=1&size=20&keyword=${encodeURIComponent(value)}` : `/api/platform/v1/partners?page=1&size=20&keyword=${encodeURIComponent(value)}`
|
||||||
const listed = await context.request('GET', listPath)
|
const listed = await context.request('GET', listPath)
|
||||||
const listedData = context.apiSuccess(module, `${name}导入列表回查`, listed, `keyword=${value}`)
|
const listedData = context.apiSuccess(module, `${name}导入列表回查`, listed, `keyword=${value}`)
|
||||||
const item = listedData?.records?.find((row) => row[key] === value)
|
const matchingItems = listedData?.records?.filter((row) => row[key] === value) ?? []
|
||||||
|
const item = matchingItems[0]
|
||||||
|
context.assert(module, `${name}重复导入后零新增`, listed, matchingItems.length === 1,
|
||||||
|
`matchingRecords=${matchingItems.length}`, { scenario: 'valid-import', deploymentBlocker: listed.http === 404 || listed.http === 405 || listed.http === 503 })
|
||||||
context.assert(module, `${name}导入资源回查 marker`, listed, Boolean(item), `found=${Boolean(item)}, id=${item?.id ?? 'missing'}`, { scenario: 'valid-import', deploymentBlocker: listed.http === 404 || listed.http === 405 || listed.http === 503 })
|
context.assert(module, `${name}导入资源回查 marker`, listed, Boolean(item), `found=${Boolean(item)}, id=${item?.id ?? 'missing'}`, { scenario: 'valid-import', deploymentBlocker: listed.http === 404 || listed.http === 405 || listed.http === 503 })
|
||||||
if (item?.id) {
|
if (item?.id) {
|
||||||
const disablePath = name === '仓库' ? `/api/platform/v1/warehouse-admin/${item.id}/status?tenantId=0&status=INACTIVE` : name === '快递公司' ? `/api/platform/v1/express-companies/${item.id}/status?tenantId=0` : `/api/platform/v1/partners/${item.id}/status?tenantId=0`
|
const disablePath = name === '仓库' ? `/api/platform/v1/warehouse-admin/${item.id}/status?tenantId=0&status=INACTIVE` : name === '快递公司' ? `/api/platform/v1/express-companies/${item.id}/status?tenantId=0` : `/api/platform/v1/partners/${item.id}/status?tenantId=0`
|
||||||
|
|||||||
Reference in New Issue
Block a user