import { describe, it, expect, beforeEach, vi } from 'vitest' import { useJackpot } from '../use-jackpot' import { useNuxtApp } from 'nuxt/app' const mockJackpotStore = { getJackpot: vi.fn(), setJackpot: vi.fn(), } const mockNadal = { game: { slot: { jackpot: vi.fn().mockResolvedValue({ game1: 100, game2: 200 }), }, }, } vi.mock('#lib/stores/jackpot', () => ({ useJackpotStore: () => mockJackpotStore, })) vi.mock('#lib/composables', () => ({ useNadal: () => mockNadal, })) describe('useJackpot composable', () => { it('should fetch game jackpots and update the store', async () => { const mockData = { game1: 100, game2: 200 } const { fetchGameJackpots, isLoading } = useJackpot() await fetchGameJackpots() expect(isLoading.value).toBe(false) expect(mockJackpotStore.setJackpot).toHaveBeenCalledWith(mockData) }) it('should compute total jackpots correctly', () => { mockJackpotStore.getJackpot.mockReturnValue({ game1: 100, game2: 200 }) const { totalJackpots } = useJackpot() expect(totalJackpots.value).toBe(300) }) it('should return the correct jackpot amount by game ID', () => { mockJackpotStore.getJackpot.mockReturnValue({ game1: 100, game2: 200 }) const { getJackpotNumberByGameId } = useJackpot() expect(getJackpotNumberByGameId('game1')).toBe(100) expect(getJackpotNumberByGameId('game2')).toBe(200) expect(getJackpotNumberByGameId('game3')).toBe(0) }) it('should handle empty jackpots gracefully', () => { mockJackpotStore.getJackpot.mockReturnValue(null) const { totalJackpots, getJackpotNumberByGameId } = useJackpot() expect(totalJackpots.value).toBe(0) expect(getJackpotNumberByGameId('game1')).toBe(0) }) })