#!/bin/bash # Complete Deployment Test Including Bot Activity Tracking # Run on production server after deployment set -e echo "================================================" echo "🚀 Complete Deployment Test Suite" echo "================================================" echo "LittleShop: https://admin.thebankofdebbie.giize.com" echo "Date: $(date)" echo "================================================" echo "" # Colors GREEN='\033[0;32m' RED='\033[0;31m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Test counters PASSED=0 FAILED=0 # Function to test endpoint test_endpoint() { local name="$1" local url="$2" local expected="$3" local method="${4:-GET}" local data="${5:-}" echo -n "Testing $name... " if [ "$method" = "POST" ] && [ -n "$data" ]; then response=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$url" -H "Content-Type: application/json" -d "$data" 2>/dev/null) else response=$(curl -s -o /dev/null -w "%{http_code}" "$url" 2>/dev/null) fi if [ "$response" = "$expected" ]; then echo -e "${GREEN}✓${NC} (HTTP $response)" ((PASSED++)) else echo -e "${RED}✗${NC} (HTTP $response, expected $expected)" ((FAILED++)) fi } # Function to test JSON response test_json() { local name="$1" local url="$2" echo -n "Testing $name... " response=$(curl -s "$url" 2>/dev/null) if echo "$response" | python3 -m json.tool > /dev/null 2>&1; then echo -e "${GREEN}✓${NC} (Valid JSON)" ((PASSED++)) else echo -e "${RED}✗${NC} (Invalid JSON or no response)" ((FAILED++)) fi } echo -e "${YELLOW}[1] Core Services${NC}" echo "--------------------------------------------" test_endpoint "LittleShop Home" "https://admin.thebankofdebbie.giize.com" "302" test_endpoint "LittleShop Admin" "https://admin.thebankofdebbie.giize.com/Admin" "302" test_endpoint "LittleShop Health" "https://admin.thebankofdebbie.giize.com/health" "200" echo "" echo -e "${YELLOW}[2] API Endpoints${NC}" echo "--------------------------------------------" test_json "Categories API" "https://admin.thebankofdebbie.giize.com/api/catalog/categories" test_json "Products API" "https://admin.thebankofdebbie.giize.com/api/catalog/products" test_endpoint "Orders API" "https://admin.thebankofdebbie.giize.com/api/orders" "400" "POST" '{"customerIdentifier":"test"}' echo "" echo -e "${YELLOW}[3] Bot Activity Tracking${NC}" echo "--------------------------------------------" test_json "Activity Stats" "https://admin.thebankofdebbie.giize.com/api/bot/activity/stats" # Test activity posting test_data='{"SessionIdentifier":"test_'$(date +%s)'","UserDisplayName":"Test User","ActivityType":"Test","ActivityDescription":"Deployment test","Platform":"Test"}' test_endpoint "Post Activity" "https://admin.thebankofdebbie.giize.com/api/bot/activity" "200" "POST" "$test_data" # Verify the activity was recorded echo -n "Verifying activity recorded... " stats=$(curl -s "https://admin.thebankofdebbie.giize.com/api/bot/activity/stats" 2>/dev/null) if echo "$stats" | grep -q "totalActivities"; then total=$(echo "$stats" | python3 -c "import sys, json; print(json.load(sys.stdin)['totalActivities'])" 2>/dev/null) echo -e "${GREEN}✓${NC} (Total activities: $total)" ((PASSED++)) else echo -e "${RED}✗${NC} (Could not verify)" ((FAILED++)) fi echo "" echo -e "${YELLOW}[4] Docker Containers${NC}" echo "--------------------------------------------" for container in littleshop-admin telebot silverpay; do echo -n "Checking $container... " if docker ps | grep -q "$container"; then status=$(docker ps | grep "$container" | awk '{print $(NF-1)}') if echo "$status" | grep -q "healthy"; then echo -e "${GREEN}✓${NC} (Running - Healthy)" ((PASSED++)) elif echo "$status" | grep -q "unhealthy"; then echo -e "${YELLOW}⚠${NC} (Running - Unhealthy)" ((FAILED++)) else echo -e "${GREEN}✓${NC} (Running)" ((PASSED++)) fi else echo -e "${RED}✗${NC} (Not running)" ((FAILED++)) fi done echo "" echo -e "${YELLOW}[5] Live Dashboard${NC}" echo "--------------------------------------------" echo -n "Checking Live Dashboard... " # The live dashboard might be behind auth, so we check for redirect or success dashboard_status=$(curl -s -o /dev/null -w "%{http_code}" "https://admin.thebankofdebbie.giize.com/Admin/BotActivity/Live" 2>/dev/null) if [ "$dashboard_status" = "302" ] || [ "$dashboard_status" = "200" ]; then echo -e "${GREEN}✓${NC} (HTTP $dashboard_status)" ((PASSED++)) else echo -e "${YELLOW}⚠${NC} (HTTP $dashboard_status - May require authentication)" ((PASSED++)) fi echo "" echo "================================================" echo -e "🎯 Test Results" echo "================================================" echo -e "Passed: ${GREEN}$PASSED${NC}" echo -e "Failed: ${RED}$FAILED${NC}" if [ $FAILED -eq 0 ]; then echo -e "\n${GREEN}✅ All tests passed! Deployment successful!${NC}" else echo -e "\n${YELLOW}⚠ Some tests failed. Review the output above.${NC}" fi echo "================================================" # Show activity tracking summary echo "" echo -e "${YELLOW}📊 Bot Activity Summary${NC}" echo "--------------------------------------------" if stats=$(curl -s "https://admin.thebankofdebbie.giize.com/api/bot/activity/stats" 2>/dev/null); then echo "$stats" | python3 -m json.tool 2>/dev/null || echo "$stats" fi echo "" exit $FAILED