Files
SupplierSystem/server/tests/bidDesignatedDirectAward.test.ts
Ubuntu 5fa2bbfd55
CI / server typecheck + tests (push) Canceled after 0s
CI / web typecheck + tests + miniprogram syntax (push) Canceled after 0s
CI / eslint (观察项,C7 骨架) (push) Canceled after 0s
CI / npm audit (critical 硬拦) (push) Canceled after 0s
fix(audit-20261019): T1-T9 审计修复、存储归属与审计日志列宽
- T1 资金/库存/报价/自采 P1(BIZ-1/2/3/4/10/13/14)
- T2 主系统反向事件墓碑/改派/孤儿处理(BIZ-6/8/9)
- T3 选分公司 ticket、trust proxy、角色权限收口(SEC-2/3/4)
- T4 缺列/RLS/tenant 名单/FK/迁移执行器(DATA-1..8)
- T5 401 登出/分页/映射口径/blob/ZIP 中文名(FE-1..4/BIZ-15)
- T6 测试脚本目标守卫/config fail-fast/容器配置(OPS-2..8)
- T7 前后端测试与 lint 门禁清零
- T8 应付卡片按关联订单日(口径 A)
- T9 存储对象全链路归属校验、敏感列禁写、审计 target_id 超长修复
2026-10-19 16:16:51 +08:00

152 lines
5.4 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');
const zhBids = readFileSync(path.join(__dirname, '../../src/i18n/locales/zh-CN/bids.ts'), '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('竞价设置与历史页文案', () => {
// 文案已迁 i18n:页面用 key,中文文案在 zh-CN/bids.ts(语义不变)
expect(mgmtSrc).toContain('bids.scope.designateSupplier');
expect(mgmtSrc).toContain('bids.scope.noDesignate');
expect(zhBids).toContain('指定供应商(跳过报价,直接供货)');
expect(zhBids).toContain('不指定(邀同品类全部报价)');
expect(zhBids).not.toContain('首选供应商(非独家)');
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/);
});
});