#!/bin/bash # ============================================ # SCRIPT DE SIMULATION RÉALISTE - E-COMMERCE # Version avec validation GPS + Simulation déplacement livreur # ============================================ BASE_URL="https://c80319bf2e28244c-90-50-148-138.serveousercontent.com" ADMIN_TOKEN="" CABINE_TOKEN="" LIVREUR_TOKEN="" NUM_PRODUCTS=13 # Couleurs pour l'affichage RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' MAGENTA='\033[0;35m' CYAN='\033[0;36m' NC='\033[0m' # No Color declare -A PRODUCT_DETAILS declare -a PRODUCT_IDS # Compteurs de tests TOTAL_TESTS=0 PASSED_TESTS=0 FAILED_TESTS=0 # Fonctions d'affichage print_section() { echo "" echo -e "${BLUE}================================================${NC}" echo -e "${BLUE}$1${NC}" echo -e "${BLUE}================================================${NC}" } print_test() { echo "" echo -e "${YELLOW}▶ $1${NC}" ((TOTAL_TESTS++)) } print_success() { echo -e "${GREEN}✓ $1${NC}" ((PASSED_TESTS++)) } print_error() { echo -e "${RED}✗ $1${NC}" ((FAILED_TESTS++)) } print_info() { echo -e "${MAGENTA}ℹ $1${NC}" } print_warning() { echo -e "${YELLOW}⚠ $1${NC}" } # Fonction pour extraire le token extract_token() { local response="$1" local token=$(echo "$response" | jq -r '.token // .access_token // empty' 2>/dev/null) echo "$token" } # Fonction pour extraire un ID extract_id() { local response="$1" local field="${2:-id}" local id=$(echo "$response" | jq -r ".${field} // .product.id // .product_id // empty" 2>/dev/null) echo "$id" } # Fonction pour vérifier les erreurs check_error() { local response="$1" if echo "$response" | jq -e '.error' >/dev/null 2>&1; then return 0 else return 1 fi } # Fonction pour vérifier le succès check_success() { local response="$1" if echo "$response" | jq -e '.id // .token // .success // .command_id' >/dev/null 2>&1; then return 0 else return 1 fi } # ============================================ # 0. VÉRIFICATION PRÉALABLE # ============================================ print_section "0. VÉRIFICATION PRÉALABLE" print_test "Vérification du serveur" HEALTH_CHECK=$(curl -s -X GET "$BASE_URL/api/v1/health") if [ -n "$HEALTH_CHECK" ]; then print_success "Serveur accessible" else print_error "Serveur non accessible" exit 1 fi # ============================================ # 1. AUTHENTIFICATION ADMIN # ============================================ print_section "0. AUTHENTIFICATION CLIENT" CLIENT_TOKEN=$(extract_token "$CLIENT_LOGIN") print_test "Création client" CLIENT_REGISTER=$(curl -s -X POST "$BASE_URL/api/v1/auth/register" \ -H "Content-Type: application/json" \ -d "{\"username\":\"salut\",\"password\":\"salut1234_\",\"role\":\"client\",\"nom\": \"Dupont\",\"prenom\": \"Jean\",\"telephone\": \"+33612345678\"}") CLIENT_TOKEN=$(extract_token "$CLIENT_REGISTER") if [ -n "$CLIENT_TOKEN" ]; then print_success "Client créé et authentifié" else print_error "Échec authentification client" exit 1 fi # ============================================ # 1. AUTHENTIFICATION ADMIN # ============================================ print_section "1. AUTHENTIFICATION ADMIN" ADMIN_TOKEN=$(extract_token "$ADMIN_LOGIN") print_test "Création admin" UNIQUE_ADMIN="admin_$(date +%s)" ADMIN_REGISTER=$(curl -s -X POST "$BASE_URL/api/v2/admin/auth/register" \ -H "Content-Type: application/json" \ -d "{\"username\":\"$UNIQUE_ADMIN\",\"password\":\"AdminPass123!\",\"role\":\"admin\"}") ADMIN_TOKEN=$(extract_token "$ADMIN_REGISTER") if [ -n "$ADMIN_TOKEN" ]; then print_success "Admin créé et authentifié" else print_error "Échec authentification admin" exit 1 fi print_test "Création livreur" UNIQUE_LIVREUR="livreur_$(date +%s)" ADMIN_REGISTER=$(curl -s -X POST "$BASE_URL/api/v2/admin/auth/register" \ -H "Content-Type: application/json" \ -d "{\"username\":\"$UNIQUE_LIVREUR\",\"password\":\"AdminPass123!\",\"role\":\"livreur\"}") LIVREUR_TOKEN=$(extract_token "$ADMIN_REGISTER") if [ -n "$LIVREUR_TOKEN" ]; then print_success "Admin créé et authentifié" else print_error "Échec authentification admin" exit 1 fi print_test "Création cabine" UNIQUE_CABINE="cabine_$(date +%s)" ADMIN_REGISTER=$(curl -s -X POST "$BASE_URL/api/v2/admin/auth/register" \ -H "Content-Type: application/json" \ -d "{\"username\":\"$UNIQUE_CABINE\",\"password\":\"AdminPass123!\",\"role\":\"cabine\"}") CABINE_TOKEN=$(extract_token "$ADMIN_REGISTER") if [ -n "$CABINE_TOKEN" ]; then print_success "Admin créé et authentifié" else print_error "Échec authentification admin" exit 1 fi # ============================================ # 2. CRÉATION MASSIVE DE PRODUITS # ============================================ print_section "2. CRÉATION MASSIVE DE PRODUITS" print_info "Création de $NUM_PRODUCTS produits..." PREDEFINED_PRODUCTS=( '{"name":"Zipette Borealis 1", "category":"zipette&co", "description":"Plante luminescente aux teintes bleutées inspirée des aurores boréales", "price":24.99, "stock":35.00}' '{"name":"Zipette Titan 1", "category":"zipette&co", "description":"Plante géante fictive atteignant jusqu'\''à 2 mètres en intérieur", "price":19.99, "stock":50.00}' '{"name":"Zipette Borealis 2", "category":"zipette&co", "description":"Plante luminescente aux teintes bleutées inspirée des aurores boréales", "price":24.99, "stock":35.00}' '{"name":"Zipette Titan 2", "category":"zipette&co", "description":"Plante géante fictive atteignant jusqu'\''à 2 mètres en intérieur", "price":19.99, "stock":50.00}' '{"name":"Zipette Borealis 3", "category":"zipette&co", "description":"Plante luminescente aux teintes bleutées inspirée des aurores boréales", "price":24.99, "stock":35.00}' '{"name":"Zipette Titan 3", "category":"zipette&co", "description":"Plante géante fictive atteignant jusqu'\''à 2 mètres en intérieur", "price":19.99, "stock":50.00}' '{"name":"Titan 4", "category":"gros&semi", "description":"Plante géante fictive atteignant jusqu'\''à 2 mètres en intérieur", "price":19.99, "stock":50.00}' '{"name":"Borealis 4", "category":"gros&semi", "description":"Plante luminescente aux teintes bleutées inspirée des aurores boréales", "price":24.99, "stock":35.00}' '{"name":"Titan 5", "category":"gros&semi", "description":"Plante géante fictive atteignant jusqu'\''à 2 mètres en intérieur", "price":19.99, "stock":50.00}' '{"name":"Kush 1", "category":"weed&hash", "description":"Variété fictive aux arômes terreux et notes citronnées, culture indoor facile", "price":14.99, "stock":80.00}' '{"name":"Haze 1", "category":"weed&hash", "description":"Plante fictive à dominance sativa, réputée pour son parfum épicé", "price":16.99, "stock":60.00}' '{"name":"Hash Gold 1", "category":"weed&hash", "description":"Résine fictive premium à la texture souple et aux notes florales", "price":9.99, "stock":120.00}' '{"name":"Hash Black 1", "category":"weed&hash", "description":"Résine fictive sombre, goût intense et épicé", "price":11.99, "stock":90.00}' '{"name":"Kush 2", "category":"weed&hash", "description":"Variété fictive compacte, floraison rapide et parfum boisé", "price":14.99, "stock":75.00}' ) for ((i=0; i