优化
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import { exportWorkbook } from './download-center-fixture.mjs'
|
||||
import assert from 'node:assert/strict'
|
||||
import fs from 'node:fs'
|
||||
import path from 'node:path'
|
||||
@@ -17,6 +18,10 @@ function contextFixture({ tenants = [{ id: '10001', status: 'ACTIVE' }], warehou
|
||||
const context = {
|
||||
context: {}, createdResources: {}, marker: 'ACC-PHASE4-TEST', calls, steps, gaps,
|
||||
async request(...args) {
|
||||
if (args[1].startsWith('/api/platform/v1/files/export-tasks')) {
|
||||
calls.push({ channel: 'domestic', method: args[0], path: args[1], body: args[2] })
|
||||
return response({ id: args[2]?.exportType || args[1].split('/').at(-1), status: args[0] === 'POST' ? 'PENDING' : 'SUCCEEDED' })
|
||||
}
|
||||
const route = /\/(?:last-leg|overseas-warehouse-resources)(?:\/|\?|$)/.test(String(args[1]));
|
||||
const handler = route ? async function(method,requestPath,body) {
|
||||
calls.push({ channel: 'overseas', method, path: requestPath, body })
|
||||
@@ -58,7 +63,7 @@ function contextFixture({ tenants = [{ id: '10001', status: 'ACTIVE' }], warehou
|
||||
return handler.apply(this,args);
|
||||
},
|
||||
|
||||
async requestBinary(method, requestPath) { calls.push({ channel: 'overseas-binary', method, path: requestPath }); return { http: 200, bytes: Buffer.from('id,status\n'), contentType: 'text/csv', requestId: 'request-binary', traceId: 'trace-binary' } },
|
||||
async requestBinary(method, requestPath) { calls.push({ channel: 'overseas-binary', method, path: requestPath }); return { http: 200, bytes: exportWorkbook(['入库单号', 'SKU', '可用箱数', '发生时间', '业务单号', '变动箱数']), contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', requestId: 'request-binary', traceId: 'trace-binary' } },
|
||||
apiSuccess(_module, _name, result) { return result?.http === 200 && String(result?.body?.code) === '200' ? result.body.data : null },
|
||||
assert(module, name, result, passed, evidence, options) { steps.push({ module, name, result, passed: Boolean(passed), evidence, options }) },
|
||||
addStep(module, name, result, passed, evidence, options) { steps.push({ module, name, result, passed: Boolean(passed), evidence, options }) },
|
||||
@@ -70,7 +75,7 @@ function contextFixture({ tenants = [{ id: '10001', status: 'ACTIVE' }], warehou
|
||||
test('模块只依赖注入请求,不读取环境或自行联网', () => {
|
||||
assert.match(source, /export async function run\(context\)/)
|
||||
assert.match(source, /context\.request\('GET'/)
|
||||
assert.match(source, /context\.requestBinary\('GET'/)
|
||||
assert.match(source, /verifyDownloadCenterExport\(context/)
|
||||
assert.doesNotMatch(source, /https?:\/\//)
|
||||
assert.doesNotMatch(source, /process\.env|fetch\(/)
|
||||
})
|
||||
@@ -80,7 +85,7 @@ test('既有仓库场景只写本轮库位与托盘生命周期', () => {
|
||||
return run(context).then(() => {
|
||||
assert.ok(context.calls.length >= 12)
|
||||
assert.ok(context.calls.every((call) => ['GET', 'POST', 'PUT', 'DELETE'].includes(call.method)))
|
||||
assert.equal(context.calls.filter((call) => call.channel === 'domestic').length, 3)
|
||||
assert.equal(context.calls.filter((call) => call.channel === 'domestic' && !call.path.includes('/files/export-tasks')).length, 3)
|
||||
assert.ok(context.calls.some((call) => call.channel === 'domestic' && call.path.startsWith('/api/platform/v1/warehouse-admin?')))
|
||||
assert.ok(context.calls.some((call) => call.channel === 'domestic' && call.path.includes('/warehouse-admin/20001?')))
|
||||
assert.equal(context.calls.some((call) => call.channel === 'overseas' && call.path === '/api/platform/v1/warehouse-admin'), false)
|
||||
@@ -89,7 +94,7 @@ test('既有仓库场景只写本轮库位与托盘生命周期', () => {
|
||||
assert.ok(writes.some((call) => call.method === 'DELETE' && call.path.includes('/locations/72002')))
|
||||
assert.ok(writes.some((call) => call.path.includes('/overseas-warehouse-resources/20001/pallets')))
|
||||
assert.equal(writes.some((call) => call.path.includes('/relabel-applications')), false)
|
||||
assert.ok(writes.every((call) => call.path.includes('/overseas-warehouse-resources/20001/')))
|
||||
assert.ok(writes.every((call) => call.path.includes('/overseas-warehouse-resources/20001/') || (call.method === 'POST' && call.path === '/api/platform/v1/files/export-tasks')))
|
||||
for (const name of ['编辑本轮公共库位', '删除本轮公共库位', '报废本轮公共托盘']) {
|
||||
const step = context.steps.find((item) => item.name === name)
|
||||
assert.ok(step?.passed, name)
|
||||
@@ -113,7 +118,7 @@ test('覆盖冻结的海外只读列表与有记录才查详情', async () => {
|
||||
for (const detailToken of ['/orders/30001?', '/relabel-applications/RL-1?', '/inbound-plans/IP-1?', '/balances/60001/positions?', '/pallets/70001']) {
|
||||
assert.ok(context.calls.some((call) => call.path.includes(detailToken)), detailToken)
|
||||
}
|
||||
for (const call of context.calls.filter((item) => item.path.includes('/inventory/summary?') || item.path.includes('/inventory/balances/export?') || item.path.includes('/inventory/ledger/export?'))) {
|
||||
for (const call of context.calls.filter((item) => item.path.includes('/inventory/summary?'))) {
|
||||
const params = new URL(`http://acceptance${call.path}`).searchParams
|
||||
assert.equal(params.has('page'), false, call.path)
|
||||
assert.equal(params.has('size'), false, call.path)
|
||||
@@ -141,11 +146,11 @@ test('缺少客户时明确失败,缺少仓库时通过正式接口创建并
|
||||
})
|
||||
|
||||
test('合同覆盖库存CSV并明确排除暂缓、离仓、PDA与内部路径', () => {
|
||||
assert.match(source, /inventory\/balances\/export/)
|
||||
assert.match(source, /inventory\/ledger\/export/)
|
||||
assert.match(source, /OVERSEAS_INVENTORY_BALANCE/)
|
||||
assert.match(source, /OVERSEAS_INVENTORY_LEDGER/)
|
||||
assert.match(source, /inventory\/summary[^\n]+\{ customerId \}/)
|
||||
assert.match(source, /inventory\/balances\/export[^\n]+\{ customerId \}/)
|
||||
assert.match(source, /inventory\/ledger\/export[^\n]+\{ customerId \}/)
|
||||
assert.match(source, /OVERSEAS_INVENTORY_BALANCE[^\n]+\{ customerId \}/)
|
||||
assert.match(source, /OVERSEAS_INVENTORY_LEDGER[^\n]+\{ customerId \}/)
|
||||
for (const forbidden of ['/cartons', '/products', '/outbound', '/dispatch', '/delivery', '/pda', '/internal']) assert.equal(source.includes(forbidden), false, forbidden)
|
||||
assert.match(source, /requestId=/)
|
||||
assert.match(source, /traceId=/)
|
||||
|
||||
Reference in New Issue
Block a user