#!/bin/bash # Script de test de l'API admin/tickets # Remplacez VOTRE_TOKEN par votre token d'authentification # Couleurs pour l'affichage GREEN='\033[0;32m' RED='\033[0;31m' BLUE='\033[0;34m' NC='\033[0m' # No Color echo -e "${BLUE}đŸ§Ș Test de l'API /admin/tickets${NC}" echo "==========================================" echo "" # Remplacez cette valeur par votre token TOKEN="VOTRE_TOKEN" if [ "$TOKEN" = "VOTRE_TOKEN" ]; then echo -e "${RED}❌ Erreur: Vous devez remplacer VOTRE_TOKEN par votre vrai token !${NC}" echo "" echo "Pour rĂ©cupĂ©rer votre token :" echo "1. Ouvrez http://localhost:3000/admin/dashboard" echo "2. Appuyez sur F12" echo "3. Dans la console, tapez : localStorage.getItem('auth_token')" echo "4. Copiez le token et remplacez VOTRE_TOKEN dans ce script" exit 1 fi echo -e "${BLUE}📡 Envoi de la requĂȘte...${NC}" echo "" # Faire la requĂȘte RESPONSE=$(curl -s -w "\n%{http_code}" -X GET "http://localhost:4000/api/admin/tickets?page=1&limit=20" \ -H "Content-Type: application/json" \ -H "Authorization: Bearer $TOKEN") # SĂ©parer le body et le status code HTTP_BODY=$(echo "$RESPONSE" | head -n -1) HTTP_CODE=$(echo "$RESPONSE" | tail -n 1) echo -e "${BLUE}đŸ“„ Status HTTP: ${NC}$HTTP_CODE" echo "" if [ "$HTTP_CODE" = "200" ]; then echo -e "${GREEN}✅ SuccĂšs !${NC}" else echo -e "${RED}❌ Erreur HTTP $HTTP_CODE${NC}" fi echo "" echo -e "${BLUE}📩 RĂ©ponse JSON:${NC}" echo "==========================================" echo "$HTTP_BODY" | python -m json.tool 2>/dev/null || echo "$HTTP_BODY" echo "==========================================" echo "" # Analyser la rĂ©ponse if echo "$HTTP_BODY" | grep -q '"success":false'; then echo -e "${RED}⚠ L'API a retournĂ© success: false${NC}" ERROR_MSG=$(echo "$HTTP_BODY" | grep -o '"error":"[^"]*"' | cut -d'"' -f4) echo -e "${RED}Erreur: $ERROR_MSG${NC}" elif echo "$HTTP_BODY" | grep -q '"data":\[\]'; then echo -e "${RED}⚠ L'API a retournĂ© un tableau vide (0 tickets)${NC}" echo "Mais il y a 24 tickets dans la base de donnĂ©es !" echo "" echo "ProblĂšmes possibles :" echo " 1. INNER JOIN qui exclut les tickets" echo " 2. Filtre par userId qui ne retourne que les tickets de l'admin" echo " 3. ProblĂšme de pagination" else TICKET_COUNT=$(echo "$HTTP_BODY" | grep -o '"data":\[[^]]*\]' | grep -o '{' | wc -l) echo -e "${GREEN}✅ Tickets trouvĂ©s: $TICKET_COUNT${NC}" fi echo "" echo "Test terminĂ©."