import { describe, expect, it, vi } from 'vitest'; import { getClaimableStockQty } from '../src/services/inventoryStockCoverService'; describe('getClaimableStockQty', () => { it('subtracts other-order reservations from available', async () => { const query = vi.fn(async (sql: string) => { if (sql.includes('FROM inventory') && sql.includes('SUM(available_qty)')) { return { rows: [{ total: 20 }] }; } if (sql.includes('FROM inventory_reservations')) { return { rows: [{ total: 7 }] }; } return { rows: [{ total: 0 }] }; }); const claimable = await getClaimableStockQty( { query } as never, 'SKU1', 'BR002', 'ORD_A' ); expect(claimable).toBe(13); expect(query).toHaveBeenCalled(); }); });