优化
This commit is contained in:
@@ -2,11 +2,38 @@ import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFile } from 'node:fs/promises'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
import { verifyDiscardApproval } from './phase4-overseas-client-services.mjs'
|
||||
import { verifyDiscardApproval, submitClientTransfer } from './phase4-overseas-client-services.mjs'
|
||||
import { parseArguments } from '../admin-test-env-acceptance.mjs'
|
||||
|
||||
const source = await readFile(fileURLToPath(new URL('./phase4-overseas-client-services.mjs', import.meta.url)), 'utf8')
|
||||
|
||||
for (const fault of ['', 'network', 'server', 'rejected', 'wrong order', 'wrong status', 'throws']) {
|
||||
test(`transfer submit sends once and stops on uncertain result: ${fault || 'success'}`, async () => {
|
||||
const calls = []
|
||||
const context = { marker: 'batch', createdResources: { phase4OverseasClientServices: {} },
|
||||
apiSuccess(_m, _n, response) { return response?.body?.data },
|
||||
async request(method, path, body, token) {
|
||||
calls.push({ method, path, body, token })
|
||||
if (fault === 'throws') throw new Error('connection closed')
|
||||
return { http: fault === 'network' ? 0 : fault === 'server' ? 503 : 200,
|
||||
requestId: 'request', traceId: 'trace', body: { code: fault === 'rejected' ? 'A0409' : '200',
|
||||
data: { transferNo: fault === 'wrong order' ? 'OTHER' : 'WT-1',
|
||||
status: fault === 'wrong status' ? 'DRAFT' : 'PENDING_REVIEW' } } }
|
||||
} }
|
||||
if (fault) await assert.rejects(submitClientTransfer(context, 'merchant', 'WT-1'))
|
||||
else assert.equal((await submitClientTransfer(context, 'merchant', 'WT-1')).status, 'PENDING_REVIEW')
|
||||
assert.equal(calls.length, 1)
|
||||
assert.equal(calls[0].method, 'POST')
|
||||
assert.equal(calls[0].path, '/api/merchant/v1/last-leg/warehouse-transfers/WT-1/submit')
|
||||
const proof = context.createdResources.phase4OverseasClientServices.transferSubmission
|
||||
assert.equal(proof.status, !fault ? 'PENDING_REVIEW' : ['network', 'server', 'throws'].includes(fault)
|
||||
? 'UNKNOWN_RESULT' : fault === 'rejected' ? 'REJECTED' : 'UNEXPECTED_RESULT')
|
||||
assert.equal(JSON.stringify(proof).includes('merchant'), false)
|
||||
await assert.rejects(submitClientTransfer(context, 'merchant', 'WT-1'), /禁止重复提交/)
|
||||
assert.equal(calls.length, 1)
|
||||
})
|
||||
}
|
||||
|
||||
test('discard proof follows reserved approval and keeps actual PDA confirmation separate', () => {
|
||||
assert.match(source, /Approval retains the existing reservation without deducting stock/)
|
||||
assert.match(source, /Actual PDA confirmation deducts the confirmed quantity/)
|
||||
@@ -70,7 +97,9 @@ test('module records marker-owned resources without forbidden fulfillment cleanu
|
||||
assert.match(source, /relabelNo = relabelNo/)
|
||||
assert.match(source, /transferNo = transferNo/)
|
||||
assert.match(source, /discardNo = discardNo/)
|
||||
assert.match(source, /no outbound, dispatch or delivery action is invoked/)
|
||||
assert.match(source, /no dispatch or delivery action is invoked/)
|
||||
assert.match(source, /await verifyCargoDiscardFulfillment\(context/)
|
||||
assert.match(source, /snapshot: \(\) => discardSnapshot\(context, token, proof, proof.approvedNo\)/)
|
||||
})
|
||||
|
||||
test('focused client services keeps the marker-owned merchant fixture when reusable credentials exist', () => {
|
||||
|
||||
Reference in New Issue
Block a user