This commit is contained in:
Gilles Soulier
2026-01-05 16:08:01 +01:00
parent dcba044cd6
commit c67befc549
2215 changed files with 26743 additions and 329 deletions

105
test_import_md.sh Executable file
View File

@@ -0,0 +1,105 @@
#!/bin/bash
# Script de test pour l'import de fichiers .md
# Teste la détection de doublons
set -e
API_URL="http://localhost:8007/api/peripherals/import/markdown"
TEST_FILE="fichier_usb/ID_0b05_17cb.md"
echo "=========================================="
echo "Test d'import de fichiers .md"
echo "=========================================="
echo ""
# Vérifier que le fichier de test existe
if [ ! -f "$TEST_FILE" ]; then
echo "❌ Fichier de test non trouvé: $TEST_FILE"
exit 1
fi
echo "✅ Fichier de test trouvé: $TEST_FILE"
echo ""
# Test 1 : Premier import (devrait créer le périphérique)
echo "📋 Test 1 : Premier import du fichier"
echo "--------------------------------------"
response1=$(curl -s -X POST "$API_URL" -F "file=@$TEST_FILE")
echo "Réponse API:"
echo "$response1" | jq '.'
already_exists=$(echo "$response1" | jq -r '.already_exists')
if [ "$already_exists" = "false" ]; then
echo "✅ Test 1 RÉUSSI : Nouveau périphérique détecté (already_exists=false)"
echo ""
# Créer le périphérique dans la base
echo "📝 Création du périphérique dans la base de données..."
suggested=$(echo "$response1" | jq '.suggested_peripheral')
create_response=$(curl -s -X POST "http://localhost:8007/api/peripherals" \
-H "Content-Type: application/json" \
-d "$suggested")
peripheral_id=$(echo "$create_response" | jq -r '.id')
echo "✅ Périphérique créé avec ID: $peripheral_id"
echo ""
# Test 2 : Réimporter le même fichier (devrait détecter le doublon)
echo "📋 Test 2 : Réimport du même fichier (détection doublon)"
echo "--------------------------------------"
response2=$(curl -s -X POST "$API_URL" -F "file=@$TEST_FILE")
echo "Réponse API:"
echo "$response2" | jq '.'
already_exists2=$(echo "$response2" | jq -r '.already_exists')
if [ "$already_exists2" = "true" ]; then
echo "✅ Test 2 RÉUSSI : Doublon détecté (already_exists=true)"
echo ""
existing_id=$(echo "$response2" | jq -r '.existing_peripheral_id')
existing_nom=$(echo "$response2" | jq -r '.existing_peripheral.nom')
echo "Périphérique existant détecté:"
echo " ID: $existing_id"
echo " Nom: $existing_nom"
echo ""
# Nettoyer : supprimer le périphérique de test
echo "🧹 Nettoyage : Suppression du périphérique de test..."
curl -s -X DELETE "http://localhost:8007/api/peripherals/$peripheral_id" > /dev/null
echo "✅ Périphérique supprimé"
echo ""
echo "=========================================="
echo "✅ TOUS LES TESTS RÉUSSIS !"
echo "=========================================="
echo ""
echo "Résumé:"
echo " ✅ Import nouveau périphérique : OK"
echo " ✅ Détection de doublon : OK"
echo " ✅ Nettoyage : OK"
echo ""
else
echo "❌ Test 2 ÉCHOUÉ : Doublon NON détecté"
exit 1
fi
elif [ "$already_exists" = "true" ]; then
echo " Le périphérique existe déjà dans la base"
echo " (probablement un test précédent non nettoyé)"
echo ""
existing_id=$(echo "$response1" | jq -r '.existing_peripheral_id')
echo "🧹 Nettoyage : Suppression du périphérique..."
curl -s -X DELETE "http://localhost:8007/api/peripherals/$existing_id" > /dev/null
echo "✅ Périphérique supprimé"
echo ""
echo "Relancez le script pour un test complet"
else
echo "❌ Test 1 ÉCHOUÉ : Réponse inattendue"
exit 1
fi