来源仓库: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 经哈希比对与线上同值), 整包推送会把这些凭据永久带入本仓库,故只取「当前版本」的单提交快照。 供应商系统后续开发自本提交开始。
53 lines
2.6 KiB
TypeScript
53 lines
2.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { readFileSync } from 'fs';
|
|
import path from 'path';
|
|
import { isAllocationHoldActive } from '../src/services/bidRoundService';
|
|
|
|
describe('中标与手调 hold 同事务(不误伤其它口径)', () => {
|
|
const bidSrc = readFileSync(path.join(__dirname, '../src/services/bidRoundService.ts'), 'utf8');
|
|
const awardSrc = readFileSync(path.join(__dirname, '../src/services/bidAwardService.ts'), 'utf8');
|
|
const allocSrc = readFileSync(
|
|
path.join(__dirname, '../src/services/orderAllocationService.ts'),
|
|
'utf8'
|
|
);
|
|
|
|
it('confirmBidAwards 在 COMMIT 前写入 hold_until 或 released_at', () => {
|
|
const fnStart = bidSrc.indexOf('export async function confirmBidAwards');
|
|
const fnEnd = bidSrc.indexOf('export async function releaseBidAllocationHold');
|
|
const body = bidSrc.slice(fnStart, fnEnd);
|
|
expect(body).toMatch(/await client\.query\('BEGIN'\)/);
|
|
expect(body).toMatch(/allocation_hold_until = NOW\(\) \+ \(\$2::int \* INTERVAL '1 minute'\)/);
|
|
expect(body).toMatch(/allocation_hold_released_at = NOW\(\)/);
|
|
const commitAt = body.indexOf("await client.query('COMMIT')");
|
|
const holdUntilAt = body.indexOf('allocation_hold_until = NOW()');
|
|
const releasedAt = body.lastIndexOf('allocation_hold_released_at = NOW()');
|
|
expect(commitAt).toBeGreaterThan(0);
|
|
expect(holdUntilAt).toBeGreaterThan(0);
|
|
expect(holdUntilAt).toBeLessThan(commitAt);
|
|
expect(releasedAt).toBeGreaterThan(0);
|
|
expect(releasedAt).toBeLessThan(commitAt);
|
|
expect(body).toMatch(/holdMinutes <= 0/);
|
|
expect(body).toMatch(/reprocessOrderAllocation/);
|
|
});
|
|
|
|
it('自动中标按订单分公司读设置', () => {
|
|
expect(bidSrc).toMatch(/async function resolveSettingsBranchForRound/);
|
|
expect(bidSrc).toMatch(/settingsBranch = await resolveSettingsBranchForRound/);
|
|
const autoStart = bidSrc.indexOf('export async function tryAutoAwardAndAllocate');
|
|
const autoSlice = bidSrc.slice(autoStart, autoStart + 3500);
|
|
expect(autoSlice).toMatch(/branchCode: settingsBranch/);
|
|
});
|
|
|
|
it('until 为空仍不算手调中(历史轮 / hold=0)', () => {
|
|
expect(isAllocationHoldActive({ allocation_hold_until: null })).toBe(false);
|
|
expect(awardSrc).toMatch(/r\.allocation_hold_until IS NULL/);
|
|
});
|
|
|
|
it('指定直供与无人报价降级路径未改闸门语义', () => {
|
|
expect(allocSrc).toMatch(/stampDesignatedSuppliersOnOrderItems/);
|
|
expect(bidSrc).toMatch(/skipPerOrderAutoBidGate: true/);
|
|
expect(bidSrc).toMatch(/fallbackFailedAwardRoundToSmartAlloc/);
|
|
expect(bidSrc).toMatch(/allocation_hold_released_at IS NOT NULL/);
|
|
});
|
|
});
|