- 库存抵扣成本按目标抵扣量幂等更新,作废/退货清 cover_qty;多批次展示按加权均价;商品成本排行纳入库存抵扣成本并改标签为“成本” - 主系统事件:allocated 定向 order_code、returned 等批量状态核对、clamped/全量兜底下调频、失败不计 applied - 订单完成:零价闸门排除已退货行;供应商系统关闭“主数据不卡流程”入口与执行接口 - 迁移 20261080/20261081;补充相关契约/回归测试
50 lines
1.7 KiB
TypeScript
50 lines
1.7 KiB
TypeScript
import { describe, expect, it, vi, beforeEach } from 'vitest';
|
|
|
|
const query = vi.fn();
|
|
|
|
vi.mock('../src/db', () => ({
|
|
pool: { query: (...args: unknown[]) => query(...args) },
|
|
}));
|
|
|
|
import { assertNoZeroPriceItems, countZeroPriceItems } from '../src/services/orderZeroPriceGuard';
|
|
|
|
describe('orderZeroPriceGuard', () => {
|
|
beforeEach(() => {
|
|
query.mockReset();
|
|
});
|
|
|
|
it('countZeroPriceItems reads cnt', async () => {
|
|
query.mockResolvedValueOnce({ rows: [{ cnt: 2 }] });
|
|
await expect(countZeroPriceItems('ORD1')).resolves.toBe(2);
|
|
});
|
|
|
|
it('零价统计排除已退回行(退货行 price 会被清 0,不应拦整单收口)', async () => {
|
|
query.mockResolvedValueOnce({ rows: [{ cnt: 0 }] });
|
|
await countZeroPriceItems('ORD1');
|
|
expect(String(query.mock.calls[0][0])).toContain('COALESCE(is_returned, false) = false');
|
|
});
|
|
|
|
it('assertNoZeroPriceItems passes when count 0', async () => {
|
|
query.mockResolvedValueOnce({ rows: [{ cnt: 0 }] });
|
|
await expect(assertNoZeroPriceItems('ORD1')).resolves.toBeUndefined();
|
|
});
|
|
|
|
it('assertNoZeroPriceItems blocks when count > 0', async () => {
|
|
query
|
|
.mockResolvedValueOnce({ rows: [{ cnt: 1 }] })
|
|
.mockResolvedValueOnce({
|
|
rows: [{ item_name: '青椒', sku_code: 'SKU1', quantity: 2, unit: '斤' }],
|
|
});
|
|
await expect(assertNoZeroPriceItems('ORD1', undefined, false, '分配')).rejects.toMatchObject({
|
|
code: 'zero_price_blocked',
|
|
status: 409,
|
|
zero_price_count: 1,
|
|
});
|
|
});
|
|
|
|
it('assertNoZeroPriceItems skips when allowUnpriced', async () => {
|
|
await expect(assertNoZeroPriceItems('ORD1', undefined, true)).resolves.toBeUndefined();
|
|
expect(query).not.toHaveBeenCalled();
|
|
});
|
|
});
|