Files
SupplierSystem/server/tests/purchaseAssignDefault.test.ts
T
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

42 lines
1.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import assert from 'node:assert/strict';
import { describe, it } from 'vitest';
import { parsePurchaseAssignDefaultConfig } from '../src/services/purchaseAssignDefaultConfigService';
import { pickLeastLoadedPurchaserPure } from '../src/services/purchaserAssignmentService';
function testParseConfig() {
assert.equal(parsePurchaseAssignDefaultConfig(null).mode, null);
assert.equal(parsePurchaseAssignDefaultConfig({ mode: 'nope' }).mode, null);
const ok = parsePurchaseAssignDefaultConfig({ mode: 'to_purchaser', purchaser_code: 'PUR002' });
assert.equal(ok.mode, 'to_purchaser');
assert.equal(ok.purchaser_code, 'PUR002');
assert.equal(parsePurchaseAssignDefaultConfig({ mode: 'free_pool' }).mode, 'free_pool');
}
function testPickLeastLoaded() {
const purchasers = [
{ purchaser_code: 'PUR001', purchaser_name: '甲', is_primary: true },
{ purchaser_code: 'PUR002', purchaser_name: '乙', is_primary: false },
];
const held = new Map<string, Set<string>>([
['PUR001', new Set(['sku:A'])],
['PUR002', new Set(['sku:B', 'sku:C'])],
]);
// 同组已有 → 跟原人
const same = pickLeastLoadedPurchaserPure(purchasers, 'sku:A', held);
assert.equal(same?.purchaser_code, 'PUR001');
// 新组 → 组数更少的 PUR001(1 < 2)
const neu = pickLeastLoadedPurchaserPure(purchasers, 'sku:Z', held);
assert.equal(neu?.purchaser_code, 'PUR001');
// 并列 0:主采购员优先
const empty = new Map<string, Set<string>>();
const first = pickLeastLoadedPurchaserPure(purchasers, 'sku:X', empty);
assert.equal(first?.purchaser_code, 'PUR001');
}
describe('purchaseAssignDefault', () => {
it('配置解析 / 最少负载选人契约(原 assert 脚本迁移为 vitest 用例)', () => {
testParseConfig();
testPickLeastLoaded();
});
});