import { readFileSync } from 'node:fs'; import { describe, expect, it } from 'vitest'; describe('mobile pending purchase cost hint', () => { const source = readFileSync( new URL('../src/routes/mobile/mobilePurchaseRoutes.ts', import.meta.url), 'utf8' ); const hintComment = source.indexOf('只读提示兜底'); const purchasePrice = source.lastIndexOf( 'NULLIF(${PURCHASE_ORDER_PRICE_EXPR}, 0)', hintComment ); const actualPrice = source.lastIndexOf('NULLIF(po.actual_price, 0)', hintComment); const orderCost = source.indexOf('NULLIF(oi.unit_cost, 0)', hintComment); const suggestedPriceEnd = source.indexOf('AS suggested_price', orderCost); const suggestedPriceSelect = source.slice(purchasePrice, suggestedPriceEnd); it('reads order item unit_cost after purchase and actual prices', () => { expect(purchasePrice).toBeGreaterThan(-1); expect(actualPrice).toBeGreaterThan(purchasePrice); expect(orderCost).toBeGreaterThan(actualPrice); }); it('keeps the fallback in the read-only suggested price select', () => { expect(suggestedPriceSelect).toContain('只读提示兜底'); expect(suggestedPriceSelect).not.toContain('UPDATE '); expect(suggestedPriceSelect).not.toContain('INSERT '); }); });