← back to Handbag Auth Nextjs

auction-viewer/test-analytics.sh

134 lines

#!/bin/bash

# LUXVAULT Analytics Endpoint Testing Script
# Tests all 10 analytics endpoints and reports results

BASE_URL="http://45.61.58.125:7500/api/insights"
PASSED=0
FAILED=0

echo "=========================================="
echo "LUXVAULT Analytics Endpoint Testing"
echo "=========================================="
echo ""

# Color codes
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color

# Test function
test_endpoint() {
    local name=$1
    local url=$2
    local expected_field=$3

    echo -n "Testing $name... "

    response=$(curl -s "$url")
    success=$(echo "$response" | jq -r '.success' 2>/dev/null)

    if [ "$success" == "true" ]; then
        if [ -n "$expected_field" ]; then
            field_exists=$(echo "$response" | jq -r ".$expected_field" 2>/dev/null)
            if [ "$field_exists" != "null" ] && [ -n "$field_exists" ]; then
                echo -e "${GREEN}PASS${NC}"
                ((PASSED++))
            else
                echo -e "${RED}FAIL${NC} (missing field: $expected_field)"
                ((FAILED++))
            fi
        else
            echo -e "${GREEN}PASS${NC}"
            ((PASSED++))
        fi
    else
        echo -e "${RED}FAIL${NC}"
        echo "Response: $response" | head -c 200
        echo ""
        ((FAILED++))
    fi
}

echo "Core Analytics Endpoints:"
echo "-------------------------"

# 1. Deal Scores
test_endpoint "Deal Scores" \
    "$BASE_URL/deal-scores?limit=5" \
    "data"

# 2. Trends
test_endpoint "Price Trends" \
    "$BASE_URL/trends" \
    "data"

# 3. Anomalies
test_endpoint "Anomalies" \
    "$BASE_URL/anomalies" \
    "data"

# 4. Market Insights
test_endpoint "Market Insights" \
    "$BASE_URL/market" \
    "data.market_summary"

# 5. Recommendations
test_endpoint "Recommendations" \
    "$BASE_URL/recommendations?budget=5000" \
    "data"

# 6. Compare Brands
test_endpoint "Brand Comparison" \
    "$BASE_URL/compare-brands" \
    "data"

# 7. Velocity
test_endpoint "Auction Velocity" \
    "$BASE_URL/velocity" \
    "data"

# 8. Time Series
test_endpoint "Time Series" \
    "$BASE_URL/time-series?interval=month" \
    "data"

echo ""
echo "Parameterized Endpoints:"
echo "------------------------"

# Get a sample auction ID for prediction test
SAMPLE_AUCTION=$(curl -s "http://45.61.58.125:7500/api/auctions?limit=1" | jq -r '.data[0].auction_id' 2>/dev/null)

if [ -n "$SAMPLE_AUCTION" ] && [ "$SAMPLE_AUCTION" != "null" ]; then
    # 9. Price Prediction
    test_endpoint "Price Prediction" \
        "$BASE_URL/predict/$SAMPLE_AUCTION" \
        "data.predicted_final_price"
else
    echo -e "Price Prediction... ${YELLOW}SKIP${NC} (no auction data)"
fi

# 10. Brand Analytics
test_endpoint "Brand Analytics" \
    "$BASE_URL/brand/Hermes%20Birkin" \
    "statistics"

echo ""
echo "=========================================="
echo "Test Results Summary"
echo "=========================================="
echo -e "Passed: ${GREEN}$PASSED${NC}"
echo -e "Failed: ${RED}$FAILED${NC}"
echo "Total:  $((PASSED + FAILED))"
echo ""

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