import { afterEach, describe, expect, it, vi } from 'vitest'; import { getBrokerOperations, getBrokerPositions } from './broker'; describe('broker api', () => { afterEach(() => { vi.restoreAllMocks(); }); it('serializes operations query parameters', async () => { vi.spyOn(globalThis, 'fetch').mockResolvedValue({ ok: true, json: async () => ({ data: { data: { accountId: 'acc-1', items: [], nextCursor: null, hasNext: false, asOf: 'now' }, meta: { fromCache: false, cachedAt: null }, }, }), } as Response); await getBrokerOperations('acc-1', { cursor: 'c1', limit: 50 }); expect(fetch).toHaveBeenCalledWith( expect.stringContaining('/api/v1/broker/accounts/acc-1/operations?cursor=c1&limit=50'), expect.any(Object), ); }); it('serializes operations query parameters including operationTypes', async () => { vi.spyOn(globalThis, 'fetch').mockResolvedValue({ ok: true, json: async () => ({ data: { data: { accountId: 'acc-1', items: [], nextCursor: null, hasNext: false, asOf: 'now' }, meta: { fromCache: false, cachedAt: null }, }, }), } as Response); await getBrokerOperations('acc-1', { cursor: 'c1', limit: 10, operationTypes: 'OPERATION_TYPE_COUPON', }); expect(fetch).toHaveBeenCalledWith( expect.stringContaining( '/api/v1/broker/accounts/acc-1/operations?cursor=c1&limit=10&operationTypes=OPERATION_TYPE_COUPON', ), expect.any(Object), ); }); it('serializes positions query parameters', async () => { vi.spyOn(globalThis, 'fetch').mockResolvedValue({ ok: true, json: async () => ({ data: { data: { accountId: 'acc-1', items: [], nextCursor: null, hasNext: false, asOf: 'now' }, meta: { fromCache: false, cachedAt: null }, }, }), } as Response); await getBrokerPositions('acc-1', { cursor: 'pos-1', limit: 5 }); expect(fetch).toHaveBeenCalledWith( expect.stringContaining('/api/v1/broker/accounts/acc-1/positions?cursor=pos-1&limit=5'), expect.any(Object), ); }); });