#!/bin/bash
# Test script for Web Chat API
echo "๐งช Testing Web Chat API Endpoints"
echo "=================================="
echo ""
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Base URL
BASE_URL="http://localhost:8002"
# Test 1: Health Check
echo "1๏ธโฃ Testing Health Check..."
response=$(curl -s -w "\n%{http_code}" "$BASE_URL/health")
http_code=$(echo "$response" | tail -n 1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" -eq 200 ]; then
echo -e "${GREEN}โ Health check passed${NC}"
echo " Response: $body"
else
echo -e "${RED}โ Health check failed (HTTP $http_code)${NC}"
echo " Response: $body"
fi
echo ""
# Test 2: Readiness Check
echo "2๏ธโฃ Testing Readiness Check..."
response=$(curl -s -w "\n%{http_code}" "$BASE_URL/ready")
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" -eq 200 ]; then
echo -e "${GREEN}โ Readiness check passed${NC}"
echo " Response: $body"
else
echo -e "${YELLOW}โ Readiness check failed (HTTP $http_code)${NC}"
echo " Response: $body"
echo " Note: This is expected if MCP server is not running"
fi
echo ""
# Test 3: Chat Endpoint - Dealership Viewer
echo "3๏ธโฃ Testing Chat Endpoint (Dealership Viewer - Role 13)..."
response=$(curl -s -w "\n%{http_code}" -X POST "$BASE_URL/chat" \
-H "Content-Type: application/json" \
-d '{
"user_id": 1,
"organization_id": 1,
"dealership_id": 10,
"role": 13,
"message": "What can I do?"
}')
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" -eq 200 ]; then
echo -e "${GREEN}โ Chat request successful${NC}"
echo " Response: $body" | head -c 200
echo "..."
else
echo -e "${RED}โ Chat request failed (HTTP $http_code)${NC}"
echo " Response: $body"
fi
echo ""
# Test 4: Chat Endpoint - Platform Admin
echo "4๏ธโฃ Testing Chat Endpoint (Platform Admin - Role 4)..."
response=$(curl -s -w "\n%{http_code}" -X POST "$BASE_URL/chat" \
-H "Content-Type: application/json" \
-d '{
"user_id": 2,
"organization_id": 1,
"platform_id": 5,
"role": 4,
"message": "Show me platform analytics"
}')
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" -eq 200 ]; then
echo -e "${GREEN}โ Chat request successful${NC}"
echo " Response: $body" | head -c 200
echo "..."
else
echo -e "${RED}โ Chat request failed (HTTP $http_code)${NC}"
echo " Response: $body"
fi
echo ""
# Test 5: Chat Endpoint - Org Admin
echo "5๏ธโฃ Testing Chat Endpoint (Org Admin - Role 2)..."
response=$(curl -s -w "\n%{http_code}" -X POST "$BASE_URL/chat" \
-H "Content-Type: application/json" \
-d '{
"user_id": 3,
"organization_id": 1,
"role": 2,
"message": "Show me organization overview"
}')
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" -eq 200 ]; then
echo -e "${GREEN}โ Chat request successful${NC}"
echo " Response: $body" | head -c 200
echo "..."
else
echo -e "${RED}โ Chat request failed (HTTP $http_code)${NC}"
echo " Response: $body"
fi
echo ""
# Test 6: Chat Endpoint - Global Admin
echo "6๏ธโฃ Testing Chat Endpoint (Global Admin - Role 1)..."
response=$(curl -s -w "\n%{http_code}" -X POST "$BASE_URL/chat" \
-H "Content-Type: application/json" \
-d '{
"user_id": 4,
"organization_id": 1,
"role": 1,
"message": "Show me system status"
}')
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | sed '$d')
if [ "$http_code" -eq 200 ]; then
echo -e "${GREEN}โ Chat request successful${NC}"
echo " Response: $body" | head -c 200
echo "..."
else
echo -e "${RED}โ Chat request failed (HTTP $http_code)${NC}"
echo " Response: $body"
fi
echo ""
echo "=================================="
echo "โ
API tests completed!"
echo ""
echo "๐ก Tips:"
echo " - Make sure both servers are running:"
echo " Terminal 1: python3 -m src.mcp_server.server"
echo " Terminal 2: python3 -m src.web_chat.main"
echo " - Check the server logs for detailed information"
echo " - See LOGGING_GUIDE.md for how to debug issues"