来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
132 lines
4.0 KiB
TypeScript
132 lines
4.0 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import type { TenantContext } from '../src/services/tenantScope';
|
|
|
|
/**
|
|
* 自采列表展示名口径(2026-09-15):
|
|
* 必须显示**商品库 SKU 名**(精准 SKU),备货行/订单行的录单名只能在拿不到商品库记录时兜底。
|
|
* 改前顺序是 备货名 → 订单行录单名 → 目录名 → 商品库名,列表会显示客户写法(如「草鱼」而非「草鱼杀好」)。
|
|
*/
|
|
const { query } = vi.hoisted(() => ({
|
|
query: vi.fn(async () => ({ rows: [] as unknown[] })),
|
|
}));
|
|
|
|
vi.mock('../src/db', () => ({
|
|
pool: { query, connect: vi.fn() },
|
|
getRawPoolQuery: () => vi.fn(),
|
|
}));
|
|
|
|
vi.mock('../src/services/selfPurchaseStockInboundService', () => ({
|
|
healOrphanIndependentInboundsAfterPass: vi.fn(async () => undefined),
|
|
}));
|
|
|
|
vi.mock('../src/services/inspectionPhotoService', () => ({
|
|
attachCategoryPhotoInspectionRequirements: vi.fn(async (rows: unknown[]) => rows),
|
|
}));
|
|
|
|
vi.mock('../src/services/skuDirectDelivery', async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import('../src/services/skuDirectDelivery')>();
|
|
return {
|
|
...actual,
|
|
listSkuDirectDeliveryCustomers: vi.fn(async () => ({})),
|
|
};
|
|
});
|
|
|
|
import { listPurchaseOrdersForManagement } from '../src/services/purchaseOrderQueryService';
|
|
|
|
const admin: TenantContext = {
|
|
userId: '22222222-2222-2222-2222-222222222222',
|
|
roles: ['admin'],
|
|
permissions: ['purchase_manage'],
|
|
branchCode: 'BR002',
|
|
supplierCode: null,
|
|
purchaserCode: null,
|
|
isSuperAdmin: false,
|
|
isBranchAdmin: true,
|
|
isInternalStaff: true,
|
|
isSupplierAccount: false,
|
|
};
|
|
|
|
const PO_ROW = {
|
|
purchase_code: 'PC1',
|
|
order_code: 'O1',
|
|
sku_code: 'SKU1',
|
|
source_id: 'prep1',
|
|
branch_code: 'BR002',
|
|
purchase_status: 10,
|
|
purchase_qty: 2,
|
|
purchase_price: 10,
|
|
created_at: '2026-09-15T02:00:00.000Z',
|
|
supplier_code: 'S1',
|
|
};
|
|
|
|
const ORDER_ITEM_ROW = {
|
|
id: 'oi1',
|
|
order_code: 'O1',
|
|
sku_code: 'SKU1',
|
|
item_name: '草鱼',
|
|
quantity: 2,
|
|
unit: '斤',
|
|
price: 20,
|
|
unit_cost: 10,
|
|
};
|
|
|
|
function mockQueries(options: { skuName?: string | null }) {
|
|
query.mockImplementation(async (sql: unknown) => {
|
|
const text = String(sql || '');
|
|
if (text.includes('SELECT row_kind, purchase_code, spi_id FROM (')) {
|
|
return { rows: [{ row_kind: 'po', purchase_code: 'PC1', spi_id: null }] };
|
|
}
|
|
if (text.includes('SELECT po.*')) return { rows: [PO_ROW] };
|
|
if (text.includes('FROM order_items WHERE order_code = ANY')) return { rows: [ORDER_ITEM_ROW] };
|
|
if (text.includes('FROM order_item_fulfillments')) return { rows: [] };
|
|
if (text.includes('FROM supplier_preparations WHERE id::text = ANY')) {
|
|
return { rows: [{ id: 'prep1', item_name: '草鱼' }] };
|
|
}
|
|
if (text.includes('FROM skus WHERE sku_code = ANY')) {
|
|
return {
|
|
rows:
|
|
options.skuName === null
|
|
? []
|
|
: [{ sku_code: 'SKU1', sku_name: options.skuName ?? '草鱼杀好', unit: '斤', category_code: 'C1' }],
|
|
};
|
|
}
|
|
return { rows: [] };
|
|
});
|
|
}
|
|
|
|
describe('自采列表展示名:商品库 SKU 名优先', () => {
|
|
beforeEach(() => {
|
|
query.mockClear();
|
|
mockQueries({});
|
|
});
|
|
|
|
it('备货名/录单名与商品库名冲突时,展示商品库名', async () => {
|
|
const result = await listPurchaseOrdersForManagement(admin, 'BR002', {
|
|
page: 1,
|
|
pageSize: 20,
|
|
statusGroup: 'all',
|
|
dateRangeFilter: 'all',
|
|
deliveryDateFilter: 'all',
|
|
} as never);
|
|
|
|
expect(result.rows).toHaveLength(1);
|
|
expect(result.rows[0].sku_name).toBe('草鱼杀好');
|
|
expect(result.rows[0].sku_name).not.toBe('草鱼');
|
|
});
|
|
|
|
it('商品库无该 SKU 记录时,回退备货行/订单行录单名', async () => {
|
|
query.mockClear();
|
|
mockQueries({ skuName: null });
|
|
|
|
const result = await listPurchaseOrdersForManagement(admin, 'BR002', {
|
|
page: 1,
|
|
pageSize: 20,
|
|
statusGroup: 'all',
|
|
dateRangeFilter: 'all',
|
|
deliveryDateFilter: 'all',
|
|
} as never);
|
|
|
|
expect(result.rows[0].sku_name).toBe('草鱼');
|
|
});
|
|
});
|