来源仓库:jxc/ai-fresh-delivery 来源提交:f0b1a180e2deb7e4673b9d1c8542619f7bc0f73d 快照树: 09f679334ff38f0ff25e907961c94a8223bcaedd(与来源 HEAD 工作树逐字节一致,3801 个文件) 按约定本仓库不带任何历史提交:来源仓库的历史中含真实凭据 (生产 SSH 私钥 deploy/id_rsa_tencent、server/.env、.env.tencent/.env.production/.env.gitea、 deploy/小程序AppSecret.txt,其中 MP_APPSECRET / S3 AccessKey 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
612 lines
20 KiB
TypeScript
612 lines
20 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
vi.mock('../src/services/orderPricingService', () => ({
|
|
calcItemAmount: (qty: number, price: number) => Math.round(qty * price * 100) / 100,
|
|
resolveSkuSalePriceForUnitChange: vi.fn(async () => 4),
|
|
unitsEquivalent: (a: string, b: string) => {
|
|
const key = (u: string) => {
|
|
const raw = String(u || '').trim().toLowerCase();
|
|
if (raw === '斤' || raw === '市斤' || raw === 'jin') return '斤';
|
|
if (raw === '公斤' || raw === '千克' || raw === 'kg' || raw === 'kilo') return '公斤';
|
|
return String(u || '').trim();
|
|
};
|
|
const left = key(a);
|
|
const right = key(b);
|
|
return Boolean(left) && left === right;
|
|
},
|
|
}));
|
|
|
|
vi.mock('../src/services/unitConversionService', () => ({
|
|
loadWeightUnitFactors: vi.fn(async () => new Map()),
|
|
sumWeightInJin: () => 0,
|
|
}));
|
|
|
|
vi.mock('../src/services/zeroSalePriceNotificationService', () => ({
|
|
scheduleZeroSalePriceNotify: vi.fn(),
|
|
}));
|
|
|
|
import { resolveSkuSalePriceForUnitChange } from '../src/services/orderPricingService';
|
|
import {
|
|
freezeOrderSettlementQtyOnComplete,
|
|
displayPickedMeasureForUnit,
|
|
normalizePickingSavedMeasures,
|
|
resolveCompleteReceivedSettlementQty,
|
|
resolvePickingSettlementQty,
|
|
syncOrderItemsFromSupplyCompletion,
|
|
} from '../src/services/orderItemSupplyUnitSync';
|
|
import { scheduleZeroSalePriceNotify } from '../src/services/zeroSalePriceNotificationService';
|
|
|
|
const resolveSalePrice = vi.mocked(resolveSkuSalePriceForUnitChange);
|
|
|
|
describe('syncOrderItemsFromSupplyCompletion keep ordered qty', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
resolveSalePrice.mockResolvedValue(4);
|
|
});
|
|
|
|
it('does not rewrite quantity when settlement exceeds ordered (merge overbuy)', async () => {
|
|
const updates: Array<{ sql: string; params: unknown[] }> = [];
|
|
const query = vi.fn(async (sql: string, params?: unknown[]) => {
|
|
const s = String(sql);
|
|
if (s.includes('FROM order_item_fulfillments f') && s.includes('purchase_code')) {
|
|
if (s.includes('SELECT DISTINCT oi.order_code')) {
|
|
return { rows: [{ order_code: 'ORD_A' }, { order_code: 'ORD_B' }], rowCount: 2 };
|
|
}
|
|
return {
|
|
rowCount: 2,
|
|
rows: [
|
|
{
|
|
id: 'item-a',
|
|
quantity: 0.5,
|
|
unit: '斤',
|
|
price: 9,
|
|
ordered_quantity: null,
|
|
ordered_unit: null,
|
|
customer_code: 'C1',
|
|
},
|
|
{
|
|
id: 'item-b',
|
|
quantity: 2,
|
|
unit: '斤',
|
|
price: 9,
|
|
ordered_quantity: null,
|
|
ordered_unit: null,
|
|
customer_code: 'C1',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
if (s.includes('UPDATE order_items')) {
|
|
updates.push({ sql: s, params: params || [] });
|
|
return { rows: [{ order_code: 'ORD_A' }], rowCount: 1 };
|
|
}
|
|
if (s.includes('SELECT quantity, unit FROM order_items')) {
|
|
return { rows: [{ quantity: 0.5, unit: '斤' }] };
|
|
}
|
|
if (s.includes('UPDATE orders')) {
|
|
return { rows: [{ branch_code: 'BR002' }], rowCount: 1 };
|
|
}
|
|
return { rows: [], rowCount: 0 };
|
|
});
|
|
|
|
await syncOrderItemsFromSupplyCompletion(
|
|
{ query } as any,
|
|
{
|
|
orderCode: 'ORD_A',
|
|
skuCode: 'SKU1',
|
|
settlementQty: 7,
|
|
settlementUnit: '斤',
|
|
link: { type: 'purchase', purchaseCode: 'PUR1' },
|
|
}
|
|
);
|
|
|
|
const itemUpdates = updates.filter((u) => u.sql.includes('UPDATE order_items'));
|
|
expect(itemUpdates.length).toBe(2);
|
|
expect(Number(itemUpdates[0].params[7])).toBe(0.5);
|
|
expect(Number(itemUpdates[1].params[7])).toBe(2);
|
|
expect(itemUpdates[0].params[8]).toBe(false);
|
|
expect(Number(itemUpdates[0].params[4])).toBe(4.5); // 0.5 * 9
|
|
expect(Number(itemUpdates[1].params[4])).toBe(18); // 2 * 9
|
|
expect(resolveSalePrice).not.toHaveBeenCalled();
|
|
expect(scheduleZeroSalePriceNotify).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('alignPlanQty rewrites ordered snapshot and settlement qty to supply', async () => {
|
|
const updates: Array<{ sql: string; params: unknown[] }> = [];
|
|
const query = vi.fn(async (sql: string, params?: unknown[]) => {
|
|
const s = String(sql);
|
|
if (s.includes('FROM order_item_fulfillments f') && s.includes('supplier_preparation_id')) {
|
|
if (s.includes('SELECT DISTINCT oi.order_code')) {
|
|
return { rows: [{ order_code: 'ORD1' }], rowCount: 1 };
|
|
}
|
|
return {
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
id: 'item-1',
|
|
quantity: 17,
|
|
unit: '公斤',
|
|
price: 20,
|
|
ordered_quantity: 17,
|
|
ordered_unit: '公斤',
|
|
customer_code: 'C1',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
if (s.includes('UPDATE order_items')) {
|
|
updates.push({ sql: s, params: params || [] });
|
|
return { rows: [{ order_code: 'ORD1' }], rowCount: 1 };
|
|
}
|
|
if (s.includes('SELECT quantity, unit FROM order_items')) {
|
|
return { rows: [{ quantity: 20, unit: '公斤' }] };
|
|
}
|
|
if (s.includes('UPDATE orders')) {
|
|
return { rows: [{ branch_code: 'BR002' }], rowCount: 1 };
|
|
}
|
|
return { rows: [], rowCount: 0 };
|
|
});
|
|
|
|
await syncOrderItemsFromSupplyCompletion(
|
|
{ query } as any,
|
|
{
|
|
orderCode: 'ORD1',
|
|
skuCode: 'SKU_RIB',
|
|
settlementQty: 20,
|
|
settlementUnit: '公斤',
|
|
link: { type: 'preparation', preparationId: 'prep-rib' },
|
|
alignPlanQty: true,
|
|
}
|
|
);
|
|
|
|
expect(updates).toHaveLength(1);
|
|
expect(updates[0].sql).toContain('WHEN $9::boolean THEN $8::numeric');
|
|
expect(Number(updates[0].params[7])).toBe(20);
|
|
expect(updates[0].params[8]).toBe(true);
|
|
expect(Number(updates[0].params[4])).toBe(400);
|
|
});
|
|
|
|
it('alignPlanQty writes supply unit even when snapshot unit is equivalent (斤 vs 市斤)', async () => {
|
|
const updates: Array<{ sql: string; params: unknown[] }> = [];
|
|
const query = vi.fn(async (sql: string, params?: unknown[]) => {
|
|
const s = String(sql);
|
|
if (s.includes('FROM order_item_fulfillments f') && s.includes('supplier_preparation_id')) {
|
|
if (s.includes('SELECT DISTINCT oi.order_code')) {
|
|
return { rows: [{ order_code: 'ORD1' }], rowCount: 1 };
|
|
}
|
|
return {
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
id: 'item-1',
|
|
quantity: 17,
|
|
unit: '斤',
|
|
price: 8.3,
|
|
ordered_quantity: 17,
|
|
ordered_unit: '斤',
|
|
customer_code: 'C1',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
if (s.includes('UPDATE order_items')) {
|
|
updates.push({ sql: s, params: params || [] });
|
|
return { rows: [{ order_code: 'ORD1' }], rowCount: 1 };
|
|
}
|
|
if (s.includes('SELECT quantity, unit FROM order_items')) {
|
|
return { rows: [{ quantity: 17, unit: '市斤' }] };
|
|
}
|
|
if (s.includes('UPDATE orders')) {
|
|
return { rows: [{ branch_code: 'BR002' }], rowCount: 1 };
|
|
}
|
|
return { rows: [], rowCount: 0 };
|
|
});
|
|
|
|
await syncOrderItemsFromSupplyCompletion(
|
|
{ query } as any,
|
|
{
|
|
orderCode: 'ORD1',
|
|
skuCode: 'SKU_PORK',
|
|
settlementQty: 17,
|
|
settlementUnit: '市斤',
|
|
link: { type: 'preparation', preparationId: 'prep-unit' },
|
|
alignPlanQty: true,
|
|
}
|
|
);
|
|
|
|
expect(updates[0].params[2]).toBe('市斤');
|
|
expect(updates[0].params[8]).toBe(true);
|
|
expect(resolveSalePrice).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('alignPlanQty writes non-equivalent supply unit (公斤 → 斤) onto the order', async () => {
|
|
const updates: Array<{ sql: string; params: unknown[] }> = [];
|
|
const query = vi.fn(async (sql: string, params?: unknown[]) => {
|
|
const s = String(sql);
|
|
if (s.includes('FROM order_item_fulfillments f') && s.includes('supplier_preparation_id')) {
|
|
if (s.includes('SELECT DISTINCT oi.order_code')) {
|
|
return { rows: [{ order_code: 'ORD1' }], rowCount: 1 };
|
|
}
|
|
return {
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
id: 'item-1',
|
|
quantity: 20,
|
|
unit: '公斤',
|
|
price: 20,
|
|
ordered_quantity: 20,
|
|
ordered_unit: '公斤',
|
|
customer_code: 'C1',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
if (s.includes('UPDATE order_items')) {
|
|
updates.push({ sql: s, params: params || [] });
|
|
return { rows: [{ order_code: 'ORD1' }], rowCount: 1 };
|
|
}
|
|
if (s.includes('SELECT quantity, unit FROM order_items')) {
|
|
return { rows: [{ quantity: 20, unit: '斤' }] };
|
|
}
|
|
if (s.includes('UPDATE orders')) {
|
|
return { rows: [{ branch_code: 'BR002' }], rowCount: 1 };
|
|
}
|
|
return { rows: [], rowCount: 0 };
|
|
});
|
|
|
|
await syncOrderItemsFromSupplyCompletion(
|
|
{ query } as any,
|
|
{
|
|
orderCode: 'ORD1',
|
|
skuCode: 'SKU_RIB',
|
|
settlementQty: 20,
|
|
settlementUnit: '斤',
|
|
link: { type: 'preparation', preparationId: 'prep-rib-unit' },
|
|
alignPlanQty: true,
|
|
}
|
|
);
|
|
|
|
expect(updates[0].params[2]).toBe('斤');
|
|
expect(resolveSalePrice).toHaveBeenCalled();
|
|
});
|
|
|
|
it('on unit change uses quote-sheet fallback price instead of locking 0', async () => {
|
|
resolveSalePrice.mockResolvedValue(3.5);
|
|
const updates: Array<{ sql: string; params: unknown[] }> = [];
|
|
const query = vi.fn(async (sql: string, params?: unknown[]) => {
|
|
const s = String(sql);
|
|
if (s.includes('FROM order_item_fulfillments f') && s.includes('supplier_preparation_id')) {
|
|
if (s.includes('SELECT DISTINCT oi.order_code')) {
|
|
return { rows: [{ order_code: 'ORD1' }], rowCount: 1 };
|
|
}
|
|
return {
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
id: 'item-1',
|
|
quantity: 11,
|
|
unit: '把',
|
|
price: 3.5,
|
|
ordered_quantity: 11,
|
|
ordered_unit: '把',
|
|
customer_code: 'CUS1',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
if (s.includes('UPDATE order_items')) {
|
|
updates.push({ sql: s, params: params || [] });
|
|
return { rows: [{ order_code: 'ORD1' }], rowCount: 1 };
|
|
}
|
|
if (s.includes('SELECT quantity, unit FROM order_items')) {
|
|
return { rows: [{ quantity: 11, unit: '斤' }] };
|
|
}
|
|
if (s.includes('UPDATE orders')) {
|
|
return { rows: [{ branch_code: 'BR002' }], rowCount: 1 };
|
|
}
|
|
return { rows: [], rowCount: 0 };
|
|
});
|
|
|
|
const result = await syncOrderItemsFromSupplyCompletion(
|
|
{ query } as any,
|
|
{
|
|
orderCode: 'ORD1',
|
|
skuCode: 'SKU_KONGXINCAI',
|
|
settlementQty: 11,
|
|
settlementUnit: '斤',
|
|
link: { type: 'preparation', preparationId: 'prep-1' },
|
|
}
|
|
);
|
|
|
|
expect(resolveSalePrice).toHaveBeenCalledWith('CUS1', 'SKU_KONGXINCAI', '斤', expect.anything());
|
|
expect(result.needsCustomerPrice).toBe(false);
|
|
expect(updates.length).toBe(1);
|
|
expect(Number(updates[0].params[3])).toBe(3.5);
|
|
expect(Number(updates[0].params[4])).toBe(38.5);
|
|
expect(updates[0].params[6]).toBe(false);
|
|
expect(scheduleZeroSalePriceNotify).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('on unit change marks needs_customer_price when all fallbacks miss', async () => {
|
|
resolveSalePrice.mockResolvedValue(null);
|
|
const updates: Array<{ sql: string; params: unknown[] }> = [];
|
|
const query = vi.fn(async (sql: string, params?: unknown[]) => {
|
|
const s = String(sql);
|
|
if (s.includes('FROM order_item_fulfillments f') && s.includes('supplier_preparation_id')) {
|
|
if (s.includes('SELECT DISTINCT oi.order_code')) {
|
|
return { rows: [{ order_code: 'ORD1' }], rowCount: 1 };
|
|
}
|
|
return {
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
id: 'item-1',
|
|
quantity: 3,
|
|
unit: '两',
|
|
price: 10,
|
|
ordered_quantity: 3,
|
|
ordered_unit: '两',
|
|
customer_code: 'CUS1',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
if (s.includes('UPDATE order_items')) {
|
|
updates.push({ sql: s, params: params || [] });
|
|
return { rows: [{ order_code: 'ORD1' }], rowCount: 1 };
|
|
}
|
|
if (s.includes('SELECT quantity, unit FROM order_items')) {
|
|
return { rows: [{ quantity: 3, unit: '斤' }] };
|
|
}
|
|
if (s.includes('UPDATE orders')) {
|
|
return { rows: [{ branch_code: 'BR002' }], rowCount: 1 };
|
|
}
|
|
return { rows: [], rowCount: 0 };
|
|
});
|
|
|
|
const result = await syncOrderItemsFromSupplyCompletion(
|
|
{ query } as any,
|
|
{
|
|
orderCode: 'ORD1',
|
|
skuCode: 'SKU_XIANGCAI',
|
|
settlementQty: 3,
|
|
settlementUnit: '斤',
|
|
link: { type: 'preparation', preparationId: 'prep-2' },
|
|
}
|
|
);
|
|
|
|
expect(result.needsCustomerPrice).toBe(true);
|
|
expect(result.itemIds).toEqual(['item-1']);
|
|
expect(Number(updates[0].params[3])).toBe(0);
|
|
expect(updates[0].params[6]).toBe(true);
|
|
expect(scheduleZeroSalePriceNotify).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
orderCode: 'ORD1',
|
|
branchCode: 'BR002',
|
|
reason: 'unit_change',
|
|
count: 1,
|
|
})
|
|
);
|
|
});
|
|
});
|
|
|
|
describe('结案按实收冻结结算量', () => {
|
|
it('斤类:重量优先,否则实配;非斤:件数优先,忽略称重', () => {
|
|
expect(resolveCompleteReceivedSettlementQty(8.2, 8, '斤')).toBe(8.2);
|
|
expect(resolveCompleteReceivedSettlementQty(0, 15.1, '斤')).toBe(15.1);
|
|
expect(resolveCompleteReceivedSettlementQty(1, 80, '盒', 80)).toBe(80);
|
|
expect(resolveCompleteReceivedSettlementQty(1, 80, '盒', 0)).toBe(80);
|
|
expect(resolveCompleteReceivedSettlementQty(null, 0, '斤')).toBeNull();
|
|
expect(resolveCompleteReceivedSettlementQty(undefined, undefined)).toBeNull();
|
|
});
|
|
|
|
it('分拣结算量:盒忽略称重,斤用称重', () => {
|
|
expect(resolvePickingSettlementQty(80, 1, '盒')).toBe(80);
|
|
expect(resolvePickingSettlementQty(80, 8.2, '斤')).toBe(8.2);
|
|
expect(resolvePickingSettlementQty(0, 1, '个')).toBe(0);
|
|
expect(normalizePickingSavedMeasures(30, 2, '根')).toEqual({ picked_qty: 30, picked_weight: 2 });
|
|
expect(normalizePickingSavedMeasures(0, 8.2, '斤')).toEqual({ picked_qty: 8.2, picked_weight: 8.2 });
|
|
expect(displayPickedMeasureForUnit('根', 6, 1)).toBe(6);
|
|
expect(displayPickedMeasureForUnit('斤', 6, 8.2)).toBe(8.2);
|
|
});
|
|
|
|
it('已完成单(status>=90)不 UPDATE order_items', async () => {
|
|
const sqls: string[] = [];
|
|
const query = vi.fn(async (sql: string) => {
|
|
sqls.push(String(sql));
|
|
if (String(sql).includes('SELECT order_status')) {
|
|
return { rows: [{ order_status: 90 }], rowCount: 1 };
|
|
}
|
|
return { rows: [], rowCount: 0 };
|
|
});
|
|
await freezeOrderSettlementQtyOnComplete({ query } as any, 'ORD_DONE');
|
|
expect(sqls.some((s) => s.includes('UPDATE order_items'))).toBe(false);
|
|
expect(sqls.some((s) => s.includes('FROM picking_items') || s.includes('order_items oi'))).toBe(
|
|
false
|
|
);
|
|
});
|
|
|
|
it('有称重且与 quantity 不同则回写;有快照不覆盖 ordered_quantity', async () => {
|
|
const updates: Array<{ sql: string; params: unknown[] }> = [];
|
|
const query = vi.fn(async (sql: string, params?: unknown[]) => {
|
|
const s = String(sql);
|
|
if (s.includes('SELECT order_status')) {
|
|
return { rows: [{ order_status: 60 }], rowCount: 1 };
|
|
}
|
|
if (s.includes('AS picked_weight')) {
|
|
return {
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
order_item_id: 'item-1',
|
|
quantity: 8,
|
|
picked_weight: 8.2,
|
|
loaded_qty: 8,
|
|
pick_unit: '斤',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
if (s.includes('FOR UPDATE OF oi')) {
|
|
return {
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
id: 'item-1',
|
|
order_code: 'ORD_NEW',
|
|
quantity: 8,
|
|
unit: '斤',
|
|
price: 3,
|
|
locked_price: 3,
|
|
ordered_quantity: 8,
|
|
ordered_unit: '斤',
|
|
amount: 24,
|
|
sku_code: 'SKU1',
|
|
customer_code: 'C1',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
if (s.includes('UPDATE order_items')) {
|
|
updates.push({ sql: s, params: params || [] });
|
|
return { rowCount: 1, rows: [] };
|
|
}
|
|
if (s.includes('SELECT quantity, unit FROM order_items')) {
|
|
return { rows: [{ quantity: 8.2, unit: '斤' }] };
|
|
}
|
|
if (s.includes('UPDATE orders')) {
|
|
return { rows: [], rowCount: 1 };
|
|
}
|
|
return { rows: [], rowCount: 0 };
|
|
});
|
|
|
|
await freezeOrderSettlementQtyOnComplete({ query } as any, 'ORD_NEW');
|
|
expect(updates.length).toBe(1);
|
|
expect(Number(updates[0].params[2])).toBe(8.2);
|
|
expect(updates[0].params[1]).toBe(false);
|
|
expect(Number(updates[0].params[4])).toBe(24.6);
|
|
});
|
|
|
|
it('非斤有称重仍按件数冻结,不覆盖 ordered_quantity', async () => {
|
|
const updates: Array<{ sql: string; params: unknown[] }> = [];
|
|
const query = vi.fn(async (sql: string, params?: unknown[]) => {
|
|
const s = String(sql);
|
|
if (s.includes('SELECT order_status')) {
|
|
return { rows: [{ order_status: 60 }], rowCount: 1 };
|
|
}
|
|
if (s.includes('AS picked_weight')) {
|
|
return {
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
order_item_id: 'item-box',
|
|
quantity: 80,
|
|
picked_weight: 1,
|
|
picked_qty: 80,
|
|
loaded_qty: 80,
|
|
pick_unit: '盒',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
if (s.includes('FOR UPDATE OF oi')) {
|
|
return {
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
id: 'item-box',
|
|
order_code: 'ORD_BOX',
|
|
quantity: 80,
|
|
unit: '盒',
|
|
price: 2.8,
|
|
locked_price: 2.8,
|
|
ordered_quantity: 80,
|
|
ordered_unit: '盒',
|
|
amount: 224,
|
|
sku_code: 'SKU_BOX',
|
|
customer_code: 'C1',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
if (s.includes('UPDATE order_items')) {
|
|
updates.push({ sql: s, params: params || [] });
|
|
return { rowCount: 1, rows: [] };
|
|
}
|
|
if (s.includes('SELECT quantity, unit FROM order_items')) {
|
|
return { rows: [{ quantity: 80, unit: '盒' }] };
|
|
}
|
|
if (s.includes('UPDATE orders')) {
|
|
return { rows: [], rowCount: 1 };
|
|
}
|
|
return { rows: [], rowCount: 0 };
|
|
});
|
|
|
|
await freezeOrderSettlementQtyOnComplete({ query } as any, 'ORD_BOX');
|
|
expect(updates.length).toBe(0);
|
|
});
|
|
|
|
it('非斤 quantity 已被称重覆盖时,结案回写件数', async () => {
|
|
const updates: Array<{ sql: string; params: unknown[] }> = [];
|
|
const query = vi.fn(async (sql: string, params?: unknown[]) => {
|
|
const s = String(sql);
|
|
if (s.includes('SELECT order_status')) {
|
|
return { rows: [{ order_status: 60 }], rowCount: 1 };
|
|
}
|
|
if (s.includes('AS picked_weight')) {
|
|
return {
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
order_item_id: 'item-box',
|
|
quantity: 1,
|
|
picked_weight: 1,
|
|
picked_qty: 80,
|
|
loaded_qty: 80,
|
|
pick_unit: '盒',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
if (s.includes('FOR UPDATE OF oi')) {
|
|
return {
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
id: 'item-box',
|
|
order_code: 'ORD_BOX',
|
|
quantity: 1,
|
|
unit: '盒',
|
|
price: 2.8,
|
|
locked_price: 2.8,
|
|
ordered_quantity: 80,
|
|
ordered_unit: '盒',
|
|
amount: 2.8,
|
|
sku_code: 'SKU_BOX',
|
|
customer_code: 'C1',
|
|
},
|
|
],
|
|
};
|
|
}
|
|
if (s.includes('UPDATE order_items')) {
|
|
updates.push({ sql: s, params: params || [] });
|
|
return { rowCount: 1, rows: [] };
|
|
}
|
|
if (s.includes('SELECT quantity, unit FROM order_items')) {
|
|
return { rows: [{ quantity: 80, unit: '盒' }] };
|
|
}
|
|
if (s.includes('UPDATE orders')) {
|
|
return { rows: [], rowCount: 1 };
|
|
}
|
|
return { rows: [], rowCount: 0 };
|
|
});
|
|
|
|
await freezeOrderSettlementQtyOnComplete({ query } as any, 'ORD_BOX');
|
|
expect(updates.length).toBe(1);
|
|
expect(Number(updates[0].params[2])).toBe(80);
|
|
expect(updates[0].params[1]).toBe(false);
|
|
});
|
|
});
|
|
|