import { describe, it, expect, vi, beforeEach } from 'vitest' import { useDepositService } from '../use-deposit-service' import { useAPI } from '#lib/composables' import { CRYPTO_API, DEPOSIT_API } from '#lib/configs/api' import type { BaseResponse } from '#lib/types/api' import type { EWalletResponseItem, CryptoDataResponse, } from '#lib/types/deposit' // Mock the useAPI function vi.mock('#lib/composables', () => ({ useAPI: vi.fn(), })) vi.mock('nuxt/app', () => ({ useNuxtApp: vi.fn().mockReturnValue({ $transaction: { histories: vi.fn(), }, }), useRuntimeConfig: vi.fn(() => ({ public: { API_URL: 'https://your-site.com/', }, })), useCookie: vi.fn().mockReturnValue({ get: vi.fn().mockReturnValue('mock-token'), }), })) describe('useDepositService composable', () => { beforeEach(() => { vi.clearAllMocks() }) it('should fetch e-wallet code', async () => { const mockResponse: BaseResponse = { success: true, data: 'mock-ewallet-code', } vi.mocked(useAPI).mockResolvedValue({ data: mockResponse }) const { fetchEWalletCodeService } = useDepositService() const response = await fetchEWalletCodeService() expect(useAPI).toHaveBeenCalledWith(DEPOSIT_API.DEPOSIT_E_WALLET_CODE) expect(response.data).toEqual(mockResponse) }) it('should fetch e-wallets list', async () => { const mockEWallets: EWalletResponseItem[] = [ { id: 1, name: 'Wallet A', isActive: true }, { id: 2, name: 'Wallet B', isActive: false }, ] const mockResponse: BaseResponse = { success: true, data: mockEWallets, } vi.mocked(useAPI).mockResolvedValue({ data: mockResponse }) const { fetchEWalletsService } = useDepositService() const response = await fetchEWalletsService() expect(useAPI).toHaveBeenCalledWith(DEPOSIT_API.DEPOSIT_E_WALLET_LIST) expect(response.data).toEqual(mockResponse) }) it('should fetch cryptocurrency data', async () => { const mockCryptoData: CryptoDataResponse = { price: 50000, change: 1.5, symbol: 'BTC', } const mockResponse: BaseResponse = { success: true, data: mockCryptoData, } vi.mocked(useAPI).mockResolvedValue({ data: mockResponse }) const { fetchCrypto } = useDepositService() const response = await fetchCrypto() expect(useAPI).toHaveBeenCalledWith(CRYPTO_API.CRYPTO) expect(response.data).toEqual(mockResponse) }) })