// Test script for tournaments functionality require('dotenv').config(); const PlayerService = require('../services/PlayerService'); async function testTournamentsAPI() { console.log('šŸ† Testing Tournaments API Functions...\n'); const playerService = new PlayerService(); try { // Test 1: Get all tournaments console.log('šŸ“‹ Test 1: Fetching all tournaments...'); console.log('=' .repeat(50)); const tournamentsData = await playerService.getTournamentsData(); if (tournamentsData && tournamentsData.success !== false) { console.log('āœ… Successfully fetched tournaments data!'); console.log(`šŸ“Š Response structure:`, Object.keys(tournamentsData)); // Show some basic info about the tournaments if (Array.isArray(tournamentsData.tournaments)) { console.log(`šŸŽÆ Found ${tournamentsData.tournaments.length} tournaments`); // Show first few tournaments as examples const sampleSize = Math.min(3, tournamentsData.tournaments.length); console.log(`\nšŸ“– Sample tournaments (showing ${sampleSize}):`); for (let i = 0; i < sampleSize; i++) { const tournament = tournamentsData.tournaments[i]; console.log(` ${i + 1}. ${tournament.name || tournament.title || 'Unknown'} (ID: ${tournament.id || 'N/A'})`); } } else if (Array.isArray(tournamentsData)) { console.log(`šŸŽÆ Found ${tournamentsData.length} tournaments (direct array)`); const sampleSize = Math.min(3, tournamentsData.length); console.log(`\nšŸ“– Sample tournaments (showing ${sampleSize}):`); for (let i = 0; i < sampleSize; i++) { const tournament = tournamentsData[i]; console.log(` ${i + 1}. ${tournament.name || tournament.title || 'Unknown'} (ID: ${tournament.id || 'N/A'})`); } } else { console.log('šŸ“Š Response data:', JSON.stringify(tournamentsData, null, 2)); } } else { console.log('āŒ Failed to fetch tournaments data'); console.log('Error:', tournamentsData?.error || 'Unknown error'); } console.log('\n' + '=' .repeat(50)); // Test 2: Try to get specific tournament data (if we have any tournament IDs) console.log('\nšŸŽÆ Test 2: Testing single tournament fetch...'); console.log('=' .repeat(50)); // Try with a sample tournament ID (you might need to adjust this based on actual data) const testTournamentId = '1'; // Start with ID 1 as a common starting point console.log(`šŸ“‹ Fetching tournament with ID: ${testTournamentId}`); const singleTournament = await playerService.getTournamentData(testTournamentId); if (singleTournament && singleTournament.success !== false) { console.log('āœ… Successfully fetched single tournament data!'); console.log('šŸ“Š Tournament details:'); console.log(` Name: ${singleTournament.name || singleTournament.title || 'Unknown'}`); console.log(` Game: ${singleTournament.game || singleTournament.game_name || 'Unknown'}`); console.log(` Status: ${singleTournament.status || 'Unknown'}`); } else { console.log(`āŒ Failed to fetch tournament with ID: ${testTournamentId}`); console.log('Error:', singleTournament?.error || 'Unknown error'); console.log('šŸ’” This might be normal if tournament ID 1 doesn\'t exist'); } } catch (error) { console.error('āŒ Test failed with error:', { message: error.message, stack: error.stack }); } console.log('\nšŸ Tournament API testing completed!'); } // Run the test if (require.main === module) { testTournamentsAPI().catch(console.error); } module.exports = { testTournamentsAPI };