fix(pda): preserve packing plan retry keys and surface missing API
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { findPackingOrders, getReturnCartonLabel, mergeReturnCartons, normalizePackingPreview } from '../src/api/return-packing.js'
|
||||
import { findPackingOrders, getReturnCartonLabel, listReturnPackingPlans, mergeReturnCartons, normalizePackingPreview } from '../src/api/return-packing.js'
|
||||
import { session } from '../src/stores/session.js'
|
||||
|
||||
test('packing preview keeps customer scope internal and exposes stable order references', () => {
|
||||
@@ -40,3 +40,11 @@ test('return packing lookup still rejects real service errors', async () => {
|
||||
globalThis.uni = { request(options) { options.success({ statusCode: 500, data: { code: 'B0500', message: '服务暂不可用' }, header: {} }) } }
|
||||
await assert.rejects(() => findPackingOrders('RT-1'), (error) => error.code === 'B0500')
|
||||
})
|
||||
|
||||
test('plan list distinguishes an empty success from a missing API and preserves diagnostics', async () => {
|
||||
session.apiBase = '/api'; session.token = 'packing-token'
|
||||
globalThis.uni = { request(options) { options.success({ statusCode: 200, data: { code: '200', data: [] }, header: {} }) } }
|
||||
assert.deepEqual(await listReturnPackingPlans(), [])
|
||||
globalThis.uni = { request(options) { options.success({ statusCode: 404, data: { code: 'A0404', message: '计划接口不存在', requestId: 'missing-plan-api' }, header: {} }) } }
|
||||
await assert.rejects(() => listReturnPackingPlans(), error => error.code === 'A0404' && error.requestId === 'missing-plan-api')
|
||||
})
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import vm from 'node:vm'
|
||||
|
||||
function setup(merge) {
|
||||
const saved = new Map()
|
||||
const context = vm.createContext({ reactive: value => value, PortalHeader: {}, ScanTargetInput: {},
|
||||
playSuccessSound() {}, playErrorSound() {}, mergeReturnPackingPlan: merge,
|
||||
uni: { setStorageSync: (key, value) => saved.set(key, structuredClone(value)), getStorageSync: key => saved.get(key), removeStorageSync: key => saved.delete(key) } })
|
||||
const store = readFileSync(new URL('../src/stores/warehouse-work.js', import.meta.url), 'utf8')
|
||||
vm.runInContext(store.replace(/^import .*$/mg, '').replace(/export /g, ''), context)
|
||||
const source = readFileSync(new URL('../src/pages/return-packing/return-packing.vue', import.meta.url), 'utf8')
|
||||
const script = source.match(/<script[^>]*>([\s\S]*?)<\/script>/)[1]
|
||||
const component = vm.runInContext(script.replace(/^\s*import .*$/mg, '').replace('export default', 'globalThis.component ='), context)
|
||||
vm.runInContext("restoreWarehouseWork('operator:warehouse')", context)
|
||||
const page = Object.assign({}, component.methods, { canCompletePlan: true, busy: false,
|
||||
activePlan: { planNo: 'PLAN-1' }, planBoxes: [{ items: [{ skuCode: ' SKU-1 ', quantity: '2' }], length: 10, width: 20, height: 30, weight: 1 }],
|
||||
async loadPlans() {} })
|
||||
return { page, restore: scope => vm.runInContext(`restoreWarehouseWork(${JSON.stringify(scope)})`, context),
|
||||
keys: () => vm.runInContext('warehouseWork.returnPackingPlan.pendingKeys', context) }
|
||||
}
|
||||
|
||||
test('plan completion reaches API and preserves the key across lost responses and draft restore', async () => {
|
||||
const calls = []; let fail = true
|
||||
const fixture = setup(async (plan, payload) => { calls.push({ plan, payload }); if (fail) throw new Error('response lost'); return { labels: [] } })
|
||||
await fixture.page.completePlan()
|
||||
assert.equal(calls.length, 1)
|
||||
assert.equal(fixture.page.error.message, 'response lost')
|
||||
assert.equal(fixture.page.busy, false)
|
||||
fixture.restore('operator:warehouse')
|
||||
fail = false
|
||||
await fixture.page.completePlan()
|
||||
assert.equal(calls.length, 2)
|
||||
assert.equal(calls[0].payload.idempotencyKey, calls[1].payload.idempotencyKey)
|
||||
assert.equal(calls[1].payload.boxes[0].items[0].skuCode, 'SKU-1')
|
||||
assert.equal(fixture.page.activePlan, null)
|
||||
assert.equal(Object.keys(fixture.keys()).length, 0)
|
||||
})
|
||||
|
||||
test('plan completion keys are not reused by another operator or warehouse', async () => {
|
||||
const keys = []
|
||||
const fixture = setup(async (_plan, payload) => { keys.push(payload.idempotencyKey); throw new Error('response lost') })
|
||||
await fixture.page.completePlan()
|
||||
fixture.restore('other-operator:warehouse')
|
||||
await fixture.page.completePlan()
|
||||
assert.equal(keys.length, 2)
|
||||
assert.notEqual(keys[0], keys[1])
|
||||
})
|
||||
Reference in New Issue
Block a user