179 lines
5.1 KiB
JavaScript
179 lines
5.1 KiB
JavaScript
'use strict';
|
|
|
|
const assert = require('node:assert/strict');
|
|
const WaveService = require('../../../../../app/service/systemMethods/order/wave');
|
|
|
|
/**
|
|
* 创建 batchRemoveExceptionOrders 轻量测试上下文。
|
|
*
|
|
* @return {{ service: WaveService, cacheStore: Map<string, any>, capture: Object }} 服务实例、缓存与调用记录。
|
|
*/
|
|
function createHarness() {
|
|
const cacheStore = new Map();
|
|
const capture = {
|
|
removePayload: null,
|
|
};
|
|
|
|
const ctx = {
|
|
app: {
|
|
config: {},
|
|
async setCacheAsync(key, value) {
|
|
cacheStore.set(key, value);
|
|
},
|
|
async getCacheAsync(key) {
|
|
return cacheStore.get(key) || null;
|
|
},
|
|
},
|
|
user: {
|
|
store_id: 100000,
|
|
},
|
|
logger: {
|
|
info() {},
|
|
warn() {},
|
|
error() {},
|
|
},
|
|
model: {},
|
|
};
|
|
|
|
const service = new WaveService(ctx);
|
|
|
|
return {
|
|
service,
|
|
cacheStore,
|
|
capture,
|
|
};
|
|
}
|
|
|
|
describe('test/app/service/systemMethods/order/wave.batchRemoveExceptionOrders.test.js', () => {
|
|
it('should remove only pending-exception(step=3) orders when wave has mixed normal orders', async () => {
|
|
const { service, capture } = createHarness();
|
|
|
|
service.getOrderModel = async () => ({
|
|
async findAll() {
|
|
return [
|
|
{ id: 1, wave_id: 11, wave_no: 'W11', step: 3 },
|
|
{ id: 2, wave_id: 11, wave_no: 'W11', step: 2 },
|
|
{ id: 3, wave_id: 11, wave_no: 'W11', step: 1 },
|
|
];
|
|
},
|
|
});
|
|
|
|
service.batchRemoveOrders = async payload => {
|
|
capture.removePayload = payload;
|
|
return service.success('ok', {
|
|
removed_order_ids: [ 1 ],
|
|
removed_order_count: 1,
|
|
affected_wave_ids: [ 11 ],
|
|
updated_wave_ids: [ 11 ],
|
|
emptied_wave_ids: [],
|
|
});
|
|
};
|
|
|
|
await service.setBatchRemoveExceptionOrdersTaskProgress('task_1', 'submitted', {
|
|
warehouse_id: 100000,
|
|
wave_ids: '11',
|
|
wave_id_list: [ 11 ],
|
|
});
|
|
|
|
await service.runBatchRemoveExceptionOrdersTask({
|
|
taskId: 'task_1',
|
|
warehouseId: 100000,
|
|
waveIds: [ 11 ],
|
|
});
|
|
|
|
assert.deepEqual(capture.removePayload, {
|
|
ids: [ 1 ],
|
|
});
|
|
|
|
const progress = await service.getBatchRemoveExceptionOrdersTaskProgress('task_1');
|
|
assert.equal(progress.state, 'success');
|
|
assert.equal(progress.removed_order_count, 1);
|
|
assert.deepEqual(progress.result.removed_order_ids, [ 1 ]);
|
|
assert.deepEqual(progress.result.updated_wave_ids, [ 11 ]);
|
|
assert.deepEqual(progress.result.emptied_wave_ids, []);
|
|
});
|
|
|
|
it('should allow wave to become empty when all orders are pending exception', async () => {
|
|
const { service, capture } = createHarness();
|
|
|
|
service.getOrderModel = async () => ({
|
|
async findAll() {
|
|
return [
|
|
{ id: 21, wave_id: 21, wave_no: 'W21', step: 3 },
|
|
{ id: 22, wave_id: 21, wave_no: 'W21', step: 3 },
|
|
];
|
|
},
|
|
});
|
|
|
|
service.batchRemoveOrders = async payload => {
|
|
capture.removePayload = payload;
|
|
return service.success('ok', {
|
|
removed_order_ids: [ 21, 22 ],
|
|
removed_order_count: 2,
|
|
affected_wave_ids: [ 21 ],
|
|
updated_wave_ids: [],
|
|
emptied_wave_ids: [ 21 ],
|
|
});
|
|
};
|
|
|
|
await service.setBatchRemoveExceptionOrdersTaskProgress('task_all_exception', 'submitted', {
|
|
warehouse_id: 100000,
|
|
wave_ids: '21',
|
|
wave_id_list: [ 21 ],
|
|
});
|
|
|
|
await service.runBatchRemoveExceptionOrdersTask({
|
|
taskId: 'task_all_exception',
|
|
warehouseId: 100000,
|
|
waveIds: [ 21 ],
|
|
});
|
|
|
|
assert.deepEqual(capture.removePayload, {
|
|
ids: [ 21, 22 ],
|
|
});
|
|
|
|
const progress = await service.getBatchRemoveExceptionOrdersTaskProgress('task_all_exception');
|
|
assert.equal(progress.state, 'success');
|
|
assert.equal(progress.removed_order_count, 2);
|
|
assert.deepEqual(progress.result.updated_wave_ids, []);
|
|
assert.deepEqual(progress.result.emptied_wave_ids, [ 21 ]);
|
|
});
|
|
|
|
it('should mark success when no exception orders found', async () => {
|
|
const { service, capture } = createHarness();
|
|
|
|
service.getOrderModel = async () => ({
|
|
async findAll() {
|
|
return [
|
|
{ id: 11, wave_id: 31, wave_no: 'W31', step: 1, inspection_status: 'fin', intercept_status: 'none' },
|
|
{ id: 12, wave_id: 31, wave_no: 'W31', step: 2, inspection_status: 'padding', intercept_status: 'none' },
|
|
];
|
|
},
|
|
});
|
|
|
|
service.batchRemoveOrders = async payload => {
|
|
capture.removePayload = payload;
|
|
return service.success('ok', {});
|
|
};
|
|
|
|
await service.setBatchRemoveExceptionOrdersTaskProgress('task_2', 'submitted', {
|
|
warehouse_id: 100000,
|
|
wave_ids: '31',
|
|
wave_id_list: [ 31 ],
|
|
});
|
|
|
|
await service.runBatchRemoveExceptionOrdersTask({
|
|
taskId: 'task_2',
|
|
warehouseId: 100000,
|
|
waveIds: [ 31 ],
|
|
});
|
|
|
|
assert.equal(capture.removePayload, null);
|
|
|
|
const progress = await service.getBatchRemoveExceptionOrdersTaskProgress('task_2');
|
|
assert.equal(progress.state, 'success');
|
|
assert.equal(progress.removed_order_count, 0);
|
|
assert.equal(progress.result.message, '未找到可移除的异常订单');
|
|
});
|
|
});
|