来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
176 lines
5.2 KiB
TypeScript
176 lines
5.2 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { readFileSync } from 'fs';
|
|
import path from 'path';
|
|
import {
|
|
shouldKeepBidExcludeOnAllocFallback,
|
|
listOrderSkusNeedingBidProcure,
|
|
} from '../src/services/bidRoundService';
|
|
|
|
const { query } = vi.hoisted(() => ({
|
|
query: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('../src/db', () => ({
|
|
pool: { query, connect: vi.fn() },
|
|
getRawPoolQuery: () => vi.fn(),
|
|
}));
|
|
|
|
const getBidSettings = vi.hoisted(() => vi.fn());
|
|
vi.mock('../src/services/bidConfigService', () => ({
|
|
getBidSettings,
|
|
assertBidEnabled: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('../src/services/inventoryStockCoverService', () => ({
|
|
applyStockCoverForOrder: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('../src/services/bidAwardService', () => ({
|
|
notifySuppliersBidOpened: vi.fn(),
|
|
}));
|
|
|
|
vi.mock('../src/services/categoryCatalogService', async (importOriginal) => {
|
|
const actual = await importOriginal<typeof import('../src/services/categoryCatalogService')>();
|
|
return {
|
|
...actual,
|
|
fetchCategoryRows: vi.fn(async () => [
|
|
{ category_code: 'GANZA', parent_code: '', category_name: '干杂' },
|
|
{ category_code: 'VEG', parent_code: '', category_name: '蔬菜' },
|
|
]),
|
|
};
|
|
});
|
|
|
|
describe('shouldKeepBidExcludeOnAllocFallback', () => {
|
|
const exclude = ['SKU_GANZA'];
|
|
|
|
it('本单轮仍进行中且有暂缓 SKU:catch / 发标失败保留 exclude', () => {
|
|
expect(
|
|
shouldKeepBidExcludeOnAllocFallback({
|
|
excludeSkuCodes: exclude,
|
|
hasActivePerOrderRound: true,
|
|
reason: 'start_failed',
|
|
})
|
|
).toBe(true);
|
|
});
|
|
|
|
it('无人报价 / 中标 / 取消:不带 exclude', () => {
|
|
for (const reason of ['already_awarded', 'empty_quotes_released', 'cancelled']) {
|
|
expect(
|
|
shouldKeepBidExcludeOnAllocFallback({
|
|
excludeSkuCodes: exclude,
|
|
hasActivePerOrderRound: true,
|
|
reason,
|
|
})
|
|
).toBe(false);
|
|
}
|
|
});
|
|
|
|
it('无进行中轮:不带 exclude', () => {
|
|
expect(
|
|
shouldKeepBidExcludeOnAllocFallback({
|
|
excludeSkuCodes: exclude,
|
|
hasActivePerOrderRound: false,
|
|
reason: 'start_failed',
|
|
})
|
|
).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('listOrderSkusNeedingBidProcure 分类 OR', () => {
|
|
beforeEach(() => {
|
|
query.mockReset();
|
|
getBidSettings.mockReset();
|
|
});
|
|
|
|
it('主数据非干杂但订单行是干杂:仍进范围内', async () => {
|
|
getBidSettings.mockResolvedValue({
|
|
enabled: true,
|
|
sku_codes: [],
|
|
category_codes: ['GANZA'],
|
|
sku_items: [],
|
|
category_items: [],
|
|
});
|
|
query.mockResolvedValueOnce({
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
sku_code: 'MUSHROOM',
|
|
sku_category_code: 'VEG',
|
|
item_category_codes: ['GANZA'],
|
|
suppliers: null,
|
|
procure_qty: 6,
|
|
},
|
|
],
|
|
});
|
|
|
|
const skus = await listOrderSkusNeedingBidProcure({ orderCode: 'ORD_MIX', branchCode: 'BR001' });
|
|
expect(skus).toEqual(['MUSHROOM']);
|
|
});
|
|
|
|
it('仅主数据是干杂、行分类为空:仍进范围内', async () => {
|
|
getBidSettings.mockResolvedValue({
|
|
enabled: true,
|
|
sku_codes: [],
|
|
category_codes: ['GANZA'],
|
|
sku_items: [],
|
|
category_items: [],
|
|
});
|
|
query.mockResolvedValueOnce({
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
sku_code: 'MUSHROOM',
|
|
sku_category_code: 'GANZA',
|
|
item_category_codes: null,
|
|
suppliers: null,
|
|
procure_qty: 6,
|
|
},
|
|
],
|
|
});
|
|
|
|
const skus = await listOrderSkusNeedingBidProcure({ orderCode: 'ORD_SOLO', branchCode: 'BR001' });
|
|
expect(skus).toEqual(['MUSHROOM']);
|
|
});
|
|
});
|
|
|
|
describe('混单回退源码约束', () => {
|
|
const submitSrc = readFileSync(
|
|
path.join(__dirname, '../src/services/customerOrderSubmitService.ts'),
|
|
'utf8'
|
|
);
|
|
const manageSrc = readFileSync(
|
|
path.join(__dirname, '../src/services/orderManageItemsService.ts'),
|
|
'utf8'
|
|
);
|
|
const allocSrc = readFileSync(
|
|
path.join(__dirname, '../src/services/orderAllocationService.ts'),
|
|
'utf8'
|
|
);
|
|
const bidSrc = readFileSync(path.join(__dirname, '../src/services/bidRoundService.ts'), 'utf8');
|
|
|
|
it('提交/改明细 catch 走 reason 解析,禁止无排除整单覆盖', () => {
|
|
expect(submitSrc).toMatch(/resolvePerOrderBidSkipGateAllocOptions/);
|
|
expect(manageSrc).toMatch(/resolvePerOrderBidSkipGateAllocOptions/);
|
|
expect(allocSrc).toMatch(/resolvePerOrderBidSkipGateAllocOptions/);
|
|
expect(submitSrc).toMatch(/禁止第三次无排除整单覆盖竞价 SKU/);
|
|
expect(manageSrc).toMatch(/禁止第三次无排除整单覆盖竞价 SKU/);
|
|
});
|
|
|
|
it('无人报价/中标/取消仍无 exclude 整单 skip 闸门', () => {
|
|
expect(bidSrc).toMatch(/无人报价改走分配失败/);
|
|
expect(bidSrc).toMatch(/中标后分配重试失败/);
|
|
expect(bidSrc).toMatch(
|
|
/await reprocessOrderAllocation\(orderCode, null, branchCode \?\? null, undefined, \{\s*skipPerOrderAutoBidGate: true,/
|
|
);
|
|
expect(allocSrc).toMatch(/skipBecauseNoProcure/);
|
|
});
|
|
|
|
it('范围内 SQL 含订单行分类,不用 COALESCE 只认行分类', () => {
|
|
expect(bidSrc).toMatch(/item_category_codes/);
|
|
expect(bidSrc).toMatch(/sku_category_code/);
|
|
expect(bidSrc).not.toMatch(
|
|
/COALESCE\(NULLIF\(oi\.category_code,''\),\s*s\.category_code\)/
|
|
);
|
|
});
|
|
});
|