import { describe, it, expect, vi, beforeEach } from 'vitest' import { useCheckGame } from '../use-check-game' import { GameProviderEnum } from '#lib/enums' import { ATHENA_GAMES } from '#lib/constants' // Mock dependencies const mockGameToast = { onShowCommingSoon: vi.fn(), onShowPromotionPrevent: vi.fn(), onShowNotEnoughBalance: vi.fn(), openModalMaintainAthenaGames: vi.fn(), openMaintainProvider: vi.fn(), } const mockAuth = { isOpenAuthentication: { value: false }, } const mockUser = { token: { value: null }, user: { value: 'user' }, subBalance: { value: 0 }, denyGameIds: { value: [] }, balance: { value: 0 }, } const mockPromotion = { isUsingPromotion: { value: false, }, isBonus: { value: false, }, isCompletedPromotionBonus: vi.fn(), } const mockPromotionStore = { getPackageId: vi.fn(), getUserPlan: vi.fn(), } const mockMaintenanceGamesStore = { isMaintain: false, } const mockEnvironment = { public: { GAME_PROVIDERS_DISABLED: [], }, } vi.mock('#lib/composables', () => ({ useGameToast: () => mockGameToast, useUser: () => mockUser, usePromotion: () => mockPromotion, })) vi.mock('#lib/stores', () => ({ useUserPromotionStore: () => mockPromotionStore, useMaintenanceGamesStore: () => mockMaintenanceGamesStore, })) vi.mock('nuxt/app', () => ({ useRuntimeConfig: () => mockEnvironment, })) describe('useCheckGame', () => { beforeEach(() => { vi.clearAllMocks() vi.resetAllMocks() }) it('should show coming soon modal if game is marked as coming soon', () => { const { checkConditionsOfGame, checkCommingSoon } = useCheckGame() const mockGame = { isCommingSoon: true } const result = checkConditionsOfGame(mockGame) expect(result).toBe(true) }) it('should return true if the provider is under maintenance', () => { mockEnvironment.public.GAME_PROVIDERS_DISABLED = [GameProviderEnum.PGSOFT] const { checkConditionsOfGame } = useCheckGame() const mockGame = { provider: GameProviderEnum.PGSOFT } const result = checkConditionsOfGame(mockGame) expect(result).toBe(true) }) it('should return true if the game is under Athena maintenance', () => { mockMaintenanceGamesStore.isMaintain = true const { checkConditionsOfGame } = useCheckGame() const mockGame = { gameId: ATHENA_GAMES[0].id } const result = checkConditionsOfGame(mockGame) expect(result).toBe(true) }) it('should return true if the user is not logged in and game requires login', () => { const { checkConditionsOfGame } = useCheckGame() const mockGame = { loginRequired: true } const result = checkConditionsOfGame(mockGame) expect(result).toBe(true) }) it('should return true if the user has insufficient balance to play the game', () => { mockUser.subBalance.value = 0 const { checkConditionsOfGame } = useCheckGame() const mockGame = { moneyRequired: true } const result = checkConditionsOfGame(mockGame) expect(result).toBe(true) }) it('should return true if the game promotion is prevented by various conditions', () => { mockEnvironment.public.GAME_PROVIDERS_DISABLED = [] mockUser.denyGameIds.value = ['1234'] mockPromotion.isUsingPromotion.value = true const { checkConditionsOfGame } = useCheckGame() const mockGame = { provider: GameProviderEnum.PGSOFT, category: ['SLOTS'], gameId: '1234', promotionPrevent: true, } const result = checkConditionsOfGame(mockGame) expect(result).toBe(true) }) it('should return false if no special conditions apply to the game', () => { const { checkConditionsOfGame } = useCheckGame() const mockGame = { isCommingSoon: false, loginRequired: false, moneyRequired: false, promotionPrevent: false, provider: 'provider', } const result = checkConditionsOfGame(mockGame) expect(result).toBe(false) }) it('should return true and trigger maintenance modal if provider is under maintenance', () => { mockEnvironment.public.GAME_PROVIDERS_DISABLED = [GameProviderEnum.PGSOFT] const { showMaintenanceProvider } = useCheckGame() const result = showMaintenanceProvider(GameProviderEnum.PGSOFT) expect(result).toBe(true) expect(mockGameToast.openMaintainProvider).toHaveBeenCalled() }) })