import { describe, it, expect, vi } from 'vitest' import { useGameService } from '../use-game-service' import { useAPI } from '#lib/composables' import { LOBBY_GAME_API } from '#lib/configs/api' import type { PGSoftRequest } from '#lib/types' // Mock `useAPI` composable vi.mock('#lib/composables', () => ({ useAPI: vi.fn(), })) describe('useGameService', () => { it('should call useAPI with correct parameters', async () => { const mockResponse = { success: true, data: 'Game Content', } // Mock the return value of useAPI vi.mocked(useAPI).mockResolvedValue(mockResponse) const { getPGSoftGameHTML } = useGameService() const mockRequestData: PGSoftRequest = { gameId: '1234', token: 'fake-token', } const response = await getPGSoftGameHTML(mockRequestData) // Assert that useAPI was called with correct parameters expect(useAPI).toHaveBeenCalledWith(LOBBY_GAME_API.PG_SOFT_GAMES_ENTRY, { body: mockRequestData, method: 'post', }) // Assert that the response is as expected expect(response).toEqual(mockResponse.data) }) it('should handle API errors gracefully', async () => { const mockError = new Error('API Error') // Mock the return value of useAPI to reject with an error vi.mocked(useAPI).mockRejectedValue(mockError) const { getPGSoftGameHTML } = useGameService() const mockRequestData: PGSoftRequest = { gameId: '1234', token: 'fake-token', } await expect(getPGSoftGameHTML(mockRequestData)).rejects.toThrow( 'API Error', ) }) })