# PowerShell script to run integration tests with containerized infrastructure # Sets up environment variables and runs the integration test suite Write-Host "=== Flyer Crawler Integration Test Runner ===" -ForegroundColor Cyan Write-Host "" # Check if containers are running Write-Host "Checking container status..." -ForegroundColor Yellow $postgresRunning = podman ps --filter "name=flyer-crawler-postgres" --format "{{.Names}}" 2>$null $redisRunning = podman ps --filter "name=flyer-crawler-redis" --format "{{.Names}}" 2>$null if (-not $postgresRunning) { Write-Host "ERROR: PostgreSQL container is not running!" -ForegroundColor Red Write-Host "Start it with: podman start flyer-crawler-postgres" -ForegroundColor Yellow exit 1 } if (-not $redisRunning) { Write-Host "ERROR: Redis container is not running!" -ForegroundColor Red Write-Host "Start it with: podman start flyer-crawler-redis" -ForegroundColor Yellow exit 1 } Write-Host "✓ PostgreSQL container: $postgresRunning" -ForegroundColor Green Write-Host "✓ Redis container: $redisRunning" -ForegroundColor Green Write-Host "" # Set environment variables for integration tests Write-Host "Setting environment variables..." -ForegroundColor Yellow $env:NODE_ENV = "test" $env:DB_HOST = "localhost" $env:DB_USER = "postgres" $env:DB_PASSWORD = "postgres" $env:DB_NAME = "flyer_crawler_dev" $env:DB_PORT = "5432" $env:REDIS_URL = "redis://localhost:6379" $env:REDIS_PASSWORD = "" $env:FRONTEND_URL = "http://localhost:5173" $env:VITE_API_BASE_URL = "http://localhost:3001/api" $env:JWT_SECRET = "test-jwt-secret-for-integration-tests" $env:NODE_OPTIONS = "--max-old-space-size=8192" Write-Host "✓ Environment configured" -ForegroundColor Green Write-Host "" # Display configuration Write-Host "Test Configuration:" -ForegroundColor Cyan Write-Host " NODE_ENV: $env:NODE_ENV" Write-Host " Database: $env:DB_HOST`:$env:DB_PORT/$env:DB_NAME" Write-Host " Redis: $env:REDIS_URL" Write-Host " Frontend URL: $env:FRONTEND_URL" Write-Host "" # Check database connectivity Write-Host "Verifying database connection..." -ForegroundColor Yellow $dbCheck = podman exec flyer-crawler-postgres psql -U postgres -d flyer_crawler_dev -c "SELECT 1;" 2>&1 if ($LASTEXITCODE -ne 0) { Write-Host "ERROR: Cannot connect to database!" -ForegroundColor Red Write-Host $dbCheck exit 1 } Write-Host "✓ Database connection successful" -ForegroundColor Green Write-Host "" # Check URL constraints are enabled Write-Host "Verifying URL constraints..." -ForegroundColor Yellow $constraints = podman exec flyer-crawler-postgres psql -U postgres -d flyer_crawler_dev -t -A -c "SELECT COUNT(*) FROM pg_constraint WHERE conname LIKE '%url_check';" Write-Host "✓ Found $constraints URL constraint(s)" -ForegroundColor Green Write-Host "" # Run integration tests Write-Host "=== Running Integration Tests ===" -ForegroundColor Cyan Write-Host "" npm run test:integration $exitCode = $LASTEXITCODE Write-Host "" if ($exitCode -eq 0) { Write-Host "=== Integration Tests PASSED ===" -ForegroundColor Green } else { Write-Host "=== Integration Tests FAILED ===" -ForegroundColor Red Write-Host "Exit code: $exitCode" -ForegroundColor Red } exit $exitCode