Files
pda-uniapp/tests/user-facing-identifiers.test.mjs
2026-08-31 17:10:46 +08:00

50 lines
2.6 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from 'node:test'
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import { containerReference, displayBusinessValue, formatApiError, sanitizeUserMessage } from '../utils/user-facing.js'
const read = (path) => readFile(new URL(path, import.meta.url), 'utf8')
test('PDA task labels prefer the container number and only fall back to the cabinet number', () => {
assert.equal(displayBusinessValue(null), '—')
assert.equal(displayBusinessValue('', '未关联'), '未关联')
assert.equal(containerReference({ currentContainerNo: 'TSTU0000760', cabinetNo: 'CAB-260830-0008', orderNo: 'FL-1' }), '集装箱号 TSTU0000760')
assert.equal(containerReference({ currentContainerNo: '', boxNo: 'TSTU0000708', cabinetNo: 'CAB-260829-0037' }), '集装箱号 TSTU0000708')
assert.equal(containerReference({ cabinetNo: 'CAB-260830-0008', taskId: '2092889048731414530' }), '柜次号 CAB-260830-0008')
assert.equal(containerReference({ boxNo: '同步中', cabinetNo: 'CAB-260830-0008' }), '柜次号 CAB-260830-0008')
assert.equal(containerReference({ taskId: '2092889048731414530', orderId: '2092889048731414531' }), '集装箱号 —')
})
test('operator errors hide internal ids but retain request and trace evidence', () => {
const error = {
message: 'taskId: 2092889048731414530 对应 loadingPlanId=2092889048731414531 处理失败',
code: 'S0500',
requestId: 'dbde0d81-7798-4d22-a12e-1731d7ec9bb1',
traceId: '5b0ba4f3ed5236b34997dd82162a5138'
}
const message = formatApiError(error, '任务处理失败')
assert.doesNotMatch(message, /209288904873141453[01]|taskId|loadingPlanId/)
assert.match(message, /错误码:S0500/)
assert.match(message, /requestId:dbde0d81/)
assert.match(message, /traceId:5b0ba4f3/)
assert.equal(sanitizeUserMessage('operation 2092889048731414530 failed'), 'operation 内部标识已隐藏 failed')
})
test('priority PDA templates do not interpolate internal ids', async () => {
const pages = await Promise.all([
read('../pages/login/login.vue'),
read('../pages/tasks/tasks.vue'),
read('../pages/picking/picking.vue'),
read('../pages/history/history.vue')
])
for (const page of pages) {
const template = page.match(/<template>[\s\S]*?<\/template>/)?.[0] || ''
assert.doesNotMatch(template, /\{\{[^}\n]*(?:taskId|inboundId|orderId|loadingPlanId|containerBookingId)[^}\n]*\}\}/)
assert.doesNotMatch(template, /订单号|入仓码|业务编号未关联/)
}
assert.match(pages[0], /formatApiError\(error, '登录失败'\)/)
assert.match(pages[1], /containerReference\(task\)/)
assert.match(pages[2], /containerReference\(currentBox\)/)
assert.match(pages[3], /containerReference\(entry\.box\)/)
})