import { beforeEach, describe, expect, it, vi } from 'vitest' const client = vi.hoisted(() => ({ get: vi.fn() })) vi.mock('@/shared/api/http', async original => ({ ...await original(), http: client })) import { getStorageRentLot, listStorageRentLots, listStorageRentWarehouses } from './storageRent' const base = '/platform/v1/last-leg/storage-rent' const envelope = (data: T) => ({ code: '200', message: 'success', data }) const lot = { id: '9223372036854775001', customerId: '9223372036854775002', warehouseId: '9223372036854775003', businessNo: 'WT1' } describe('仓租查询接口', () => { beforeEach(() => vi.clearAllMocks()) it('uses the paginated root endpoint with server filters and preserves long IDs', async () => { client.get.mockResolvedValue(envelope({ records: [lot], total: '1', page: 1, size: 20, pages: 1 })) const params = { page: 1, size: 20, businessType: 'WAREHOUSE_TRANSFER', warehouseId: lot.warehouseId, status: 'IN_STOCK' } const result = await listStorageRentLots(params) expect(client.get).toHaveBeenCalledWith(base, { params }) expect(result.total).toBe(1) expect(result.records[0]).toMatchObject(lot) }) it('reads a lot with its actual charges and warehouse options from dedicated endpoints', async () => { const charge = { id: '9223372036854775004', outboundNo: 'OUT1', quantity: 2, originalAmount: 23, currency: 'CNY', settlementAmount: 23 } const currencyLot = { ...lot, generatedAmount: null, generatedCurrency: null, generatedAmounts: [{ currency: 'USD', amount: 12 }, { currency: 'CNY', amount: 23 }] } client.get.mockResolvedValueOnce(envelope({ lot: currencyLot, charges: [charge] })) .mockResolvedValueOnce(envelope([{ id: lot.warehouseId, warehouseName: '测试仓' }])) const detail = await getStorageRentLot(lot.id) expect(client.get).toHaveBeenNthCalledWith(1, `${base}/${lot.id}`) expect(detail.lot.id).toBe(lot.id) expect(detail.lot).toMatchObject(currencyLot) expect(detail.charges).toEqual([charge]) expect(await listStorageRentWarehouses()).toEqual([{ id: lot.warehouseId, warehouseName: '测试仓' }]) expect(client.get).toHaveBeenNthCalledWith(2, `${base}/warehouse-options`) }) })