import { describe, it, expect, vi } from 'vitest'; import { queryTokenDistributeRequests } from './distributions'; import { fetchGraphData } from './fetch-graph'; import { Address } from 'viem'; import { PrexApiService } from '../api'; vi.mock('./fetch-graph', () => ({ fetchGraphData: vi.fn(), })); describe('queryTokenDistributeRequests', () => { const CHAIN_ID = 1337; const USER_ADDRESS = '0x0000000000000000000000000000000000000001' as Address; const mockApiService = { chainId: CHAIN_ID } as PrexApiService; it('should fetch and transform token distribute requests', async () => { const mockResponse = { tokenDistributeRequests: [ { id: '0x01', status: 'PENDING', name: 'test', maxAmountPerAddress: '100', expiry: '1000', token: { id: '0x02', }, sender: { id: '0x03', name: 'test', }, coordinate: '0x04', cooltime: '60', amountPerWithdrawal: '10', amount: '1000', totalAmount: '1000', createdAt: '1234567890', txHash: '0x05', }, ], }; vi.mocked(fetchGraphData).mockResolvedValue(mockResponse); const result = await queryTokenDistributeRequests( mockApiService, { user: USER_ADDRESS }, 0, 10 ); expect(fetchGraphData).toHaveBeenCalledWith( mockApiService, 'tokenDistributeRequests', expect.any(String), { offset: 0, limit: 10, address: USER_ADDRESS.toLowerCase(), } ); expect(result).toEqual([ { id: '0x01', status: 'PENDING', name: 'test', maxAmountPerAddress: 100n, expiry: 1000, token: '0x02', sender: '0x03', senderName: 'test', coordinate: '0x04', cooltime: 60, amountPerWithdrawal: 10n, amount: 1000n, totalAmount: 1000n, createdAt: 1234567890, txHash: '0x05', }, ]); }); });