#!/bin/bash

# --- GLOBAL TEST RUNNER ---
# Runs tests for all integrated services

RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color

run_container_tests() {
    local container=$1
    local test_dir=$2
    local test_file=$3
    
    echo -e "\n${GREEN}>>> Testing Service: $container <<<${NC}"
    
    # 1. Install dependencies
    docker exec $container pip install pytest httpx > /dev/null 2>&1
    
    # 2. Copy tests and runner to container
    docker cp $test_dir/tests/. $container:/app/tests/
    docker cp $test_dir/run_tests.sh $container:/app/run_tests.sh
    
    # 3. Execute
    docker exec $container chmod +x /app/run_tests.sh
    docker exec $container /app/run_tests.sh
    
    if [ $? -eq 0 ]; then
        echo -e "${GREEN}SUCCESS: $container tests passed.${NC}"
    else
        echo -e "${RED}FAILURE: $container tests failed.${NC}"
    fi
}

# 1. Company Explorer
run_container_tests "company-explorer" "company-explorer/backend" "test_api_integration.py"

# 2. Connector
run_container_tests "connector-superoffice" "connector-superoffice" "test_webhook.py"

# 3. Lead Engine
run_container_tests "lead-engine" "lead-engine" "test_lead_engine.py"

# 4. B2B Marketing Assistant
run_container_tests "b2b-marketing-assistant" "b2b-marketing-assistant" "test_orchestrator.py"

echo -e "\n${GREEN}=== Test Suite Finished ===${NC}"

