- Remove unused variables and imports across codebase - Use empty catch blocks where error object not needed - Remove unused fs, path imports from apply-grand-prize-migration.js - Remove unused OAuth2Client from oauth.controller.js - Update dependencies to latest patch versions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
109 lines
3.9 KiB
JavaScript
109 lines
3.9 KiB
JavaScript
/**
|
|
* Test de l'endpoint eligible-participants
|
|
*/
|
|
|
|
import 'dotenv/config';
|
|
|
|
const API_URL = 'http://localhost:4000/api';
|
|
const TOKEN = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOiI1YTIzOThkZi00NWNiLTQyOGQtOWY1ZS04YzQwNzQxNzEyNGIiLCJpYXQiOjE3NjMwODIwOTQsImV4cCI6MTc2MzY4Njg5NH0.zeu2ir4TjB6neonfAKv82Hms6IEFRkaGySEjWyGlL8E';
|
|
|
|
async function testEligibleParticipants() {
|
|
console.log('🧪 Test de l\'endpoint /api/draw/eligible-participants\n');
|
|
|
|
try {
|
|
console.log('📡 Requête vers:', `${API_URL}/draw/eligible-participants?minTickets=1&verified=true`);
|
|
console.log('🔑 Token:', TOKEN.substring(0, 50) + '...\n');
|
|
|
|
const response = await fetch(
|
|
`${API_URL}/draw/eligible-participants?minTickets=1&verified=true`,
|
|
{
|
|
method: 'GET',
|
|
headers: {
|
|
'Authorization': `Bearer ${TOKEN}`,
|
|
'Content-Type': 'application/json',
|
|
},
|
|
}
|
|
);
|
|
|
|
console.log('📊 Status:', response.status, response.statusText);
|
|
console.log('📋 Headers:', JSON.stringify(Object.fromEntries(response.headers.entries()), null, 2));
|
|
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
console.log('\n✅ SUCCÈS!\n');
|
|
console.log('Données reçues:');
|
|
console.log(JSON.stringify(data, null, 2));
|
|
|
|
if (data.data && data.data.participants) {
|
|
console.log(`\n🎯 ${data.data.total} participants éligibles trouvés:\n`);
|
|
data.data.participants.forEach((p, i) => {
|
|
console.log(`${i + 1}. ${p.first_name} ${p.last_name} (${p.email})`);
|
|
console.log(` Tickets: ${p.tickets_played} | Lots: ${p.prizes_won} | Vérifié: ${p.is_verified ? '✅' : '❌'}\n`);
|
|
});
|
|
}
|
|
} else {
|
|
console.log('\n❌ ERREUR!\n');
|
|
console.log('Réponse:', JSON.stringify(data, null, 2));
|
|
|
|
// Diagnostics
|
|
if (response.status === 401) {
|
|
console.log('\n🔍 Diagnostic: Token JWT invalide ou expiré');
|
|
console.log('Solution: Générer un nouveau token avec: node scripts/generate-admin-token.js');
|
|
} else if (response.status === 403) {
|
|
console.log('\n🔍 Diagnostic: Accès refusé');
|
|
console.log('Solution: Vérifier que l\'utilisateur a le rôle ADMIN');
|
|
} else if (response.status === 404) {
|
|
console.log('\n🔍 Diagnostic: Route non trouvée');
|
|
console.log('Solution: Vérifier que les routes sont bien enregistrées dans index.js');
|
|
} else if (response.status === 500) {
|
|
console.log('\n🔍 Diagnostic: Erreur serveur');
|
|
console.log('Solution: Vérifier les logs du serveur backend');
|
|
}
|
|
}
|
|
|
|
} catch (error) {
|
|
console.log('\n💥 ERREUR RÉSEAU!\n');
|
|
console.log('Message:', error.message);
|
|
|
|
if (error.code === 'ECONNREFUSED') {
|
|
console.log('\n🔍 Diagnostic: Le serveur backend n\'est pas démarré');
|
|
console.log('Solution: Démarrer le serveur avec: npm run dev');
|
|
} else if (error.name === 'TypeError' && error.message.includes('fetch')) {
|
|
console.log('\n🔍 Diagnostic: fetch() n\'est pas disponible (Node.js < 18)');
|
|
console.log('Solution: Utiliser Node.js 18+ ou installer node-fetch');
|
|
}
|
|
}
|
|
}
|
|
|
|
// Vérifier d'abord que le serveur est actif
|
|
async function checkServer() {
|
|
console.log('🔍 Vérification que le serveur backend est actif...\n');
|
|
|
|
try {
|
|
const response = await fetch('http://localhost:4000');
|
|
const data = await response.json();
|
|
|
|
if (response.ok) {
|
|
console.log('✅ Serveur actif:', data.message, '\n');
|
|
return true;
|
|
}
|
|
} catch {
|
|
console.log('❌ Serveur non accessible');
|
|
console.log('💡 Démarrez le serveur avec: npm run dev\n');
|
|
return false;
|
|
}
|
|
}
|
|
|
|
async function main() {
|
|
const serverActive = await checkServer();
|
|
|
|
if (serverActive) {
|
|
await testEligibleParticipants();
|
|
} else {
|
|
console.log('⚠️ Impossible de tester l\'endpoint sans serveur actif');
|
|
}
|
|
}
|
|
|
|
main();
|