Files
baiyue-firstleg/scripts/admin-test-env-modules/phase4-overseas-pda-contract.test.mjs
T

50 lines
2.4 KiB
JavaScript

import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import test from 'node:test'
import { fileURLToPath } from 'node:url'
import { run } from './phase4-overseas-pda.mjs'
const here = path.dirname(fileURLToPath(import.meta.url))
const source = fs.readFileSync(path.join(here, 'phase4-overseas-pda.mjs'), 'utf8')
test('PDA module uses only injected development acceptance requests', () => {
assert.match(source, /export async function run\(context\)/)
assert.match(source, /context\.requestOverseas\(/)
assert.match(source, /context\.requestOverseasMultipart\(/)
assert.doesNotMatch(source, /https?:\/\//)
assert.doesNotMatch(source, /process\.env|fetch\(/)
})
test('PDA module covers the complete receiving lifecycle and excludes outbound domains', () => {
for (const token of ['/destination', '/inbound-plans/convert', '/pallets/', '/push', '/cartons/scan', '/allocations/',
'/count', '/pick', '/unload-photos/files', '/unload-photos', '/complete', '/inventory/balances']) {
assert.ok(source.includes(token), token)
}
for (const forbidden of ['/outbound', '/dispatch', '/delivery', '/internal/']) assert.equal(source.includes(forbidden), false, forbidden)
assert.match(source, /requestId=/)
assert.match(source, /traceId=/)
assert.match(source, /PENDING_ASSIGNMENT/)
assert.match(source, /nonBlank\(item\?\.containerNo\)/)
assert.match(source, /expectedCartons/)
})
test('missing source order is reported as a fixture prerequisite without business writes', async () => {
const calls = []; const gaps = []; const steps = []
const context = {
marker: 'PDA-CONTRACT', createdResources: {},
async request(method, requestPath) { calls.push({ channel: 'domestic', method, requestPath }); return { http: 200, body: { code: '200', data: { records: [], page: 1, size: 200, total: 0, pages: 0 } } } },
async requestOverseas(method, requestPath) { calls.push({ channel: 'overseas', method, requestPath }); throw new Error('overseas should not be called without customers') },
addStep(...args) { steps.push(args) },
assert(...args) { steps.push(args) },
addCoverageGap(...args) { gaps.push(args) },
}
await run(context)
assert.equal(calls.length, 1)
assert.equal(calls[0].method, 'GET')
assert.equal(gaps.length, 1)
assert.match(gaps[0][3], /三期装柜完成事件链/)
assert.deepEqual(context.createdResources.phase4OverseasPda.finalStatus, null)
})