← back to Handbag Auth Nextjs

auction-viewer/test-backend-v2.sh

137 lines

#!/bin/bash

# Backend v2.0 Test Suite
# Validates all new features and optimizations

BASE_URL="http://45.61.58.125:7500"
PASS=0
FAIL=0

# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
BLUE='\033[0;34m'
NC='\033[0m'

echo "═══════════════════════════════════════════════════════"
echo "  LUXVAULT Backend v2.0 - Comprehensive Test Suite"
echo "═══════════════════════════════════════════════════════"
echo ""

test_endpoint() {
    local name="$1"
    local url="$2"
    local expected="$3"
    
    echo -n "Testing: $name... "
    
    response=$(curl -s "$url")
    
    if echo "$response" | grep -q "$expected"; then
        echo -e "${GREEN}✓ PASS${NC}"
        ((PASS++))
    else
        echo -e "${RED}✗ FAIL${NC}"
        echo "  Expected: $expected"
        echo "  Got: $response" | head -c 200
        ((FAIL++))
    fi
}

test_response_time() {
    local name="$1"
    local url="$2"
    local max_time="$3"
    
    echo -n "Testing: $name response time... "
    
    start=$(date +%s%N)
    curl -s "$url" > /dev/null
    end=$(date +%s%N)
    
    duration=$(( (end - start) / 1000000 ))
    
    if [ $duration -lt $max_time ]; then
        echo -e "${GREEN}✓ PASS${NC} (${duration}ms)"
        ((PASS++))
    else
        echo -e "${RED}✗ FAIL${NC} (${duration}ms > ${max_time}ms)"
        ((FAIL++))
    fi
}

# Core endpoint tests
echo -e "${BLUE}📊 Testing Core Endpoints${NC}"
test_endpoint "Health check" "$BASE_URL/health" '"status":"healthy"'
test_endpoint "System status" "$BASE_URL/api/status" '"success":true'
test_endpoint "Legacy auctions endpoint" "$BASE_URL/api/auctions?limit=5" '"success":true'

# API v1 tests
echo ""
echo -e "${BLUE}🚀 Testing API v1 Features${NC}"
test_endpoint "v1 auctions endpoint" "$BASE_URL/api/v1/auctions?limit=5" '"success":true'
test_endpoint "Pagination metadata" "$BASE_URL/api/v1/auctions?limit=5&page=2" '"totalPages"'
test_endpoint "Brand filtering" "$BASE_URL/api/v1/auctions?brand=Hermes%20Birkin&limit=5" '"search_term":"Hermes Birkin"'
test_endpoint "Price range filtering" "$BASE_URL/api/v1/auctions?min_price=5000&max_price=10000&limit=5" '"success":true'
test_endpoint "Sort by price" "$BASE_URL/api/v1/auctions?sort=price&order=asc&limit=5" '"success":true'
test_endpoint "Full-text search" "$BASE_URL/api/v1/search?q=birkin" '"query":"birkin"'

# Analytics endpoints
echo ""
echo -e "${BLUE}🧠 Testing Analytics Endpoints${NC}"
test_endpoint "Statistics" "$BASE_URL/api/stats" '"success":true'
test_endpoint "Best values" "$BASE_URL/api/best-values?limit=10" '"success":true'
test_endpoint "Brand analytics" "$BASE_URL/api/insights/brand/Hermes%20Birkin" '"brand":"Hermes Birkin"'
test_endpoint "Time series" "$BASE_URL/api/insights/time-series?interval=month" '"success":true'
test_endpoint "Compare brands" "$BASE_URL/api/insights/compare-brands" '"success":true'

# Performance tests
echo ""
echo -e "${BLUE}⚡ Testing Performance${NC}"
test_response_time "Basic query" "$BASE_URL/api/v1/auctions?limit=50" 200
test_response_time "Filtered query" "$BASE_URL/api/v1/auctions?brand=Hermes%20Birkin&limit=50" 150
test_response_time "Search query" "$BASE_URL/api/v1/search?q=birkin" 100
test_response_time "Statistics" "$BASE_URL/api/stats" 200

# Cache test
echo ""
echo -e "${BLUE}💾 Testing Cache${NC}"
echo -n "First request (cold cache)... "
start=$(date +%s%N)
curl -s "$BASE_URL/api/stats" > /dev/null
end=$(date +%s%N)
cold_time=$(( (end - start) / 1000000 ))
echo "${cold_time}ms"

echo -n "Second request (warm cache)... "
start=$(date +%s%N)
curl -s "$BASE_URL/api/stats" > /dev/null
end=$(date +%s%N)
warm_time=$(( (end - start) / 1000000 ))
echo "${warm_time}ms"

if [ $warm_time -lt $cold_time ]; then
    echo -e "${GREEN}✓ Cache is working${NC} (${warm_time}ms < ${cold_time}ms)"
    ((PASS++))
else
    echo -e "${RED}✗ Cache might not be working${NC}"
    ((FAIL++))
fi

# Summary
echo ""
echo "═══════════════════════════════════════════════════════"
echo "  Test Results"
echo "═══════════════════════════════════════════════════════"
echo -e "Passed: ${GREEN}$PASS${NC}"
echo -e "Failed: ${RED}$FAIL${NC}"
echo ""

if [ $FAIL -eq 0 ]; then
    echo -e "${GREEN}✓ All tests passed!${NC}"
    exit 0
else
    echo -e "${RED}✗ Some tests failed${NC}"
    exit 1
fi