来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
99 lines
3.1 KiB
TypeScript
99 lines
3.1 KiB
TypeScript
import { describe, expect, it, vi } from 'vitest';
|
|
|
|
vi.mock('../src/db', () => ({
|
|
pool: { query: vi.fn(), connect: vi.fn() },
|
|
getRawPoolQuery: () => vi.fn(),
|
|
}));
|
|
vi.mock('../src/services/bidConfigService', () => ({
|
|
getBidSettings: vi.fn(),
|
|
assertBidEnabled: vi.fn(),
|
|
}));
|
|
vi.mock('../src/services/inventoryStockCoverService', () => ({
|
|
applyStockCoverForOrder: vi.fn(),
|
|
}));
|
|
vi.mock('../src/services/bidAwardService', () => ({
|
|
notifySuppliersBidOpened: vi.fn(),
|
|
}));
|
|
|
|
import {
|
|
isRealBidSupplier,
|
|
resolveDesignatedSupplierForSku,
|
|
} from '../src/services/bidRoundService';
|
|
|
|
const matchExact = (itemCat: string, settingCat: string) => itemCat === settingCat;
|
|
|
|
describe('指定供应商解析', () => {
|
|
it('空码 / INTERNAL / UNASSIGNED 不算真实供应商', () => {
|
|
expect(isRealBidSupplier('')).toBe(false);
|
|
expect(isRealBidSupplier(null)).toBe(false);
|
|
expect(isRealBidSupplier('INTERNAL')).toBe(false);
|
|
expect(isRealBidSupplier('UNASSIGNED')).toBe(false);
|
|
expect(isRealBidSupplier('SUP_A')).toBe(true);
|
|
});
|
|
|
|
it('优先级:订单行 > 商品行 > 分类行', () => {
|
|
expect(
|
|
resolveDesignatedSupplierForSku({
|
|
skuCode: 'MUSHROOM',
|
|
categoryCode: 'VEG',
|
|
orderLineSupplier: 'S_ORDER',
|
|
skuItems: [{ sku_code: 'MUSHROOM', supplier_code: 'S_SKU' }],
|
|
categoryItems: [{ category_code: 'VEG', supplier_code: 'S_CAT' }],
|
|
categoryMatches: matchExact,
|
|
})
|
|
).toBe('S_ORDER');
|
|
});
|
|
|
|
it('订单行自采时回落到商品行指定', () => {
|
|
expect(
|
|
resolveDesignatedSupplierForSku({
|
|
skuCode: 'MUSHROOM',
|
|
categoryCode: 'VEG',
|
|
orderLineSupplier: 'INTERNAL',
|
|
skuItems: [{ sku_code: 'MUSHROOM', supplier_code: 'S_SKU' }],
|
|
categoryItems: [{ category_code: 'VEG', supplier_code: 'S_CAT' }],
|
|
categoryMatches: matchExact,
|
|
})
|
|
).toBe('S_SKU');
|
|
});
|
|
|
|
it('仅商品行指定(分类未填)', () => {
|
|
expect(
|
|
resolveDesignatedSupplierForSku({
|
|
skuCode: 'MUSHROOM',
|
|
categoryCode: 'VEG',
|
|
orderLineSupplier: null,
|
|
skuItems: [{ sku_code: 'MUSHROOM', supplier_code: 'S_SKU' }],
|
|
categoryItems: [{ category_code: 'VEG', supplier_code: '' }],
|
|
categoryMatches: matchExact,
|
|
})
|
|
).toBe('S_SKU');
|
|
});
|
|
|
|
it('仅分类行指定', () => {
|
|
expect(
|
|
resolveDesignatedSupplierForSku({
|
|
skuCode: 'MUSHROOM',
|
|
categoryCode: 'VEG',
|
|
orderLineSupplier: null,
|
|
skuItems: [{ sku_code: 'MUSHROOM', supplier_code: '' }],
|
|
categoryItems: [{ category_code: 'VEG', supplier_code: 'S_CAT' }],
|
|
categoryMatches: matchExact,
|
|
})
|
|
).toBe('S_CAT');
|
|
});
|
|
|
|
it('未指定返回 null,保持多方邀请', () => {
|
|
expect(
|
|
resolveDesignatedSupplierForSku({
|
|
skuCode: 'TOFU',
|
|
categoryCode: 'VEG',
|
|
orderLineSupplier: null,
|
|
skuItems: [{ sku_code: 'MUSHROOM', supplier_code: 'S_SKU' }],
|
|
categoryItems: [{ category_code: 'MEAT', supplier_code: 'S_CAT' }],
|
|
categoryMatches: matchExact,
|
|
})
|
|
).toBeNull();
|
|
});
|
|
});
|