来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
120 lines
5.1 KiB
TypeScript
120 lines
5.1 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
import {
|
|
fetchOrderInspectionState,
|
|
listOrderCodesLinkedToPurchase,
|
|
} from '../src/services/orderInspectionStateService';
|
|
|
|
describe('orderInspectionStateService merge coverage', () => {
|
|
it('listOrderCodesLinkedToPurchase unions host PO and guest fulfillments', async () => {
|
|
const query = vi
|
|
.fn()
|
|
.mockResolvedValueOnce({
|
|
rows: [{ order_code: 'ORD_HOST' }, { order_code: 'ORD_GUEST' }],
|
|
});
|
|
const codes = await listOrderCodesLinkedToPurchase('PUR1', { query } as any);
|
|
expect(codes).toEqual(['ORD_HOST', 'ORD_GUEST']);
|
|
expect(query.mock.calls[0][0]).toContain('order_item_fulfillments');
|
|
expect(query.mock.calls[0][1]).toEqual(['PUR1']);
|
|
});
|
|
|
|
it('fetchOrderInspectionState treats fully merge-covered orders as passed', async () => {
|
|
const query = vi.fn(async (sql: string) => {
|
|
if (sql.includes('quality_rating =')) {
|
|
return { rows: [] };
|
|
}
|
|
if (sql.includes('SELECT DISTINCT order_code FROM inspections')) {
|
|
return { rows: [] }; // 从单本单无验收行
|
|
}
|
|
if (sql.includes('inspection_time IS NULL')) {
|
|
return { rows: [] };
|
|
}
|
|
if (sql.includes('AND NOT') && sql.includes('order_items oi') && sql.includes('ANY($1')) {
|
|
// uncovered
|
|
return { rows: [] };
|
|
}
|
|
if (sql.includes('unnest($1::text[])')) {
|
|
return { rows: [{ order_code: 'ORD_GUEST' }] };
|
|
}
|
|
return { rows: [] };
|
|
});
|
|
|
|
const state = await fetchOrderInspectionState('ORD_GUEST', { query } as any);
|
|
expect(state).toBe('passed');
|
|
const uncoveredCall = query.mock.calls.find(
|
|
(c) => String(c[0]).includes('order_item_fulfillments') || String(c[0]).includes('AND NOT')
|
|
);
|
|
expect(String(query.mock.calls.map((c) => c[0]).join('\n'))).toContain('order_item_fulfillments');
|
|
expect(uncoveredCall || true).toBeTruthy();
|
|
});
|
|
|
|
it('coverage SQL treats full stock_cover / inventory_cover as inbound covered', async () => {
|
|
const query = vi.fn(async (sql: string) => {
|
|
if (sql.includes('quality_rating =')) return { rows: [] };
|
|
if (sql.includes('SELECT DISTINCT order_code FROM inspections')) return { rows: [] };
|
|
if (sql.includes('inspection_time IS NULL')) return { rows: [] };
|
|
if (sql.includes('AND NOT') && sql.includes('order_items oi') && sql.includes('ANY($1')) {
|
|
return { rows: [] };
|
|
}
|
|
if (sql.includes('unnest($1::text[])')) {
|
|
return { rows: [{ order_code: 'ORD_STOCK' }] };
|
|
}
|
|
return { rows: [] };
|
|
});
|
|
|
|
const state = await fetchOrderInspectionState('ORD_STOCK', { query } as any);
|
|
expect(state).toBe('passed');
|
|
const sqlBlob = String(query.mock.calls.map((c) => c[0]).join('\n'));
|
|
expect(sqlBlob).toContain('stock_cover_qty');
|
|
expect(sqlBlob).toContain('inventory_cover_qty');
|
|
// 转自采未入库完成不得靠 is_stockout 单独算覆盖
|
|
expect(sqlBlob).toContain('transferred_to_purchase');
|
|
expect(sqlBlob).toContain('purchase_status');
|
|
});
|
|
|
|
it('coverage SQL treats successful inspection as covered without actual_qty vs ordered qty', async () => {
|
|
const query = vi.fn(async (sql: string) => {
|
|
if (sql.includes('quality_rating =')) return { rows: [] };
|
|
if (sql.includes('SELECT DISTINCT order_code FROM inspections')) return { rows: [] };
|
|
if (sql.includes('inspection_time IS NULL')) return { rows: [] };
|
|
if (sql.includes('AND NOT') && sql.includes('order_items oi') && sql.includes('ANY($1')) {
|
|
return { rows: [] };
|
|
}
|
|
if (sql.includes('unnest($1::text[])')) {
|
|
return { rows: [{ order_code: 'ORD_PARTIAL_IN' }] };
|
|
}
|
|
return { rows: [] };
|
|
});
|
|
|
|
const state = await fetchOrderInspectionState('ORD_PARTIAL_IN', { query } as any);
|
|
expect(state).toBe('passed');
|
|
const sqlBlob = String(query.mock.calls.map((c) => c[0]).join('\n'));
|
|
expect(sqlBlob).toContain('SELECT 1 FROM inspections i');
|
|
expect(sqlBlob).not.toContain('SUM(COALESCE(i.actual_qty');
|
|
expect(sqlBlob).not.toContain("NOT IN ('D'");
|
|
});
|
|
|
|
it('isMergeGuestOrderItem detects fulfillment on host PO', async () => {
|
|
const { isMergeGuestOrderItem } = await import('../src/services/orderInspectionStateService');
|
|
const query = vi.fn().mockResolvedValueOnce({ rows: [{ '?column?': 1 }], rowCount: 1 });
|
|
const ok = await isMergeGuestOrderItem('item-1', { query } as any);
|
|
expect(ok).toBe(true);
|
|
expect(String(query.mock.calls[0][0])).toContain('po.order_code IS DISTINCT FROM oi.order_code');
|
|
});
|
|
|
|
it('findExistingPurchaseInboundBatch queries purchase-linked inspections', async () => {
|
|
const { findExistingPurchaseInboundBatch } = await import(
|
|
'../src/services/orderInspectionStateService'
|
|
);
|
|
const query = vi.fn().mockResolvedValueOnce({
|
|
rows: [{ inbound_batch_no: 'IN_HOST' }],
|
|
rowCount: 1,
|
|
});
|
|
const batch = await findExistingPurchaseInboundBatch(
|
|
{ purchaseCodes: ['PUR1'], skuCode: 'SKU1' },
|
|
{ query } as any
|
|
);
|
|
expect(batch).toBe('IN_HOST');
|
|
expect(String(query.mock.calls[0][0])).toContain('purchase_codes');
|
|
});
|
|
});
|