GuDingZiChan/print-agent/tests/job-processor.test.mjs
WuYongJie 0dc3c09315 feat(资产与打印): 提交近期借还盘点与打印助手源码
- 提交借用单缺失异常处理、扫码借还搜索与站内消息快捷处理源码
- 提交盘点范围、多终端打印、组织同步与认证模式相关源码
- 提交 .NET/Node 打印助手及版本清单源码
2026-03-27 20:18:31 +08:00

97 lines
2.5 KiB
JavaScript

import test from 'node:test'
import assert from 'node:assert/strict'
import { createJobProcessor } from '../src/services/jobProcessor.js'
test('正式资产标签任务会调用真实打印执行器并返回 completed', async () => {
const printedJobs = []
const processor = createJobProcessor({
async printAssetLabels(payload) {
printedJobs.push(payload)
return {
printed_count: payload.items.length
}
}
})
const result = await processor.process({
id: 21,
job_type: 'asset_label',
payload: {
job_type: 'asset_label',
equipment_ids: [1],
items: [
{
id: 1,
equipment_code: 'JS-PC-2101',
equipment_name: '办公主机',
equipment_type: '主机',
purchase_date: '2026-03-01T00:00:00.000Z',
department: {
name: '行政部'
}
}
]
}
}, {
selectedPrinterName: 'Xprinter XP-420B'
})
assert.equal(result.ok, true)
assert.equal(result.nextStatus, 'completed')
assert.match(result.message, /Xprinter XP-420B/)
assert.equal(printedJobs.length, 1)
assert.equal(printedJobs[0].printerName, 'Xprinter XP-420B')
assert.equal(printedJobs[0].items[0].equipment_code, 'JS-PC-2101')
})
test('未选择打印机时会返回人话错误,不会继续打印', async () => {
const processor = createJobProcessor({
async printAssetLabels() {
throw new Error('不应该进入真实打印')
}
})
const result = await processor.process({
id: 22,
job_type: 'asset_label',
payload: {
job_type: 'asset_label',
equipment_ids: [1],
items: [
{
id: 1,
equipment_code: 'JS-PC-2201',
equipment_name: '办公主机',
equipment_type: '主机'
}
]
}
})
assert.equal(result.ok, false)
assert.equal(result.nextStatus, 'failed')
assert.match(result.errorMessage, /尚未选择标签打印机/)
})
test('测试打印会调用真实测试标签打印执行器', async () => {
const calls = []
const processor = createJobProcessor({
async printTestLabel(payload) {
calls.push(payload)
return {
printer_name: payload.printerName
}
}
})
const result = await processor.runTestPrint({
selectedPrinterName: 'Xprinter XP-420B'
})
assert.equal(result.ok, true)
assert.match(result.message, /Xprinter XP-420B/)
assert.equal(calls.length, 1)
assert.equal(calls[0].printerName, 'Xprinter XP-420B')
})