#!/bin/bash # Comprehensive E2E Testing Script for LittleShop and SilverPAY # This script tests all major features and integration points set -e # Exit on error API_URL="http://localhost:8080/api" SILVERPAY_URL="http://31.97.57.205:8001/api" TEST_RESULTS="" TESTS_PASSED=0 TESTS_FAILED=0 # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Test function run_test() { local test_name="$1" local test_command="$2" echo -e "${YELLOW}Testing: $test_name${NC}" if eval "$test_command"; then echo -e "${GREEN}✓ $test_name passed${NC}" TEST_RESULTS="$TEST_RESULTS\n✓ $test_name" ((TESTS_PASSED++)) return 0 else echo -e "${RED}✗ $test_name failed${NC}" TEST_RESULTS="$TEST_RESULTS\n✗ $test_name" ((TESTS_FAILED++)) return 1 fi } # Helper function to check HTTP status check_http_status() { local url="$1" local expected_status="$2" local actual_status=$(curl -s -o /dev/null -w "%{http_code}" "$url") [ "$actual_status" == "$expected_status" ] } echo "=========================================" echo " LittleShop & SilverPAY E2E Testing" echo "=========================================" echo "" # 1. Health Check Tests echo -e "\n${YELLOW}=== 1. Health Check Tests ===${NC}" run_test "LittleShop API Health" "check_http_status '$API_URL/../health' 200" # 2. Authentication Tests echo -e "\n${YELLOW}=== 2. Authentication Tests ===${NC}" # Test login with valid credentials LOGIN_RESPONSE=$(curl -s -X POST "$API_URL/auth/login" \ -H "Content-Type: application/json" \ -d '{"username":"admin","password":"admin"}') run_test "Admin Login" "echo '$LOGIN_RESPONSE' | grep -q 'token'" # Extract token for authenticated requests TOKEN=$(echo "$LOGIN_RESPONSE" | jq -r '.token // empty') if [ -z "$TOKEN" ]; then echo -e "${RED}Failed to extract JWT token. Some tests will fail.${NC}" else AUTH_HEADER="Authorization: Bearer $TOKEN" fi # Test login with invalid credentials INVALID_LOGIN=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$API_URL/auth/login" \ -H "Content-Type: application/json" \ -d '{"username":"invalid","password":"wrong"}') run_test "Invalid Login Returns 401" "[ '$INVALID_LOGIN' == '401' ]" # 3. User Management Tests echo -e "\n${YELLOW}=== 3. User Management Tests ===${NC}" # Create a test user CREATE_USER=$(curl -s -X POST "$API_URL/users" \ -H "$AUTH_HEADER" \ -H "Content-Type: application/json" \ -d '{ "username": "testuser_'$(date +%s)'", "password": "TestPass123!", "email": "test@example.com", "role": "Staff" }') USER_ID=$(echo "$CREATE_USER" | jq -r '.id // empty') run_test "Create User" "[ ! -z '$USER_ID' ]" # Get all users run_test "Get Users List" "curl -s -H '$AUTH_HEADER' '$API_URL/users' | jq -e '.[] | .id' > /dev/null" # Get specific user if [ ! -z "$USER_ID" ]; then run_test "Get User by ID" "check_http_status '$API_URL/users/$USER_ID' 200" # Update user UPDATE_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X PUT "$API_URL/users/$USER_ID" \ -H "$AUTH_HEADER" \ -H "Content-Type: application/json" \ -d '{"email": "updated@example.com"}') run_test "Update User" "[ '$UPDATE_STATUS' == '204' ]" # Delete user DELETE_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X DELETE "$API_URL/users/$USER_ID" \ -H "$AUTH_HEADER") run_test "Delete User (Soft Delete)" "[ '$DELETE_STATUS' == '204' ]" fi # 4. Catalog Tests echo -e "\n${YELLOW}=== 4. Catalog Tests ===${NC}" # Get categories run_test "Get Categories" "check_http_status '$API_URL/catalog/categories' 200" # Get products PRODUCTS_RESPONSE=$(curl -s "$API_URL/catalog/products") run_test "Get Products" "echo '$PRODUCTS_RESPONSE' | jq -e '.items' > /dev/null" # Get products with pagination run_test "Get Products with Pagination" "curl -s '$API_URL/catalog/products?pageNumber=1&pageSize=5' | jq -e '.pageSize == 5' > /dev/null" # 5. Product Management Tests echo -e "\n${YELLOW}=== 5. Product Management Tests ===${NC}" # Create a test product CREATE_PRODUCT=$(curl -s -X POST "$API_URL/products" \ -H "$AUTH_HEADER" \ -H "Content-Type: application/json" \ -d '{ "name": "Test Product '$(date +%s)'", "description": "This is a test product", "price": 29.99, "stock": 100, "weight": 500, "weightUnit": "Grams", "isActive": true }') PRODUCT_ID=$(echo "$CREATE_PRODUCT" | jq -r '.id // empty') run_test "Create Product" "[ ! -z '$PRODUCT_ID' ]" if [ ! -z "$PRODUCT_ID" ]; then # Get product details run_test "Get Product by ID" "check_http_status '$API_URL/catalog/products/$PRODUCT_ID' 200" # Add product variations VARIATION_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$API_URL/products/$PRODUCT_ID/variations" \ -H "$AUTH_HEADER" \ -H "Content-Type: application/json" \ -d '{ "productId": "'$PRODUCT_ID'", "quantity": 3, "price": 75.00, "description": "Bundle of 3 - Save 15%" }') run_test "Add Product Variation" "[ '$VARIATION_STATUS' == '201' ] || [ '$VARIATION_STATUS' == '200' ]" fi # 6. Order Management Tests echo -e "\n${YELLOW}=== 6. Order Management Tests ===${NC}" # Create an order CREATE_ORDER=$(curl -s -X POST "$API_URL/orders" \ -H "Content-Type: application/json" \ -d '{ "identityReference": "test_customer_'$(date +%s)'", "shippingInfo": "123 Test St, Test City, TC 12345", "items": [ { "productId": "'${PRODUCT_ID:-00000000-0000-0000-0000-000000000000}'", "quantity": 2, "price": 29.99 } ] }') ORDER_ID=$(echo "$CREATE_ORDER" | jq -r '.id // empty') run_test "Create Order" "[ ! -z '$ORDER_ID' ]" if [ ! -z "$ORDER_ID" ]; then # Get order details run_test "Get Order by ID" "curl -s '$API_URL/orders/by-identity/test_customer_'$(date +%s)'/$ORDER_ID' | jq -e '.id' > /dev/null" fi # 7. SilverPAY Integration Tests echo -e "\n${YELLOW}=== 7. SilverPAY Integration Tests ===${NC}" if [ ! -z "$ORDER_ID" ]; then # Create payment via SilverPAY CREATE_PAYMENT=$(curl -s -X POST "$API_URL/orders/$ORDER_ID/payments" \ -H "Content-Type: application/json" \ -d '{ "cryptocurrency": "BTC", "amount": 59.98 }') PAYMENT_ID=$(echo "$CREATE_PAYMENT" | jq -r '.id // empty') run_test "Create SilverPAY Payment" "[ ! -z '$PAYMENT_ID' ]" # Check payment details if [ ! -z "$PAYMENT_ID" ]; then run_test "Payment Has Wallet Address" "echo '$CREATE_PAYMENT' | jq -e '.walletAddress' > /dev/null" run_test "Payment Has Crypto Amount" "echo '$CREATE_PAYMENT' | jq -e '.cryptoAmount' > /dev/null" fi fi # Test SilverPAY webhook endpoint WEBHOOK_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$API_URL/orders/payments/webhook" \ -H "Content-Type: application/json" \ -H "X-Webhook-Signature: test_signature" \ -d '{ "event": "payment.confirmed", "payment_id": "test_payment", "order_id": "test_order", "status": "confirmed" }') run_test "SilverPAY Webhook Endpoint" "[ '$WEBHOOK_STATUS' == '200' ] || [ '$WEBHOOK_STATUS' == '400' ]" # 8. Push Notification Tests echo -e "\n${YELLOW}=== 8. Push Notification Tests ===${NC}" # Test push subscription endpoint PUSH_SUB_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$API_URL/push/subscribe" \ -H "$AUTH_HEADER" \ -H "Content-Type: application/json" \ -d '{ "endpoint": "https://fcm.googleapis.com/fcm/send/test", "keys": { "p256dh": "test_key", "auth": "test_auth" } }') run_test "Push Subscription Endpoint" "[ '$PUSH_SUB_STATUS' == '200' ] || [ '$PUSH_SUB_STATUS' == '201' ] || [ '$PUSH_SUB_STATUS' == '404' ]" # 9. Admin Panel Tests echo -e "\n${YELLOW}=== 9. Admin Panel Tests ===${NC}" # Test admin login page run_test "Admin Login Page" "check_http_status 'http://localhost:8080/Admin/Account/Login' 200" # Test admin dashboard (requires authentication) ADMIN_COOKIE=$(curl -s -c - -X POST "http://localhost:8080/Admin/Account/Login" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "Username=admin&Password=admin&RememberMe=false" | \ grep -o 'LittleShop.Auth[^\s]*' | head -1) if [ ! -z "$ADMIN_COOKIE" ]; then run_test "Admin Dashboard Access" "curl -s -o /dev/null -w '%{http_code}' -H 'Cookie: $ADMIN_COOKIE' 'http://localhost:8080/Admin/Dashboard' | grep -q '200'" fi # 10. TeleBot Integration Tests echo -e "\n${YELLOW}=== 10. TeleBot Integration Tests ===${NC}" # Check if TeleBot is running run_test "TeleBot Service Running" "check_http_status 'http://localhost:5010/health' 200 || true" # Test bot registration endpoint BOT_REG_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$API_URL/bots/register" \ -H "Content-Type: application/json" \ -d '{ "name": "Test Bot", "description": "E2E Test Bot" }') run_test "Bot Registration Endpoint" "[ '$BOT_REG_STATUS' == '200' ] || [ '$BOT_REG_STATUS' == '409' ]" # 11. Error Handling Tests echo -e "\n${YELLOW}=== 11. Error Handling Tests ===${NC}" # Test 404 for non-existent endpoints run_test "404 for Non-existent Endpoint" "check_http_status '$API_URL/nonexistent' 404" # Test validation errors VALIDATION_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST "$API_URL/orders" \ -H "Content-Type: application/json" \ -d '{}') run_test "Validation Error Returns 400" "[ '$VALIDATION_STATUS' == '400' ]" # 12. Performance Tests echo -e "\n${YELLOW}=== 12. Performance Tests ===${NC}" # Simple load test - 10 concurrent requests PERF_TEST_RESULT=$(seq 1 10 | xargs -P10 -I{} curl -s -o /dev/null -w "%{http_code}\n" "$API_URL/catalog/products" | grep -c "200") run_test "Handle Concurrent Requests" "[ '$PERF_TEST_RESULT' -ge '8' ]" # Allow 80% success rate # Response time test START_TIME=$(date +%s%3N) curl -s "$API_URL/catalog/products" > /dev/null END_TIME=$(date +%s%3N) RESPONSE_TIME=$((END_TIME - START_TIME)) run_test "Products API Response < 1s" "[ '$RESPONSE_TIME' -lt '1000' ]" # ============================================ # Test Summary # ============================================ echo "" echo "=========================================" echo " TEST SUMMARY" echo "=========================================" echo -e "Tests Passed: ${GREEN}$TESTS_PASSED${NC}" echo -e "Tests Failed: ${RED}$TESTS_FAILED${NC}" echo "" echo "Detailed Results:" echo -e "$TEST_RESULTS" echo "" if [ $TESTS_FAILED -eq 0 ]; then echo -e "${GREEN}✓ All tests passed successfully!${NC}" exit 0 else echo -e "${RED}✗ Some tests failed. Please review the results above.${NC}" exit 1 fi