oms/backend/test/app/lib/printPlatformDgj.test.js
liufumingren 7f8cff808b feat(waybill): 取号时解析并留痕打印记录ID(PrintHistoryIds)
平台 ExpressPrint 响应里有 Data.PrintHistoryIds,元素 { Id, Pid, WaybillCode,
WaybillCodeChild, BatchIndex },其中 Id 即 printHistoryId:重打/作废/查打印记录
(PrintHistory/LoadPrintData)都按它回捞。之前只用了 WaybillCode/printinfo,
这块被丢掉了。

- dgj.fetchWaybillNo 解析为 [{ id, pid, waybill_code, batch_index }]
- waybillGet 写入 waybill_fetch_records.print_history_ids(JSON 数组,多包裹对齐)
- 仅本地留痕,不改回 WMS 的响应契约
- 迁移 20261107030000 加列;单测覆盖真实响应样例与多包裹/缺失字段

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
2026-11-07 06:26:46 +08:00

78 lines
3.1 KiB
JavaScript
Raw 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.

'use strict';
const { assert } = require('egg-mock/bootstrap');
const DgjService = require('../../../app/lib/printPlatform/dgj');
describe('printPlatform/dgj isOrderFinished', () => {
const base = { ErpState: 'waitsellersend', PrintState: 0, LogisticStatus: 0, WaybillCodes: [] };
it('ErpState 为 sended / success / close 时判定为已处理', () => {
for (const state of [ 'sended', 'success', 'close', 'SENDED', 'Closed' ]) {
assert.strictEqual(DgjService.isOrderFinished({ ...base, ErpState: state }), true, state);
}
});
it('待发货且没有任何发货证据时保留(需要处理)', () => {
assert.strictEqual(DgjService.isOrderFinished(base), false);
});
it('有 OnlineSendTime 时判定为已发货', () => {
assert.strictEqual(DgjService.isOrderFinished({ ...base, OnlineSendTime: '2026-11-02 10:00:00' }), true);
});
it('面单包裹 IsSended=true 时判定为已发货', () => {
assert.strictEqual(
DgjService.isOrderFinished({ ...base, WaybillCodes: [{ WaybillCode: '770', IsSended: false }, { WaybillCode: '771', IsSended: true }] }),
true
);
});
it('LogisticStatus > 0 时判定为已发货', () => {
assert.strictEqual(DgjService.isOrderFinished({ ...base, LogisticStatus: 2 }), true);
});
it('只打印了面单、未发货(PrintState=1 且有 ExpressPrintTime)时仍需要处理', () => {
assert.strictEqual(
DgjService.isOrderFinished({ ...base, PrintState: 1, ExpressPrintTime: '2026-11-02 10:00:00' }),
false
);
});
it('状态字段缺失时不误判', () => {
assert.strictEqual(DgjService.isOrderFinished({}), false);
assert.strictEqual(DgjService.isOrderFinished(null), false);
});
});
describe('printPlatform/dgj extractPrintHistoryIds', () => {
it('解析真实 ExpressPrint 响应的 PrintHistoryIds(打印记录ID)', () => {
const printed = {
Data: {
PrintHistoryIds: [
{ Id: 10000078656002, Pid: '3316997317085033076', WaybillCode: '9823617121121', WaybillCodeChild: null, BatchIndex: 1 },
],
WaybillCode: [{ WaybillCode: '9823617121121', WaybillCodeId: 10000298258339 }],
},
};
const list = DgjService.extractPrintHistoryIds(printed);
console.log('打印记录:', JSON.stringify(list));
assert.deepStrictEqual(list, [
{ id: '10000078656002', pid: '3316997317085033076', waybill_code: '9823617121121', batch_index: 1 },
]);
});
it('多包裹按顺序返回,缺失数据不炸', () => {
const printed = { Data: { PrintHistoryIds: [{ Id: 1, Pid: 'a', WaybillCode: 'W1', BatchIndex: 1 }, { Id: 2, WaybillCode: 'W2' }, null, {}] } };
const list = DgjService.extractPrintHistoryIds(printed);
assert.deepStrictEqual(list, [
{ id: '1', pid: 'a', waybill_code: 'W1', batch_index: 1 },
{ id: '2', pid: '', waybill_code: 'W2', batch_index: null },
]);
});
it('没有该字段时返回空数组', () => {
assert.deepStrictEqual(DgjService.extractPrintHistoryIds({ Data: {} }), []);
assert.deepStrictEqual(DgjService.extractPrintHistoryIds(null), []);
});
});