#!/bin/bash # Couleurs pour l'affichage GREEN='\033[0;32m' RED='\033[0;31m' BLUE='\033[0;34m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Token JWT TOKEN="eyJhbGciOiJIUzM4NCJ9.eyJzdWIiOiJ0ZXN0YWRtaW4iLCJpYXQiOjE3NTk0MTgwNjcsImV4cCI6MTc1OTUwNDQ2N30.O3NdNW6W1dcXW4-cqFKi08Wrd_w7_H7DkJf260XvFsEjRUbsO7pXcKXV8aElkEur" echo -e "${BLUE}========================================${NC}" echo -e "${BLUE} TEST COMPLET DES ENDPOINTS API${NC}" echo -e "${BLUE}========================================${NC}" echo "" # Fonction pour tester un endpoint test_endpoint() { local method=$1 local endpoint=$2 local auth=$3 local data=$4 local name=$5 echo -e "${YELLOW}Testing: ${name}${NC}" echo -e " ${BLUE}${method} ${endpoint}${NC}" if [ "$auth" == "true" ]; then if [ -n "$data" ]; then response=$(curl -s -w "\n%{http_code}" -X ${method} \ -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" \ -d "${data}" \ "http://localhost:8080${endpoint}") else response=$(curl -s -w "\n%{http_code}" -X ${method} \ -H "Authorization: Bearer ${TOKEN}" \ "http://localhost:8080${endpoint}") fi else if [ -n "$data" ]; then response=$(curl -s -w "\n%{http_code}" -X ${method} \ -H "Content-Type: application/json" \ -d "${data}" \ "http://localhost:8080${endpoint}") else response=$(curl -s -w "\n%{http_code}" -X ${method} \ "http://localhost:8080${endpoint}") fi fi # Extraire le code HTTP (dernière ligne) http_code=$(echo "$response" | tail -n 1) body=$(echo "$response" | sed '$d') # Vérifier le code de statut if [[ $http_code -ge 200 && $http_code -lt 300 ]]; then echo -e " ${GREEN}✓ Status: ${http_code}${NC}" if [ -n "$body" ] && [ "$body" != "{}" ] && [ "$body" != "[]" ]; then echo -e " ${GREEN}✓ Response: ${body:0:100}...${NC}" else echo -e " ${GREEN}✓ Response: Empty or minimal${NC}" fi else echo -e " ${RED}✗ Status: ${http_code}${NC}" echo -e " ${RED}✗ Response: ${body:0:200}${NC}" fi echo "" } # ===== ENDPOINTS PUBLICS ===== echo -e "${BLUE}===== ENDPOINTS PUBLICS =====${NC}" echo "" test_endpoint "GET" "/actuator/health" "false" "" "Health Check" # ===== AUTHENTICATION ===== echo -e "${BLUE}===== AUTHENTICATION =====${NC}" echo "" test_endpoint "POST" "/api/v1/auth/login" "false" '{"username":"testadmin","password":"Password123"}' "Login" # ===== USER MANAGEMENT ===== echo -e "${BLUE}===== USER MANAGEMENT =====${NC}" echo "" test_endpoint "GET" "/api/v1/users" "true" "" "Get All Users" test_endpoint "GET" "/api/v1/users/profile" "true" "" "Get User Profile" # ===== COMPANY MANAGEMENT ===== echo -e "${BLUE}===== COMPANY MANAGEMENT =====${NC}" echo "" test_endpoint "GET" "/api/v1/companies" "true" "" "Get All Companies" # ===== DOCUMENT MANAGEMENT ===== echo -e "${BLUE}===== DOCUMENT MANAGEMENT =====${NC}" echo "" test_endpoint "GET" "/api/v1/documents" "true" "" "Get All Documents" # ===== EXPORT FOLDER MANAGEMENT ===== echo -e "${BLUE}===== EXPORT FOLDER MANAGEMENT =====${NC}" echo "" test_endpoint "GET" "/api/v1/export-folders" "true" "" "Get All Export Folders" # ===== QUOTE MANAGEMENT ===== echo -e "${BLUE}===== QUOTE MANAGEMENT =====${NC}" echo "" test_endpoint "GET" "/api/v1/quotes" "true" "" "Get All Quotes" # ===== SUBSCRIPTION MANAGEMENT (NEWLY ACTIVATED) ===== echo -e "${BLUE}===== SUBSCRIPTION MANAGEMENT (NEWLY ACTIVATED) =====${NC}" echo "" test_endpoint "GET" "/api/v1/subscriptions" "true" "" "Get All Subscriptions" # ===== PLAN MANAGEMENT (NEWLY ACTIVATED) ===== echo -e "${BLUE}===== PLAN MANAGEMENT (NEWLY ACTIVATED) =====${NC}" echo "" test_endpoint "GET" "/api/v1/plans" "true" "" "Get All Plans" # ===== VESSEL SCHEDULE ===== echo -e "${BLUE}===== VESSEL SCHEDULE =====${NC}" echo "" test_endpoint "GET" "/api/v1/vessel-schedules" "true" "" "Get All Vessel Schedules" # ===== SHIPMENT TRACKING ===== echo -e "${BLUE}===== SHIPMENT TRACKING =====${NC}" echo "" test_endpoint "GET" "/api/v1/shipments" "true" "" "Get All Shipments" # ===== NOTIFICATIONS ===== echo -e "${BLUE}===== NOTIFICATIONS =====${NC}" echo "" test_endpoint "GET" "/api/v1/notifications" "true" "" "Get All Notifications" # ===== RÉSUMÉ ===== echo -e "${BLUE}========================================${NC}" echo -e "${GREEN} Tests terminés!${NC}" echo -e "${BLUE}========================================${NC}"