import { describe, it, expect, vi, beforeEach } from 'vitest' import type { CasinoGameItem } from '#lib/types/game' import { useCasino } from '../use-casino' import { IFRAME_GAME_API } from '#lib/constants' vi.mock('nuxt/app', () => ({ useRuntimeConfig: vi.fn().mockReturnValue({ public: { SITE_DOMAIN: 'https://your-site.com/', GAME_PROVIDERS_DISABLED: ['spribe'], }, }), useRoute: vi.fn(() => ({ fullpath: vi.fn(), })), useCookie: vi.fn().mockReturnValue(''), useNuxtData: vi.fn().mockReturnValue({ data: [], }), useAsyncData: vi.fn().mockReturnValue({ data: [], }), })) const mockUseGame = { playGame: vi.fn(), } const mockCheckGame = { showMaintenanceProvider: vi.fn(), } vi.mock('#lib/composables', () => ({ useGames: () => mockUseGame, useCheckGame: () => mockCheckGame, })) vi.mock('#lib/composables/service/use-api-fetch', () => ({ useApiFetch: vi.fn().mockReturnValue({ request: vi.fn(), }), })) vi.mock('#imports', () => ({ persistedState: vi.fn().mockReturnValue({ localStorage: {}, }), })) describe('useCasino', () => { const props = { gameLimit: 10 } describe('playCasinoGame', () => { const { playCasinoGame } = useCasino(props) it('should call playGame with correct params for EVOLUTION provider', async () => { const item: CasinoGameItem = { title: 'Fan Tan', gameName: 'Fan Tan', img: { thumbnail: { url: 'https://wp.red88.com/wp-content/uploads/2022/03/livecasino-fantan.jpg', }, }, group: ['hot'], category: ['fan-tan'], provider: 'evolution', tableId: 'FanTan0000000001', gameId: 'lcevo_1006fantan:', range: '4 Đ - 20.000 Đ', loginRequired: true, newTab: false, wallet: 'SUB_WALLET', feature: true, } await playCasinoGame(item) expect(mockUseGame.playGame).toHaveBeenCalledWith({ gameUrl: `/${IFRAME_GAME_API.LIVE_CASINO}?category=${item.category}&tableId=${item.tableId}`, newTab: true, promotionPrevent: true, promotionPrevent100K: true, loginRequired: true, moneyRequired: true, isCasino: true, }) }) it('should call playGame with correct params for EBET provider', async () => { const item: CasinoGameItem = { title: 'Dragon Tiger 12', gameName: 'Dragon Tiger 12', img: { thumbnail: { url: 'https://wp.red88.com/wp-content/uploads/2022/03/livecasino-Rongho5.png', }, }, category: ['dragon-tiger'], provider: 'ebet', range: '1 Đ - 100.000 Đ', tableCode: 'STUDIO-DT-12', loginRequired: true, newTab: false, wallet: 'SUB_WALLET', } await playCasinoGame(item) expect(mockUseGame.playGame).toHaveBeenCalledWith({ provider: 'ebet', gameId: 'ebet-casino&tableCode=STUDIO-DT-12', urlLocation: '&redirecturl=http://localhost:3000/', newTab: true, promotionPrevent: true, promotionPrevent100K: true, loginRequired: true, moneyRequired: true, withoutIframe: true, }) }) it('should call playGame with correct params for VIVO provider', async () => { const item: CasinoGameItem = { title: 'Casino Hold’em', gameName: 'Casino Hold’em', img: { thumbnail: { url: 'https://wp.red88.com/wp-content/uploads/2022/03/Casino-Holdem.png', }, }, group: ['hot'], category: ['casino-holdem'], provider: 'vivo', subTitle: '', tableCode: '256', loginRequired: true, newTab: false, wallet: 'SUB_WALLET', } await playCasinoGame(item) expect(mockUseGame.playGame).toHaveBeenCalledWith({ provider: 'vivo', gameId: 'vivo-casino&tableCode=256', urlLocation: '&application=casinoholdem&tableid=256', newTab: true, promotionPrevent: true, promotionPrevent100K: true, loginRequired: true, moneyRequired: true, withoutIframe: true, }) }) it('should call playGame with correct params without tableCode for VIVO provider', async () => { const item: CasinoGameItem = { title: 'Casino Hold’em', gameName: 'Casino Hold’em', img: { thumbnail: { url: 'https://wp.red88.com/wp-content/uploads/2022/03/Casino-Holdem.png', }, }, group: ['hot'], category: ['casino-holdem'], provider: 'vivo', subTitle: '', tableCode: '', loginRequired: true, newTab: false, wallet: 'SUB_WALLET', } await playCasinoGame(item) expect(mockUseGame.playGame).toHaveBeenCalledWith({ provider: 'vivo', gameId: 'vivo-casino&tableCode=', urlLocation: '', newTab: true, promotionPrevent: true, promotionPrevent100K: true, loginRequired: true, moneyRequired: true, withoutIframe: true, }) }) it('should call playGame with correct params without provider', async () => { const item: CasinoGameItem = { title: 'Casino Hold’em', gameName: 'Casino Hold’em', img: { thumbnail: { url: 'https://wp.red88.com/wp-content/uploads/2022/03/Casino-Holdem.png', }, }, group: ['hot'], category: ['casino-holdem'], provider: '', subTitle: '', tableCode: '', loginRequired: true, newTab: false, wallet: 'SUB_WALLET', subType: 'test', type: 'test', } await playCasinoGame(item) expect(mockUseGame.playGame).toHaveBeenCalledWith({ provider: '', gameId: '-casino&tableCode=&subGameType=test&gameType=test', urlLocation: '', newTab: true, promotionPrevent: true, promotionPrevent100K: true, loginRequired: true, moneyRequired: true, withoutIframe: true, }) }) }) describe('filterCasinoGames', () => { const props = { gameLimit: 10 } it('should update currentPage correctly', () => { const { filterCasinoGames, currentPage } = useCasino(props) filterCasinoGames({}, { prov: 'provider1', limit: 5, paged: 2 }) expect(currentPage.value).toBe(2) }) }) })