Files
SupplierSystem/server/tests/bidInviteMatch.test.ts
T
Ubuntu deb3e72750
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
chore: 以 AI 生鲜配送系统 当前版本作为 SupplierSystem 起点
来源仓库: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 经哈希比对与线上同值),
整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。
供应商系统后续开发自本提交开始。
2026-10-08 17:35:43 +08:00

105 lines
3.6 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import type { CategoryRow } from '../src/services/categoryCatalogService';
import {
categoryInExpandedSet,
resolveCategoryInviteSuppliers,
} from '../src/services/bidRoundService';
function cat(
category_code: string,
parent_code: string | null,
level: number,
category_name = category_code
): CategoryRow {
return {
category_code,
parent_code,
category_name,
level,
sort_order: 0,
loss_threshold: null,
is_fresh: false,
merge_same_day_fulfillment: false,
status: 1,
};
}
describe('bid invite category match', () => {
const rows: CategoryRow[] = [
cat('BR001_VEG', null, 1, '蔬菜'),
cat('BR001_LEAF', 'BR001_VEG', 2, '叶菜'),
cat('BR001_GANZA', null, 1, '干杂'),
cat('BR001_EGG', null, 1, '蛋类'),
];
it('invites supplier bound to parent when item is leaf', () => {
const invited = resolveCategoryInviteSuppliers(
['BR001_LEAF'],
rows,
[
{ supplier_code: 'S_PARENT', category_code: 'BR001_VEG' },
{ supplier_code: 'S_OTHER', category_code: 'BR001_MEAT' },
],
'BR001'
);
expect(invited).toContain('S_PARENT');
expect(invited).not.toContain('S_OTHER');
});
it('invites exact leaf binding and bare/prefix variants', () => {
const invited = resolveCategoryInviteSuppliers(
['LEAF'],
rows,
[{ supplier_code: 'S_LEAF', category_code: 'BR001_LEAF' }],
'BR001'
);
expect(invited).toContain('S_LEAF');
});
it('categoryInExpandedSet matches branch prefix variants', () => {
const expanded = new Set(['BR001_VEG', 'BR001_LEAF']);
expect(categoryInExpandedSet('LEAF', expanded, 'BR001')).toBe(true);
expect(categoryInExpandedSet('BR001_LEAF', expanded, 'BR001')).toBe(true);
expect(categoryInExpandedSet('MEAT', expanded, 'BR001')).toBe(false);
});
it('does not invite egg supplier after rebind away from 干杂', () => {
const invited = resolveCategoryInviteSuppliers(
['BR001_GANZA'],
rows,
[
{ supplier_code: 'S_EGG', category_code: 'BR001_EGG' },
{ supplier_code: 'S_GANZA', category_code: 'BR001_GANZA' },
],
'BR001'
);
expect(invited).toContain('S_GANZA');
expect(invited).not.toContain('S_EGG');
});
it('category-only invite set is driven by live supplier_categories bindings', () => {
// 模拟:sku_suppliers 仍挂着蛋商,但经营分类已改绑蛋类 —— 分类邀请不应包含蛋商
const liveBindings = [{ supplier_code: 'S_EGG', category_code: 'BR001_EGG' }];
const invited = resolveCategoryInviteSuppliers(['GANZA'], rows, liveBindings, 'BR001');
expect(invited).not.toContain('S_EGG');
expect(invited).toEqual([]);
});
it('经营品类闸门:单供应商绑定下,跨分类商品不可报价', () => {
// 报价侧闸门(resolveSupplierQuotableSkus)就是拿该供应商自己的绑定跑这个函数:
// 只报自己品类内的商品,跨分类的返回空集 → 拒绝报价。
const ganzaBindings = [{ supplier_code: 'S_GANZA', category_code: 'BR001_GANZA' }];
expect(resolveCategoryInviteSuppliers(['BR001_EGG'], rows, ganzaBindings, 'BR001')).toEqual([]);
expect(resolveCategoryInviteSuppliers(['BR001_GANZA'], rows, ganzaBindings, 'BR001')).toContain(
'S_GANZA'
);
});
it('经营品类闸门:绑定父类时子类商品仍可报价', () => {
const parentBindings = [{ supplier_code: 'S_PARENT', category_code: 'BR001_VEG' }];
expect(resolveCategoryInviteSuppliers(['BR001_LEAF'], rows, parentBindings, 'BR001')).toContain(
'S_PARENT'
);
});
});