WMS_MAIN/test/app/service/systems/delivery_order.auditStatus.test.js
liufumingren e73a311076 ok
2026-04-11 17:09:06 +08:00

100 lines
3.4 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('node:assert/strict');
const { app, mm } = require('egg-mock/bootstrap');
describe('test/app/service/systems/delivery_order.auditStatus.test.js', () => {
let ctx;
let deliveryOrderService;
/**
* Mock StoreWarehouse.findOne,兼容固定返回值或函数实现。
*
* @param {Function|any} implOrValue mock 实现或返回值。
*/
function mockStoreWarehouseFindOne(implOrValue) {
const findOneImpl = typeof implOrValue === 'function'
? implOrValue
: async () => implOrValue;
mm(ctx, 'model', {
StoreWarehouse: {
findOne: findOneImpl,
},
});
}
beforeEach(() => {
ctx = app.mockContext();
deliveryOrderService = ctx.service.systems.deliveryOrder;
});
afterEach(() => {
mm.restore();
});
it('should resolveOrderStep return 0 when need_order_approval is 1', async () => {
const info = { storeId: 1000000, warehouseId: 100000 };
mockStoreWarehouseFindOne(async () => ({ id: 1 }));
mm(ctx.service.systems.storeWarehouse, 'getEffectivePolicyConfigByContractId', async () => ({ need_order_approval: 1 }));
const step = await deliveryOrderService.resolveOrderStep(info, null);
assert.equal(step, 0);
});
it('should resolveOrderStep return 1 when need_order_approval is 0', async () => {
const info = { storeId: 1000000, warehouseId: 100000 };
mockStoreWarehouseFindOne(async () => ({ id: 1 }));
mm(ctx.service.systems.storeWarehouse, 'getEffectivePolicyConfigByContractId', async () => ({ need_order_approval: 0 }));
const step = await deliveryOrderService.resolveOrderStep(info, null);
assert.equal(step, 1);
});
it('should resolveOrderStep return 0 when relation not found', async () => {
const info = { storeId: 1, warehouseId: 2 };
mockStoreWarehouseFindOne(async () => null);
const step = await deliveryOrderService.resolveOrderStep(info, null);
assert.equal(step, 0);
});
it('should resolveOrderStep return 1 when policy_config is missing', async () => {
const info = { storeId: 1000000, warehouseId: 100000 };
mockStoreWarehouseFindOne(async () => ({ id: 1 }));
mm(ctx.service.systems.storeWarehouse, 'getEffectivePolicyConfigByContractId', async () => null);
const step = await deliveryOrderService.resolveOrderStep(info, null);
assert.equal(step, 1);
});
it('should prepareOrderData include step', async () => {
const deliveryOrder = {
deliveryOrderCode: 'TEST_ORDER_001',
sourcePlatformCode: 'TAOBAO',
receiverInfo: { name: 'test' },
};
const info = {
storeId: 1000000,
warehouseId: 100000,
};
// Mock platform check
mm(ctx.service.systems.platform, 'checkPlatformExists', async (platformCode, warehouseId) => {
if (platformCode === 'TAOBAO' && warehouseId === 100000) {
return { code: 'TAOBAO', name: '淘宝' };
}
return null;
});
// 1. Test with step = 0
const preparedDataPending = await deliveryOrderService.prepareOrderData(deliveryOrder, info, 0);
assert.ok(preparedDataPending, 'preparedDataPending should not be null');
assert.equal(preparedDataPending.step, 0, 'step should be 0');
// 2. Test with step = 1
const preparedDataApproved = await deliveryOrderService.prepareOrderData(deliveryOrder, info, 1);
assert.ok(preparedDataApproved, 'preparedDataApproved should not be null');
assert.equal(preparedDataApproved.step, 1, 'step should be 1');
});
});