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/); }); });