- storage.stockout.confirm 出站回传改为按 source_type 分流(复用 order_async.js 既有分流实现): QM→奇门 taobao.qimen.stockout.confirm;API→OpenAPI 回调 stockout.confirm(appKey 按货主合约 反查 wms_store_warehouse(auth_status=2) + wms_api_app(启用且 callback_url 非空)); WMS 等内部来源无需外部通知、直接视为成功。修复此前 API 来源出库单被硬编码发往奇门、 遭「-1 无法匹配货主」拒绝后无法确认(跳过出站同样走失败分支)的问题。 - storage.stockout.confirm 运单号校验与回传改为以复数 waybill_codes 为准(对齐奇门 packages.package[].expressCode 多运单模型,不使用 deliveryOrder.expressCode); 单数 waybill_code 已弃用,仅在复数缺失时回退单数兼容存量单;失败文案改为 (waybill_codes)。 - storage.stockout.updateExpress 以 waybill_codes 为准,单数 waybill_code 降级为镜像字段 (传非空复数时镜像首个、传空数组/null 时同步置 NULL、同时传两列时复数优先); 仅传单数的旧调用方行为不变。 - app/service/systems/order_async.js 新增 3 个可复用实例方法(buildStockoutConfirmRequest / notifyStockoutExternal / resolveOpenApiAppByStore),薄封装既有模块级实现, 未改动原函数及其既有调用方。 - 新增回归测试:stockout.confirm.outbound.test.js(8 条,覆盖 API/QM/WMS 三路来源、多运单复数 回传、存量单单数回退)、stockout.updateExpress.test.js(7 条,覆盖复数镜像与兼容行为)。 - 同步 methods/system.json 与 methods/changes/system.json(storage.stockout.confirm / storage.stockout.updateExpress)。
162 lines
4.8 KiB
JavaScript
162 lines
4.8 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const StorageStockoutService = require('../../../../../app/service/systemMethods/storage/stockout');
|
|
|
|
/**
|
|
* 构造 storage.stockout.updateExpress 测试桩。
|
|
*
|
|
* 重点覆盖「单数 waybill_code 已弃用、以复数 waybill_codes 为准」的镜像写入口径。
|
|
*
|
|
* @param {Object} [options] 可选配置。
|
|
* @param {Map<string, Object>} [options.expressMap] 系统快递表映射(编码 → { name })。
|
|
* @return {Object} 服务实例与写入记录。
|
|
*/
|
|
function createHarness(options = {}) {
|
|
const writes = [];
|
|
const warnLogs = [];
|
|
|
|
const order = {
|
|
id: 24,
|
|
stockout_order_code: 'CK_3',
|
|
express_code: null,
|
|
express_name: null,
|
|
waybill_code: null,
|
|
waybill_codes: null,
|
|
async update(values) {
|
|
writes.push(values);
|
|
Object.assign(this, values);
|
|
},
|
|
async reload() {
|
|
// 无需实现:仅保证 updateExpress 内的 reload 调用可用
|
|
},
|
|
};
|
|
|
|
const expressMap = options.expressMap || new Map([
|
|
[ 'ZT', { name: '自提' }],
|
|
[ 'SF', { name: '顺丰速运' }],
|
|
]);
|
|
|
|
const ctx = {
|
|
app: { config: {} },
|
|
model: {
|
|
OrderStockout: {
|
|
async findByPk() {
|
|
return order;
|
|
},
|
|
},
|
|
},
|
|
service: {
|
|
systems: {
|
|
setting: {
|
|
express: {
|
|
async getSystemExpressMap() {
|
|
return expressMap;
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
logger: {
|
|
info() {},
|
|
warn(message) {
|
|
warnLogs.push(String(message));
|
|
},
|
|
error() {},
|
|
},
|
|
};
|
|
|
|
return {
|
|
order,
|
|
service: new StorageStockoutService(ctx),
|
|
writes,
|
|
warnLogs,
|
|
};
|
|
}
|
|
|
|
describe('test/app/service/systemMethods/storage/stockout.updateExpress.test.js', () => {
|
|
it('传复数 waybill_codes 时以复数为准,并镜像单数 waybill_code 为首个', async () => {
|
|
const harness = createHarness();
|
|
|
|
const result = await harness.service.updateExpress({
|
|
id: 24,
|
|
express_code: 'ZT',
|
|
waybill_codes: [ 'WB-A', 'WB-B' ],
|
|
});
|
|
|
|
assert.equal(result.flag, 'success');
|
|
assert.deepEqual(harness.writes.length, 1);
|
|
const write = harness.writes[0];
|
|
assert.deepEqual(write.waybill_codes, [ 'WB-A', 'WB-B' ]);
|
|
assert.equal(write.waybill_code, 'WB-A', '单数列应镜像为复数首个');
|
|
assert.equal(write.express_code, 'ZT');
|
|
assert.equal(write.express_name, '自提');
|
|
assert.equal(result.waybill_code, 'WB-A');
|
|
assert.deepEqual(result.waybill_codes, [ 'WB-A', 'WB-B' ]);
|
|
});
|
|
|
|
it('传 waybill_codes 为空数组时单数镜像为 null', async () => {
|
|
const harness = createHarness();
|
|
|
|
const result = await harness.service.updateExpress({ id: 24, waybill_codes: [] });
|
|
|
|
assert.equal(result.flag, 'success');
|
|
assert.deepEqual(harness.writes[0].waybill_codes, []);
|
|
assert.equal(harness.writes[0].waybill_code, null);
|
|
});
|
|
|
|
it('传 waybill_codes 为 null 时两列同时清空', async () => {
|
|
const harness = createHarness();
|
|
|
|
const result = await harness.service.updateExpress({ id: 24, waybill_codes: null });
|
|
|
|
assert.equal(result.flag, 'success');
|
|
assert.equal(harness.writes[0].waybill_codes, null);
|
|
assert.equal(harness.writes[0].waybill_code, null);
|
|
});
|
|
|
|
it('复数优先:同时传单数与复数时以复数首个覆盖单数', async () => {
|
|
const harness = createHarness();
|
|
|
|
const result = await harness.service.updateExpress({
|
|
id: 24,
|
|
waybill_code: 'OLD-WB',
|
|
waybill_codes: [ 'NEW-WB-1', 'NEW-WB-2' ],
|
|
});
|
|
|
|
assert.equal(result.flag, 'success');
|
|
assert.equal(harness.writes[0].waybill_code, 'NEW-WB-1');
|
|
assert.deepEqual(harness.writes[0].waybill_codes, [ 'NEW-WB-1', 'NEW-WB-2' ]);
|
|
});
|
|
|
|
it('兼容:仅传单数 waybill_code 时行为不变(写入单数)', async () => {
|
|
const harness = createHarness();
|
|
|
|
const result = await harness.service.updateExpress({ id: 24, waybill_code: 'ONLY-SINGLE' });
|
|
|
|
assert.equal(result.flag, 'success');
|
|
assert.equal(harness.writes[0].waybill_code, 'ONLY-SINGLE');
|
|
assert.equal(harness.writes[0].waybill_codes, undefined);
|
|
});
|
|
|
|
it('waybill_codes 非数组时返回 400 且不写入', async () => {
|
|
const harness = createHarness();
|
|
|
|
const result = await harness.service.updateExpress({ id: 24, waybill_codes: 'WB-A' });
|
|
|
|
assert.equal(result.flag, 'failure');
|
|
assert.match(result.message, /必须是数组或 null/);
|
|
assert.equal(harness.writes.length, 0);
|
|
});
|
|
|
|
it('三个字段都未传时返回「没有需要更新的字段」', async () => {
|
|
const harness = createHarness();
|
|
|
|
const result = await harness.service.updateExpress({ id: 24 });
|
|
|
|
assert.equal(result.flag, 'failure');
|
|
assert.match(result.message, /没有需要更新的字段/);
|
|
assert.equal(harness.writes.length, 0);
|
|
});
|
|
});
|