Files
baiyue-firstleg/scripts/admin-test-env-modules/domestic-container-contract.test.mjs

49 lines
2.4 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
const here = path.dirname(fileURLToPath(import.meta.url))
const moduleSource = fs.readFileSync(path.join(here, 'domestic-container.mjs'), 'utf8')
const acceptance = fs.readFileSync(path.join(here, '..', 'admin-test-env-acceptance.mjs'), 'utf8')
test('国内整柜模块仅由总编排注入 context 后执行', () => {
assert.match(moduleSource, /export async function run\(context\)/)
assert.doesNotMatch(moduleSource, /https?:\/\//)
assert.doesNotMatch(moduleSource, /ADMIN_TEST_GATEWAY|process\.env|fetch\(/)
assert.match(acceptance, /import\(new URL\(`\.\/admin-test-env-modules\/\$\{module\}\.mjs`/)
})
test('正式全量验收默认注册国内整柜模块', () => {
assert.match(acceptance, /CONFIGURED_MODULES\s*=\s*\[[^\]]*['"]domestic-container['"]/s)
assert.match(acceptance, /DEFAULT_MODULES\s*=\s*normalizeModuleOrder\(CONFIGURED_MODULES\)/)
})
test('覆盖国内仓、待单、完成入库、部分和全部出库及列表详情流水', () => {
for (const token of ['warehouseType=DOMESTIC', "status: 'PENDING'", "status: 'COMPLETED'",
'PARTIALLY_OUTBOUND', "inventoryStatus === 'OUTBOUND'", '/inbounds?page=1', '/outbounds?page=1',
'/inventories/${inventoryId}', 'transactions?.length === 3']) assert.match(moduleSource, new RegExp(token.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')))
})
test('在创建测试数据前覆盖无筛选整柜入库列表', () => {
const unfilteredList = '`${BASE}/inbounds?page=1&size=20`'
assert.match(moduleSource, /无筛选查询整柜入库单列表/)
assert.ok(moduleSource.indexOf(unfilteredList) < moduleSource.indexOf("api(context, 'POST', `${BASE}/inbounds`"))
})
test('覆盖库存不足、版本冲突及两类幂等行为', () => {
assert.match(moduleSource, /库存不足禁止出库/)
assert.match(moduleSource, /过期库存版本冲突/)
assert.match(moduleSource, /同幂等键同请求重放/)
assert.match(moduleSource, /同幂等键不同请求冲突/)
assert.match(moduleSource, /inventoryVersion/)
})
test('覆盖权限拒绝与 requestId traceId', () => {
assert.match(moduleSource, /无整柜权限用户被拒绝/)
assert.match(moduleSource, /'A0403'/)
assert.match(moduleSource, /Boolean\(response\?\.requestId\).*Boolean\(response\?\.traceId\)/s)
assert.match(moduleSource, /status: 'DISABLED'/)
})