#!/bin/bash
# Run all individual test scripts and show summary

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$SCRIPT_DIR"

TOTAL_PASSED=0
TOTAL_FAILED=0
TESTS_RUN=0

run_test_script() {
    local script="$1"
    local name="$2"
    
    echo ""
    echo "========================================="
    echo "Running: $name"
    echo "========================================="
    echo ""
    
    if [ -f "$script" ] && [ -x "$script" ]; then
        if bash "$script"; then
            TOTAL_PASSED=$((TOTAL_PASSED + 1))
            echo -e "\n${GREEN}✓ $name: PASSED${NC}"
        else
            TOTAL_FAILED=$((TOTAL_FAILED + 1))
            echo -e "\n${RED}✗ $name: FAILED${NC}"
        fi
        TESTS_RUN=$((TESTS_RUN + 1))
    else
        echo -e "${RED}✗ Script not found or not executable: $script${NC}"
        TOTAL_FAILED=$((TOTAL_FAILED + 1))
        TESTS_RUN=$((TESTS_RUN + 1))
    fi
}

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

echo "========================================="
echo "Running All Individual Tests"
echo "========================================="
echo ""

run_test_script "test-idempotency.sh" "Idempotency Tests"
run_test_script "test-queue.sh" "Queue Tests"
run_test_script "test-e2e.sh" "E2E/Workflow Tests"
run_test_script "test-concurrency.sh" "Concurrency Tests"

echo ""
echo "========================================="
echo "Overall Summary"
echo "========================================="
echo "Tests Run: $TESTS_RUN"
echo "Passed: $TOTAL_PASSED"
echo "Failed: $TOTAL_FAILED"
echo ""

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

