来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
148 lines
5.1 KiB
TypeScript
148 lines
5.1 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
|
import { readFileSync } from 'fs';
|
|
import path from 'path';
|
|
|
|
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(),
|
|
}));
|
|
|
|
import { listOrderSkusNeedingBidProcure } from '../src/services/bidRoundService';
|
|
|
|
describe('指定供应商直供接线', () => {
|
|
const bidSrc = readFileSync(path.join(__dirname, '../src/services/bidRoundService.ts'), 'utf8');
|
|
const allocSrc = readFileSync(
|
|
path.join(__dirname, '../src/services/orderAllocationService.ts'),
|
|
'utf8'
|
|
);
|
|
const mgmtSrc = readFileSync(
|
|
path.join(__dirname, '../../src/pages/orders/BidManagement.tsx'),
|
|
'utf8'
|
|
);
|
|
const histSrc = readFileSync(path.join(__dirname, '../../src/pages/orders/BidHistory.tsx'), 'utf8');
|
|
|
|
beforeEach(() => {
|
|
query.mockReset();
|
|
getBidSettings.mockReset();
|
|
});
|
|
|
|
it('闸门:商品行指定的 SKU 不进 needingBid', async () => {
|
|
getBidSettings.mockResolvedValue({
|
|
enabled: true,
|
|
sku_codes: ['MUSHROOM', 'TOFU'],
|
|
category_codes: [],
|
|
sku_items: [
|
|
{ sku_code: 'MUSHROOM', supplier_code: 'SUP_A' },
|
|
{ sku_code: 'TOFU', supplier_code: '' },
|
|
],
|
|
category_items: [],
|
|
});
|
|
query.mockResolvedValueOnce({
|
|
rowCount: 2,
|
|
rows: [
|
|
{ sku_code: 'MUSHROOM', category_code: 'VEG', suppliers: null, procure_qty: 2 },
|
|
{ sku_code: 'TOFU', category_code: 'VEG', suppliers: null, procure_qty: 1 },
|
|
],
|
|
});
|
|
|
|
const skus = await listOrderSkusNeedingBidProcure({ orderCode: 'ORD_MIX', branchCode: 'BR001' });
|
|
expect(skus).toEqual(['TOFU']);
|
|
expect(skus).not.toContain('MUSHROOM');
|
|
});
|
|
|
|
it('闸门:订单行真实供应商的 SKU 不进 needingBid', async () => {
|
|
getBidSettings.mockResolvedValue({
|
|
enabled: true,
|
|
sku_codes: ['MUSHROOM'],
|
|
category_codes: [],
|
|
sku_items: [{ sku_code: 'MUSHROOM', supplier_code: '' }],
|
|
category_items: [],
|
|
});
|
|
query.mockResolvedValueOnce({
|
|
rowCount: 1,
|
|
rows: [
|
|
{
|
|
sku_code: 'MUSHROOM',
|
|
category_code: 'VEG',
|
|
suppliers: ['SUP_ORDER'],
|
|
procure_qty: 3,
|
|
},
|
|
],
|
|
});
|
|
|
|
const skus = await listOrderSkusNeedingBidProcure({ orderCode: 'ORD_LINE' });
|
|
expect(skus).toEqual([]);
|
|
});
|
|
|
|
it('闸门:INTERNAL 不算指定,仍进竞价(无设置指定时)', async () => {
|
|
getBidSettings.mockResolvedValue({
|
|
enabled: true,
|
|
sku_codes: ['MUSHROOM'],
|
|
category_codes: [],
|
|
sku_items: [{ sku_code: 'MUSHROOM', supplier_code: '' }],
|
|
category_items: [],
|
|
});
|
|
query.mockResolvedValueOnce({
|
|
rowCount: 1,
|
|
rows: [
|
|
{ sku_code: 'MUSHROOM', category_code: 'VEG', suppliers: ['INTERNAL'], procure_qty: 1 },
|
|
],
|
|
});
|
|
|
|
const skus = await listOrderSkusNeedingBidProcure({ orderCode: 'ORD_SELF' });
|
|
expect(skus).toEqual(['MUSHROOM']);
|
|
});
|
|
|
|
it('openBidRound 全指定不写假中标、取消轮次并直接分配;混开删除指定明细', () => {
|
|
expect(bidSrc).toMatch(/allDirect/);
|
|
expect(bidSrc).toMatch(/全部指定直供,跳过请报价通知/);
|
|
expect(bidSrc).toMatch(/DELETE FROM bid_round_items WHERE round_id = \$1 AND sku_code = ANY/);
|
|
expect(bidSrc).not.toMatch(/allCategoriesDesignated/);
|
|
expect(bidSrc).not.toMatch(/writeDirectAwards/);
|
|
expect(bidSrc).not.toMatch(/SELECT cost_price FROM purchase_costs/);
|
|
const start = bidSrc.indexOf('export async function openBidRound');
|
|
const next = bidSrc.indexOf('export async function submitBidQuotes');
|
|
const openFn = bidSrc.slice(start, next > start ? next : undefined);
|
|
expect(openFn).toMatch(/status = 'cancelled'/);
|
|
expect(openFn).toMatch(/reprocessOrderAllocation/);
|
|
expect(openFn).not.toMatch(/INSERT INTO bid_awards/);
|
|
});
|
|
|
|
it('分配两条路径盖章且禁止智能分配改派指定 SKU', () => {
|
|
expect(allocSrc).toMatch(/stampDesignatedSuppliersOnOrderItems/);
|
|
expect(allocSrc).toMatch(/const designatedSupplier = designatedBySku\.get/);
|
|
expect(allocSrc).toMatch(/supplierCode: designatedSupplier/);
|
|
});
|
|
|
|
it('竞价设置与历史页文案', () => {
|
|
expect(mgmtSrc).toMatch(/指定供应商(跳过报价,直接供货)/);
|
|
expect(mgmtSrc).toMatch(/不指定(邀同品类全部报价)/);
|
|
expect(mgmtSrc).not.toMatch(/首选供应商(非独家)/);
|
|
expect(histSrc).toMatch(/detail\.round\.status !== 'awarded'/);
|
|
});
|
|
|
|
it('加载范围不把最近中标回填到已保存的空供应商', () => {
|
|
expect(mgmtSrc).toMatch(/已保存供应商(含空=不指定)原样展示/);
|
|
expect(mgmtSrc).not.toMatch(/award && bound\.has\(award\)/);
|
|
expect(mgmtSrc).not.toMatch(/i\.supplier_code \|\| awardsSku/);
|
|
});
|
|
});
|