优化
This commit is contained in:
@@ -7,12 +7,12 @@ import { prepareTerminalDrayage, run } from './phase5-terminal-drayage.mjs'
|
||||
|
||||
const source = await readFile(fileURLToPath(new URL('./phase5-terminal-drayage.mjs', import.meta.url)), 'utf8')
|
||||
|
||||
test('four real command payloads mutate contract fields and preserve remarks and state on conflict', async () => {
|
||||
test('three real command payloads mutate contract fields and preserve remarks and state on conflict', async () => {
|
||||
const marker = 'offline-terminal'
|
||||
const containerBookingId = '9223372036854775806'
|
||||
const containerNo = 'TEST0000001'
|
||||
const actions = ['SELECT_FLEET', 'SCHEDULE_PICKUP', 'RECORD_PICKUP', 'RECORD_EMPTY_RETURN']
|
||||
const paths = ['fleet', 'pickup-appointment', 'pickup', 'empty-return']
|
||||
const actions = ['SELECT_FLEET', 'SCHEDULE_PICKUP', 'RECORD_EMPTY_RETURN']
|
||||
const paths = ['fleet', 'pickup-appointment', 'empty-return']
|
||||
let state = { containerBookingId, containerNo, version: 0, allowedActions: ['SELECT_FLEET'] }
|
||||
const history = []
|
||||
const commands = new Map()
|
||||
@@ -59,20 +59,19 @@ test('four real command payloads mutate contract fields and preserve remarks and
|
||||
state = { ...state, version: state.version + 1 }
|
||||
if (index === 0) Object.assign(state, { fleetSupplierId: body.fleetSupplierId, fleetSupplierName: body.fleetSupplierName, allowedActions: ['SCHEDULE_PICKUP'] })
|
||||
if (index === 1) state.pickupAppointmentAt = body.pickupAppointmentAt
|
||||
if (index === 2) Object.assign(state, { status: 'PICKED_UP', actualPickupAt: body.actualAt, allowedActions: [] })
|
||||
if (index === 3) Object.assign(state, { status: 'EMPTY_RETURNED', actualEmptyReturnAt: body.actualAt, allowedActions: [], emptyReturnWarning: { status: 'RESOLVED' } })
|
||||
if (index === 2) Object.assign(state, { status: 'EMPTY_RETURNED', actualEmptyReturnAt: body.actualAt, allowedActions: [], emptyReturnWarning: { status: 'RESOLVED' } })
|
||||
history.push({ action: actions[index], fromVersion: index, toVersion: index + 1, reason: body[field] })
|
||||
commands.set(key, { body: structuredClone(body), state: structuredClone(state) })
|
||||
return response(state)
|
||||
},
|
||||
}
|
||||
await prepareTerminalDrayage(context, producer)
|
||||
state = { ...state, status: 'UNLOADED', unloadingCompletedAt: '2026-09-09T04:00:00', allowedActions: ['RECORD_EMPTY_RETURN'] }
|
||||
state = { ...state, status: 'UNLOADED', unloadingCompletedAt: '2026-09-09T04:00:00', actualPickupAt: '2026-09-09T04:00:00', allowedActions: ['RECORD_EMPTY_RETURN'] }
|
||||
await run(context)
|
||||
assert.equal(commands.size, 4)
|
||||
assert.equal(replays, 4)
|
||||
assert.equal(conflicts, 4)
|
||||
assert.equal(state.version, 4)
|
||||
assert.equal(commands.size, 3)
|
||||
assert.equal(replays, 3)
|
||||
assert.equal(conflicts, 3)
|
||||
assert.equal(state.version, 3)
|
||||
assert.equal(context.createdResources.phase5TerminalDrayage.finalStatus, 'EMPTY_RETURNED')
|
||||
})
|
||||
|
||||
@@ -90,7 +89,7 @@ test('terminal drayage prepares pickup before unloading and finalizes return bef
|
||||
|
||||
test('module uses only public business endpoints and reuses public trucking master data', () => {
|
||||
for (const path of [
|
||||
'/api/platform/v1/terminal-drayages', "'fleet'", "'pickup-appointment'", "'pickup'", "'empty-return'", '/history',
|
||||
'/api/platform/v1/terminal-drayages', "'fleet'", "'pickup-appointment'", "'empty-return'", '/history',
|
||||
'category=TRUCKING',
|
||||
]) assert.ok(source.includes(path), `missing ${path}`)
|
||||
assert.doesNotMatch(source, /\/internal\//)
|
||||
@@ -98,11 +97,11 @@ test('module uses only public business endpoints and reuses public trucking mast
|
||||
assert.match(source, /脚本不临时创建主数据/)
|
||||
})
|
||||
|
||||
test('all four commands cover idempotent replay hash conflict and lifecycle semantics', () => {
|
||||
test('all three commands cover idempotent replay hash conflict and lifecycle semantics', () => {
|
||||
for (const token of [
|
||||
'选择车队', '预约提柜', '确认实际提柜', '确认实际还柜',
|
||||
'同键重放', '同键异载荷返回A0409', 'PICKED_UP', 'UNLOADED', 'EMPTY_RETURNED',
|
||||
'SELECT_FLEET', 'SCHEDULE_PICKUP', 'RECORD_PICKUP', 'RECORD_EMPTY_RETURN', 'RESOLVED',
|
||||
'选择车队', '预约提柜', '确认实际还柜',
|
||||
'同键重放', '同键异载荷返回A0409', 'UNLOADED', 'EMPTY_RETURNED',
|
||||
'SELECT_FLEET', 'SCHEDULE_PICKUP', 'RECORD_EMPTY_RETURN', 'RESOLVED',
|
||||
]) assert.ok(source.includes(token), `missing ${token}`)
|
||||
assert.match(source, /JSON\.stringify\(replay\.data\) === JSON\.stringify\(first\.data\)/)
|
||||
assert.match(source, /terminal-\$\{path\}.*replace\(\/\[\^A-Za-z0-9:_-\]\//)
|
||||
|
||||
Reference in New Issue
Block a user