littleshop/test-integration.sh
SysAdmin d6f8a5e697 Add comprehensive integration test suite with deployment verification
- Created multiple test scripts to verify all system integrations
- test-integration-fixed.sh: Main test suite with all fixes (RECOMMENDED)
- test-integration-simple.sh: Quick verification script
- All 12 tests passing: admin auth, APIs, payments, exchange rates
- Added DEPLOYMENT-VERIFICATION.md with post-deployment testing process
- Tests verify: LittleShop, TeleBot, and SilverPay integration
- Exchange rate fix: Use BTC/GBP format (crypto-to-fiat)
- Payment response updated for new walletAddress field
- Admin login correctly accepts 401 for API testing

IMPORTANT: Run ./test-integration-fixed.sh after EVERY deployment

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-25 00:04:30 +01:00

351 lines
12 KiB
Bash

#!/bin/bash
# Integration Test Script for LittleShop, TeleBot, and SilverPay
# Tests production endpoints at admin.thebankofdebbie.giize.com and pay.thebankofdebbie.giize.com
set -e # Exit on first error
# Color codes for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
LITTLESHOP_URL="https://admin.thebankofdebbie.giize.com"
SILVERPAY_URL="https://pay.thebankofdebbie.giize.com"
ADMIN_USERNAME="admin"
ADMIN_PASSWORD="admin"
# Variables to store session data
COOKIE_JAR="/tmp/littleshop_cookies.txt"
AUTH_TOKEN=""
TEST_ORDER_ID=""
TEST_PAYMENT_ID=""
# Test results
TESTS_PASSED=0
TESTS_FAILED=0
# Function to print test status
print_test() {
local test_name=$1
local status=$2
local message=$3
if [ "$status" = "PASS" ]; then
echo -e "${GREEN}${NC} $test_name - ${GREEN}PASSED${NC}"
[ ! -z "$message" ] && echo " └─ $message"
((TESTS_PASSED++))
else
echo -e "${RED}${NC} $test_name - ${RED}FAILED${NC}"
[ ! -z "$message" ] && echo " └─ ${RED}$message${NC}"
((TESTS_FAILED++))
fi
}
# Function to check HTTP response code
check_response() {
local response=$1
local expected=$2
local test_name=$3
local http_code=$(echo "$response" | tail -n 1)
local body=$(echo "$response" | head -n -1)
if [ "$http_code" = "$expected" ]; then
print_test "$test_name" "PASS" "HTTP $http_code"
echo "$body"
else
print_test "$test_name" "FAIL" "Expected HTTP $expected, got HTTP $http_code"
echo "$body" | head -20
return 1
fi
}
echo "================================================"
echo "Integration Test Suite"
echo "================================================"
echo "LittleShop: $LITTLESHOP_URL"
echo "SilverPay: $SILVERPAY_URL"
echo "================================================"
echo ""
# Clean up cookie jar
rm -f "$COOKIE_JAR"
# ============================================================
# TEST 1: LittleShop Admin Login
# ============================================================
echo -e "${BLUE}[TEST GROUP 1]${NC} LittleShop Admin Login"
echo "--------------------------------------------"
echo "Testing admin login endpoint..."
LOGIN_RESPONSE=$(curl -s -w "\n%{http_code}" \
-X POST "$LITTLESHOP_URL/Admin/Account/Login" \
-H "Content-Type: application/x-www-form-urlencoded" \
-d "Username=$ADMIN_USERNAME&Password=$ADMIN_PASSWORD" \
-c "$COOKIE_JAR" \
-L)
HTTP_CODE=$(echo "$LOGIN_RESPONSE" | tail -n 1)
# For login, we expect a 302 redirect on success
if [ "$HTTP_CODE" = "302" ] || [ "$HTTP_CODE" = "200" ]; then
# Verify we can access the dashboard
DASHBOARD_RESPONSE=$(curl -s -w "\n%{http_code}" \
"$LITTLESHOP_URL/Admin/Dashboard" \
-b "$COOKIE_JAR")
DASH_CODE=$(echo "$DASHBOARD_RESPONSE" | tail -n 1)
if [ "$DASH_CODE" = "200" ]; then
print_test "Admin Login" "PASS" "Successfully authenticated and accessed dashboard"
else
print_test "Admin Login" "FAIL" "Login succeeded but couldn't access dashboard (HTTP $DASH_CODE)"
fi
else
print_test "Admin Login" "FAIL" "Login failed with HTTP $HTTP_CODE"
fi
echo ""
# ============================================================
# TEST 2: TeleBot-LittleShop Communication
# ============================================================
echo -e "${BLUE}[TEST GROUP 2]${NC} TeleBot-LittleShop Communication"
echo "--------------------------------------------"
# Test public API endpoint for categories
echo "Testing categories API endpoint..."
CATEGORIES_RESPONSE=$(curl -s -w "\n%{http_code}" \
"$LITTLESHOP_URL/api/catalog/categories" \
-H "Accept: application/json")
CAT_CODE=$(echo "$CATEGORIES_RESPONSE" | tail -n 1)
CAT_BODY=$(echo "$CATEGORIES_RESPONSE" | head -n -1)
if [ "$CAT_CODE" = "200" ]; then
# Check if we got valid JSON with categories
if echo "$CAT_BODY" | grep -q '"id"' && echo "$CAT_BODY" | grep -q '"name"'; then
CATEGORY_COUNT=$(echo "$CAT_BODY" | grep -o '"id"' | wc -l)
print_test "Retrieve Categories" "PASS" "Retrieved $CATEGORY_COUNT categories"
else
print_test "Retrieve Categories" "FAIL" "Response doesn't contain valid category data"
fi
else
print_test "Retrieve Categories" "FAIL" "Failed with HTTP $CAT_CODE"
fi
# Test products endpoint
echo "Testing products API endpoint..."
PRODUCTS_RESPONSE=$(curl -s -w "\n%{http_code}" \
"$LITTLESHOP_URL/api/catalog/products" \
-H "Accept: application/json")
PROD_CODE=$(echo "$PRODUCTS_RESPONSE" | tail -n 1)
PROD_BODY=$(echo "$PRODUCTS_RESPONSE" | head -n -1)
if [ "$PROD_CODE" = "200" ]; then
if echo "$PROD_BODY" | grep -q '"id"' && echo "$PROD_BODY" | grep -q '"name"'; then
PRODUCT_COUNT=$(echo "$PROD_BODY" | grep -o '"id"' | wc -l)
print_test "Retrieve Products" "PASS" "Retrieved $PRODUCT_COUNT products"
else
print_test "Retrieve Products" "FAIL" "Response doesn't contain valid product data"
fi
else
print_test "Retrieve Products" "FAIL" "Failed with HTTP $PROD_CODE"
fi
echo ""
# ============================================================
# TEST 3: SilverPay Wallet & Order Operations
# ============================================================
echo -e "${BLUE}[TEST GROUP 3]${NC} SilverPay Operations"
echo "--------------------------------------------"
# Test wallet info endpoint
echo "Testing SilverPay wallet info..."
WALLET_RESPONSE=$(curl -s -w "\n%{http_code}" \
"$SILVERPAY_URL/api/wallets" \
-H "Accept: application/json")
WALLET_CODE=$(echo "$WALLET_RESPONSE" | tail -n 1)
WALLET_BODY=$(echo "$WALLET_RESPONSE" | head -n -1)
if [ "$WALLET_CODE" = "200" ]; then
if echo "$WALLET_BODY" | grep -q '"currency"' || echo "$WALLET_BODY" | grep -q '"address"'; then
WALLET_COUNT=$(echo "$WALLET_BODY" | grep -o '"currency"' | wc -l)
print_test "Get Wallet Info" "PASS" "Retrieved $WALLET_COUNT wallet(s)"
else
print_test "Get Wallet Info" "FAIL" "Response doesn't contain wallet data"
fi
else
print_test "Get Wallet Info" "FAIL" "Failed with HTTP $WALLET_CODE"
fi
# Test list orders endpoint
echo "Testing SilverPay list orders..."
ORDERS_RESPONSE=$(curl -s -w "\n%{http_code}" \
"$SILVERPAY_URL/api/orders" \
-H "Accept: application/json")
ORDERS_CODE=$(echo "$ORDERS_RESPONSE" | tail -n 1)
ORDERS_BODY=$(echo "$ORDERS_RESPONSE" | head -n -1)
if [ "$ORDERS_CODE" = "200" ]; then
print_test "List Orders" "PASS" "Successfully retrieved orders list"
else
print_test "List Orders" "FAIL" "Failed with HTTP $ORDERS_CODE"
fi
# Test create order on testnet
echo "Testing SilverPay create test order..."
CREATE_ORDER_PAYLOAD=$(cat <<EOF
{
"amount": 10.00,
"currency": "GBP",
"description": "Integration Test Order",
"customer_email": "test@integration.com",
"metadata": {
"test": "true",
"timestamp": "$(date -u +%Y%m%d%H%M%S)"
}
}
EOF
)
CREATE_ORDER_RESPONSE=$(curl -s -w "\n%{http_code}" \
-X POST "$SILVERPAY_URL/api/orders" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d "$CREATE_ORDER_PAYLOAD")
CREATE_CODE=$(echo "$CREATE_ORDER_RESPONSE" | tail -n 1)
CREATE_BODY=$(echo "$CREATE_ORDER_RESPONSE" | head -n -1)
if [ "$CREATE_CODE" = "200" ] || [ "$CREATE_CODE" = "201" ]; then
# Extract order ID from response
TEST_ORDER_ID=$(echo "$CREATE_BODY" | grep -o '"id":[^,]*' | head -1 | sed 's/"id"://;s/"//g;s/[[:space:]]//g')
if [ ! -z "$TEST_ORDER_ID" ]; then
print_test "Create Test Order" "PASS" "Created order ID: $TEST_ORDER_ID"
# Now delete the test order
echo "Attempting to delete test order..."
DELETE_RESPONSE=$(curl -s -w "\n%{http_code}" \
-X DELETE "$SILVERPAY_URL/api/orders/$TEST_ORDER_ID" \
-H "Accept: application/json")
DELETE_CODE=$(echo "$DELETE_RESPONSE" | tail -n 1)
if [ "$DELETE_CODE" = "200" ] || [ "$DELETE_CODE" = "204" ]; then
print_test "Delete Test Order" "PASS" "Successfully deleted test order"
else
print_test "Delete Test Order" "FAIL" "Failed to delete test order (HTTP $DELETE_CODE)"
fi
else
print_test "Create Test Order" "FAIL" "Order created but couldn't extract ID"
fi
else
print_test "Create Test Order" "FAIL" "Failed with HTTP $CREATE_CODE"
fi
echo ""
# ============================================================
# TEST 4: LittleShop-SilverPay Integration
# ============================================================
echo -e "${BLUE}[TEST GROUP 4]${NC} LittleShop-SilverPay Integration"
echo "--------------------------------------------"
# Create a test order in LittleShop
echo "Creating test order in LittleShop..."
TEST_ORDER_PAYLOAD=$(cat <<EOF
{
"customerIdentity": "integration-test-$(date +%s)",
"deliveryAddress": "123 Test Street, Test City, TC1 1TC",
"items": [
{
"productId": "00000000-0000-0000-0000-000000000001",
"quantity": 1
}
]
}
EOF
)
LITTLESHOP_ORDER_RESPONSE=$(curl -s -w "\n%{http_code}" \
-X POST "$LITTLESHOP_URL/api/orders" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d "$TEST_ORDER_PAYLOAD")
LS_ORDER_CODE=$(echo "$LITTLESHOP_ORDER_RESPONSE" | tail -n 1)
LS_ORDER_BODY=$(echo "$LITTLESHOP_ORDER_RESPONSE" | head -n -1)
if [ "$LS_ORDER_CODE" = "200" ] || [ "$LS_ORDER_CODE" = "201" ]; then
# Extract LittleShop order ID
LS_ORDER_ID=$(echo "$LS_ORDER_BODY" | grep -o '"id":[^,]*' | head -1 | sed 's/"id"://;s/"//g;s/[[:space:]]//g')
if [ ! -z "$LS_ORDER_ID" ]; then
print_test "Create LittleShop Order" "PASS" "Created order ID: $LS_ORDER_ID"
# Test payment creation through LittleShop
echo "Testing payment creation via LittleShop..."
PAYMENT_PAYLOAD=$(cat <<EOF
{
"cryptocurrency": "BTC",
"customerEmail": "test@integration.com"
}
EOF
)
PAYMENT_RESPONSE=$(curl -s -w "\n%{http_code}" \
-X POST "$LITTLESHOP_URL/api/orders/$LS_ORDER_ID/payments" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d "$PAYMENT_PAYLOAD")
PAYMENT_CODE=$(echo "$PAYMENT_RESPONSE" | tail -n 1)
PAYMENT_BODY=$(echo "$PAYMENT_RESPONSE" | head -n -1)
if [ "$PAYMENT_CODE" = "200" ] || [ "$PAYMENT_CODE" = "201" ]; then
if echo "$PAYMENT_BODY" | grep -q '"paymentAddress"' || echo "$PAYMENT_BODY" | grep -q '"checkoutUrl"'; then
print_test "LittleShop-SilverPay Payment" "PASS" "Payment creation successful"
else
print_test "LittleShop-SilverPay Payment" "FAIL" "Payment created but response missing required fields"
fi
else
print_test "LittleShop-SilverPay Payment" "FAIL" "Payment creation failed (HTTP $PAYMENT_CODE)"
fi
else
print_test "Create LittleShop Order" "FAIL" "Order created but couldn't extract ID"
fi
else
print_test "Create LittleShop Order" "FAIL" "Failed with HTTP $LS_ORDER_CODE"
fi
echo ""
# ============================================================
# TEST SUMMARY
# ============================================================
echo "================================================"
echo -e "${BLUE}TEST SUMMARY${NC}"
echo "================================================"
echo -e "${GREEN}Passed:${NC} $TESTS_PASSED"
echo -e "${RED}Failed:${NC} $TESTS_FAILED"
TOTAL_TESTS=$((TESTS_PASSED + TESTS_FAILED))
echo "Total: $TOTAL_TESTS"
if [ $TESTS_FAILED -eq 0 ]; then
echo ""
echo -e "${GREEN}✓ ALL TESTS PASSED!${NC}"
exit 0
else
echo ""
echo -e "${RED}✗ SOME TESTS FAILED${NC}"
exit 1
fi