来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
166 lines
5.1 KiB
TypeScript
166 lines
5.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { parseBidSettingsForTest } from '../src/services/bidConfigService';
|
|
import {
|
|
evaluateAutoAwardGate,
|
|
isUnrecoverableAutoAwardFailure,
|
|
shouldReleaseEmptyQuoteRound,
|
|
} from '../src/services/bidRoundService';
|
|
|
|
describe('bid auto_award_lowest settings', () => {
|
|
it('defaults auto_award_lowest to false', () => {
|
|
const parsed = parseBidSettingsForTest({ enabled: true });
|
|
expect(parsed.auto_award_lowest).toBe(false);
|
|
});
|
|
|
|
it('parses auto_award_lowest when true', () => {
|
|
const parsed = parseBidSettingsForTest({ auto_award_lowest: true });
|
|
expect(parsed.auto_award_lowest).toBe(true);
|
|
});
|
|
|
|
it('ignores truthy non-boolean auto_award_lowest', () => {
|
|
const parsed = parseBidSettingsForTest({ auto_award_lowest: 1 });
|
|
expect(parsed.auto_award_lowest).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('evaluateAutoAwardGate', () => {
|
|
it('does not auto-award before deadline when switch is off', () => {
|
|
expect(
|
|
evaluateAutoAwardGate({
|
|
autoAwardLowest: false,
|
|
status: 'open',
|
|
pending: 0,
|
|
quoted: 3,
|
|
deadlinePassed: false,
|
|
})
|
|
).toEqual({ proceed: false, reason: 'disabled' });
|
|
});
|
|
|
|
it('auto-awards after deadline even when switch is off', () => {
|
|
expect(
|
|
evaluateAutoAwardGate({
|
|
autoAwardLowest: false,
|
|
status: 'open',
|
|
pending: 0,
|
|
quoted: 2,
|
|
deadlinePassed: true,
|
|
})
|
|
).toEqual({ proceed: true, reason: 'ok' });
|
|
});
|
|
|
|
it('auto-awards after deadline with pending leftovers even when switch is off', () => {
|
|
expect(
|
|
evaluateAutoAwardGate({
|
|
autoAwardLowest: false,
|
|
status: 'closed',
|
|
pending: 1,
|
|
quoted: 2,
|
|
deadlinePassed: true,
|
|
})
|
|
).toEqual({ proceed: true, reason: 'ok' });
|
|
});
|
|
|
|
it('auto-awards when all invited have quoted', () => {
|
|
expect(
|
|
evaluateAutoAwardGate({
|
|
autoAwardLowest: true,
|
|
status: 'open',
|
|
pending: 0,
|
|
quoted: 3,
|
|
deadlinePassed: false,
|
|
})
|
|
).toEqual({ proceed: true, reason: 'ok' });
|
|
});
|
|
|
|
it('waits while some invites are still pending before deadline', () => {
|
|
expect(
|
|
evaluateAutoAwardGate({
|
|
autoAwardLowest: true,
|
|
status: 'open',
|
|
pending: 1,
|
|
quoted: 2,
|
|
deadlinePassed: false,
|
|
})
|
|
).toEqual({ proceed: false, reason: 'waiting_quotes' });
|
|
});
|
|
|
|
it('auto-awards after deadline even with pending leftovers', () => {
|
|
expect(
|
|
evaluateAutoAwardGate({
|
|
autoAwardLowest: true,
|
|
status: 'open',
|
|
pending: 1,
|
|
quoted: 2,
|
|
deadlinePassed: true,
|
|
})
|
|
).toEqual({ proceed: true, reason: 'ok' });
|
|
});
|
|
|
|
it('does not award when nobody quoted', () => {
|
|
expect(
|
|
evaluateAutoAwardGate({
|
|
autoAwardLowest: true,
|
|
status: 'open',
|
|
pending: 0,
|
|
quoted: 0,
|
|
deadlinePassed: true,
|
|
})
|
|
).toEqual({ proceed: false, reason: 'no_quotes' });
|
|
});
|
|
|
|
it('does not award after deadline when nobody quoted even if switch off', () => {
|
|
expect(
|
|
evaluateAutoAwardGate({
|
|
autoAwardLowest: false,
|
|
status: 'open',
|
|
pending: 2,
|
|
quoted: 0,
|
|
deadlinePassed: true,
|
|
})
|
|
).toEqual({ proceed: false, reason: 'no_quotes' });
|
|
});
|
|
|
|
it('skips already awarded rounds', () => {
|
|
expect(
|
|
evaluateAutoAwardGate({
|
|
autoAwardLowest: true,
|
|
status: 'awarded',
|
|
pending: 0,
|
|
quoted: 2,
|
|
deadlinePassed: true,
|
|
})
|
|
).toEqual({ proceed: false, reason: 'already_awarded' });
|
|
});
|
|
});
|
|
|
|
describe('shouldReleaseEmptyQuoteRound', () => {
|
|
it('releases after deadline when nobody quoted', () => {
|
|
expect(shouldReleaseEmptyQuoteRound({ deadlinePassed: true, quoted: 0 })).toBe(true);
|
|
});
|
|
|
|
it('does not release before deadline even with zero quotes', () => {
|
|
expect(shouldReleaseEmptyQuoteRound({ deadlinePassed: false, quoted: 0 })).toBe(false);
|
|
});
|
|
|
|
it('does not release after deadline when someone quoted', () => {
|
|
expect(shouldReleaseEmptyQuoteRound({ deadlinePassed: true, quoted: 1 })).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe('isUnrecoverableAutoAwardFailure', () => {
|
|
it('treats empty suggestion and invalid price as unrecoverable', () => {
|
|
expect(isUnrecoverableAutoAwardFailure('没有可确认的中标报价')).toBe(true);
|
|
expect(isUnrecoverableAutoAwardFailure('商品 SKU1 缺少有效中标价')).toBe(true);
|
|
expect(isUnrecoverableAutoAwardFailure('供应商 S1 未对商品 SKU1 报价,不能中标')).toBe(true);
|
|
expect(isUnrecoverableAutoAwardFailure('竞价功能未开启,请先在竞价设置中开启')).toBe(true);
|
|
});
|
|
|
|
it('does not treat gate or transient reasons as unrecoverable', () => {
|
|
expect(isUnrecoverableAutoAwardFailure('disabled')).toBe(false);
|
|
expect(isUnrecoverableAutoAwardFailure('waiting_quotes')).toBe(false);
|
|
expect(isUnrecoverableAutoAwardFailure('no_quotes')).toBe(false);
|
|
expect(isUnrecoverableAutoAwardFailure('fallback_smart_alloc')).toBe(false);
|
|
expect(isUnrecoverableAutoAwardFailure('connection timeout')).toBe(false);
|
|
});
|
|
});
|