优化
This commit is contained in:
@@ -4,17 +4,17 @@ import path from 'node:path'
|
||||
import test from 'node:test'
|
||||
import { fileURLToPath } from 'node:url'
|
||||
|
||||
import { EXCEPTION_CODES, QUERY_STATUSES, STANDARD_NODES, run } from './phase4-carrier-nodes.mjs'
|
||||
import { EXCEPTION_CODES, QUERY_STATUSES, STANDARD_NODES, markerOwnedCarrierQuery, run } from './phase4-carrier-nodes.mjs'
|
||||
|
||||
const here = path.dirname(fileURLToPath(import.meta.url))
|
||||
const source = fs.readFileSync(path.join(here, 'phase4-carrier-nodes.mjs'), 'utf8')
|
||||
|
||||
function response(data) { return { http: 200, body: { code: '200', data } } }
|
||||
function contextFor(routes) {
|
||||
function contextFor(routes, createdResources = {}) {
|
||||
const calls = []
|
||||
return {
|
||||
calls,
|
||||
marker: 'T-PHASE4', token: 'token',
|
||||
marker: 'T-PHASE4', token: 'token', createdResources,
|
||||
request: async (method, requestPath, body, _token, headers = {}) => {
|
||||
calls.push(method === 'POST' ? { method, path: requestPath, body, headers } : { method, path: requestPath })
|
||||
assert.ok(['GET', 'POST'].includes(method))
|
||||
@@ -84,6 +84,19 @@ test('canonical task node and exception sets are locked to the phase-4 contract'
|
||||
assert.deepEqual(EXCEPTION_CODES, ['CUSTOMS_HOLD', 'TERMINAL_HOLD', 'DOCUMENT_HOLD', 'UNKNOWN_HOLD'])
|
||||
})
|
||||
|
||||
test('marker ownership requires explicit module ownership, query id and exact current marker', () => {
|
||||
assert.equal(markerOwnedCarrierQuery({ marker: 'M', createdResources: {} }), null)
|
||||
assert.equal(markerOwnedCarrierQuery({ marker: 'M', createdResources: {
|
||||
phase3CarrierScheduleQuery: { queryId: '1', marker: 'OLD', ownedByModule: true },
|
||||
} }), null)
|
||||
assert.equal(markerOwnedCarrierQuery({ marker: 'M', createdResources: {
|
||||
phase3CarrierScheduleQuery: { queryId: '1', marker: 'M', ownedByModule: false },
|
||||
} }), null)
|
||||
assert.equal(markerOwnedCarrierQuery({ marker: 'M', createdResources: {
|
||||
phase3CarrierScheduleQuery: { queryId: '1', marker: 'M', ownedByModule: true },
|
||||
} }).queryId, '1')
|
||||
})
|
||||
|
||||
test('empty page validates read-only pagination without detail calls', async () => {
|
||||
const context = contextFor({
|
||||
'/api/platform/v1/carrier-schedule-queries/carriers': carriers,
|
||||
@@ -96,17 +109,40 @@ test('empty page validates read-only pagination without detail calls', async ()
|
||||
])
|
||||
})
|
||||
|
||||
test('existing task reads page, detail and history with nullable node times', async () => {
|
||||
test('standalone existing historical task is read-only and never receives manual nodes', async () => {
|
||||
const base = '/api/platform/v1/carrier-schedule-queries'
|
||||
const context = contextFor({
|
||||
[`${base}/carriers`]: carriers,
|
||||
[`${base}?page=1&size=20`]: { records: [{ query: task, expired: false }], page: 1, size: 20, total: 1, pages: 1 },
|
||||
[`${base}/${task.id}`]: { query: { query: task, expired: false }, nodes: [node], exceptions: [exception], histories: [history] },
|
||||
[`${base}/${task.id}/manual-nodes`]: { query: { query: task, expired: false }, nodes: [node, manualNode], exceptions: [exception], histories: [history] },
|
||||
[`${base}/${task.id}/history`]: [history],
|
||||
})
|
||||
await run(context)
|
||||
assert.deepEqual(context.calls.map((item) => item.method), ['GET', 'GET', 'GET', 'POST', 'GET'])
|
||||
assert.equal(context.calls.find((item) => item.method === 'POST').headers['Idempotency-Key'], `T-PHASE4-carrier-manual-${task.id}`)
|
||||
assert.deepEqual(context.calls.map((item) => item.method), ['GET', 'GET', 'GET', 'GET'])
|
||||
assert.equal(context.calls.some((item) => item.method === 'POST'), false)
|
||||
assert.equal(context.calls.at(-1).path, `${base}/${task.id}/history`)
|
||||
})
|
||||
|
||||
test('phase4 writes only the exact current-marker query registered by phase3', async () => {
|
||||
const base = '/api/platform/v1/carrier-schedule-queries'
|
||||
const ownedTask = { ...task, id: '9007199254740994', queryNo: 'CSQ9007199254740994',
|
||||
status: 'READY', trackingNo: 'TSTU1234567', version: 6 }
|
||||
const resource = { queryId: ownedTask.id, marker: 'T-PHASE4', ownedByModule: true, trackingNo: ownedTask.trackingNo }
|
||||
const context = contextFor({
|
||||
[`${base}/carriers`]: carriers,
|
||||
[`${base}?page=1&size=20`]: { records: [{ query: task, expired: false }], page: 1, size: 20, total: 1, pages: 1 },
|
||||
[`${base}/${ownedTask.id}`]: { query: { query: ownedTask, expired: false }, nodes: [node], exceptions: [exception], histories: [history] },
|
||||
[`${base}/${ownedTask.id}/manual-nodes`]: { query: { query: { ...ownedTask, version: 7 }, expired: false },
|
||||
nodes: [node, manualNode], exceptions: [exception], histories: [history] },
|
||||
[`${base}/${ownedTask.id}/history`]: [history],
|
||||
}, { phase3CarrierScheduleQuery: resource })
|
||||
|
||||
await run(context)
|
||||
|
||||
assert.deepEqual(context.calls.map((item) => item.method), ['GET', 'GET', 'GET', 'POST', 'GET'])
|
||||
const write = context.calls.find((item) => item.method === 'POST')
|
||||
assert.equal(write.path, `${base}/${ownedTask.id}/manual-nodes`)
|
||||
assert.equal(write.body.expectedVersion, ownedTask.version)
|
||||
assert.equal(write.body.actualAt, null)
|
||||
assert.equal(write.headers['Idempotency-Key'], `T-PHASE4-carrier-manual-${ownedTask.id}`)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user