# E2E Integration Test for LittleShop + TeleBot + SilverPay # Tests the complete flow across all three components $ErrorActionPreference = "Stop" $baseUrl = "http://localhost:5000" $teleBotUrl = "http://localhost:5010" $silverPayUrl = "http://10.0.0.51:5500" Write-Host "============================================" -ForegroundColor Cyan Write-Host "E2E INTEGRATION TEST - LittleShop Ecosystem" -ForegroundColor Cyan Write-Host "============================================" -ForegroundColor Cyan Write-Host "" # Test results tracking $testResults = @{ Passed = 0 Failed = 0 Total = 0 Tests = @() } function Test-Endpoint { param( [string]$Name, [string]$Url, [string]$Method = "GET", [object]$Body = $null, [hashtable]$Headers = @{} ) $testResults.Total++ $startTime = Get-Date try { Write-Host "[$($testResults.Total)] Testing: $Name" -ForegroundColor Yellow $params = @{ Uri = $Url Method = $Method Headers = $Headers TimeoutSec = 10 } if ($Body) { $params.Body = ($Body | ConvertTo-Json -Depth 10) $params.ContentType = "application/json" } $response = Invoke-WebRequest @params $elapsed = (Get-Date) - $startTime if ($response.StatusCode -ge 200 -and $response.StatusCode -lt 300) { Write-Host " ✅ PASSED - Status: $($response.StatusCode), Time: $($elapsed.TotalMilliseconds)ms" -ForegroundColor Green $testResults.Passed++ $testResults.Tests += @{ Name = $Name Status = "PASSED" StatusCode = $response.StatusCode Time = $elapsed.TotalMilliseconds Response = $response.Content } return $response } else { throw "Unexpected status code: $($response.StatusCode)" } } catch { $elapsed = (Get-Date) - $startTime Write-Host " ❌ FAILED - Error: $($_.Exception.Message), Time: $($elapsed.TotalMilliseconds)ms" -ForegroundColor Red $testResults.Failed++ $testResults.Tests += @{ Name = $Name Status = "FAILED" Error = $_.Exception.Message Time = $elapsed.TotalMilliseconds } return $null } } Write-Host "Phase 1: Service Health Checks" -ForegroundColor Cyan Write-Host "-------------------------------" -ForegroundColor Cyan # Test 1: LittleShop API Health $response = Test-Endpoint -Name "LittleShop API Health Check" -Url "$baseUrl/health" # Test 2: TeleBot API Health $response = Test-Endpoint -Name "TeleBot API Health Check" -Url "$teleBotUrl/health" # Test 3: SilverPay API Health $response = Test-Endpoint -Name "SilverPay API Health Check" -Url "$silverPayUrl/api/health" Write-Host "" Write-Host "Phase 2: Product Catalog Integration" -ForegroundColor Cyan Write-Host "-------------------------------------" -ForegroundColor Cyan # Test 4: Get Categories $categoriesResponse = Test-Endpoint -Name "Get Product Categories" -Url "$baseUrl/api/catalog/categories" if ($categoriesResponse) { $categories = $categoriesResponse.Content | ConvertFrom-Json Write-Host " 📦 Found $($categories.Count) categories" -ForegroundColor Gray } # Test 5: Get Products $productsResponse = Test-Endpoint -Name "Get Product Catalog" -Url "$baseUrl/api/catalog/products" if ($productsResponse) { $products = $productsResponse.Content | ConvertFrom-Json Write-Host " 📦 Found $($products.Count) products" -ForegroundColor Gray if ($products.Count -gt 0) { $testProduct = $products[0] Write-Host " 📦 Test Product: $($testProduct.name) - £$($testProduct.price)" -ForegroundColor Gray } } Write-Host "" Write-Host "Phase 3: Order Creation Workflow" -ForegroundColor Cyan Write-Host "--------------------------------" -ForegroundColor Cyan # Test 6: Create Order if ($products -and $products.Count -gt 0) { $orderData = @{ identityReference = "telegram_e2e_test_$(Get-Date -Format 'yyyyMMddHHmmss')" items = @( @{ productId = $products[0].id quantity = 2 } ) } $orderResponse = Test-Endpoint -Name "Create Order" -Url "$baseUrl/api/orders" -Method "POST" -Body $orderData if ($orderResponse) { $order = $orderResponse.Content | ConvertFrom-Json Write-Host " 📝 Order ID: $($order.id)" -ForegroundColor Gray Write-Host " 💰 Total Amount: £$($order.totalPrice)" -ForegroundColor Gray Write-Host " 📊 Status: $($order.status)" -ForegroundColor Gray Write-Host "" Write-Host "Phase 4: Payment Integration with SilverPay" -ForegroundColor Cyan Write-Host "-------------------------------------------" -ForegroundColor Cyan # Test 7: Create Payment $paymentData = @{ orderId = $order.id cryptoCurrency = "BTC" } $paymentResponse = Test-Endpoint -Name "Create Payment for Order" ` -Url "$baseUrl/api/orders/$($order.id)/payments" ` -Method "POST" ` -Body $paymentData if ($paymentResponse) { $payment = $paymentResponse.Content | ConvertFrom-Json Write-Host " 💳 Payment ID: $($payment.id)" -ForegroundColor Gray Write-Host " ₿ Crypto Currency: $($payment.cryptoCurrency)" -ForegroundColor Gray Write-Host " 💰 Crypto Amount: $($payment.cryptoAmount)" -ForegroundColor Gray if ($payment.paymentUrl) { Write-Host " 🔗 Payment URL: $($payment.paymentUrl)" -ForegroundColor Gray } # Test 8: Verify Order Status Updated $verifyOrderResponse = Test-Endpoint -Name "Verify Order After Payment" ` -Url "$baseUrl/api/orders/by-identity/$($orderData.identityReference)/$($order.id)" if ($verifyOrderResponse) { $updatedOrder = $verifyOrderResponse.Content | ConvertFrom-Json Write-Host " 📊 Updated Status: $($updatedOrder.status)" -ForegroundColor Gray } } } } else { Write-Host " ⚠️ SKIPPED - No products available for testing" -ForegroundColor Yellow $testResults.Total += 3 } Write-Host "" Write-Host "Phase 5: Bot Activity Tracking Performance" -ForegroundColor Cyan Write-Host "------------------------------------------" -ForegroundColor Cyan # Test 9: Bot Activity Tracking (verify no 3-second delays) $activityData = @{ sessionIdentifier = "test_session_$(Get-Date -Format 'yyyyMMddHHmmss')" userDisplayName = "E2E Test User" activityType = "Browse" activityDescription = "E2E test activity" platform = "Test" location = "Unknown" timestamp = (Get-Date).ToUniversalTime().ToString("o") } $activityResponse = Test-Endpoint -Name "Bot Activity Tracking (Performance Test)" ` -Url "$baseUrl/api/bot/activity" ` -Method "POST" ` -Body $activityData if ($activityResponse) { $activityTest = $testResults.Tests | Where-Object { $_.Name -eq "Bot Activity Tracking (Performance Test)" } if ($activityTest.Time -lt 1000) { Write-Host " ⚡ Performance: EXCELLENT (<1000ms)" -ForegroundColor Green } elseif ($activityTest.Time -lt 3000) { Write-Host " ⚡ Performance: ACCEPTABLE (<3000ms)" -ForegroundColor Yellow } else { Write-Host " ⚠️ Performance: POOR (>3000ms) - DNS resolution issue may still exist" -ForegroundColor Red } } # Test 10: Multiple rapid activity tracking calls Write-Host "" Write-Host " Testing rapid activity tracking (3 sequential calls)..." -ForegroundColor Gray $rapidTestTimes = @() for ($i = 1; $i -le 3; $i++) { $startTime = Get-Date try { Invoke-WebRequest -Uri "$baseUrl/api/bot/activity" ` -Method POST ` -Body ($activityData | ConvertTo-Json) ` -ContentType "application/json" ` -TimeoutSec 5 | Out-Null $elapsed = ((Get-Date) - $startTime).TotalMilliseconds $rapidTestTimes += $elapsed Write-Host " Call ${i}: $([math]::Round($elapsed, 2))ms" -ForegroundColor Gray } catch { Write-Host " Call ${i}: FAILED - $($_.Exception.Message)" -ForegroundColor Red } } if ($rapidTestTimes.Count -gt 0) { $avgTime = ($rapidTestTimes | Measure-Object -Average).Average Write-Host " ⚡ Average Time: $([math]::Round($avgTime, 2))ms" -ForegroundColor $(if ($avgTime -lt 1000) { "Green" } else { "Red" }) } Write-Host "" Write-Host "============================================" -ForegroundColor Cyan Write-Host "TEST SUMMARY" -ForegroundColor Cyan Write-Host "============================================" -ForegroundColor Cyan Write-Host "Total Tests: $($testResults.Total)" -ForegroundColor White Write-Host "Passed: $($testResults.Passed)" -ForegroundColor Green Write-Host "Failed: $($testResults.Failed)" -ForegroundColor Red Write-Host "Pass Rate: $([math]::Round(($testResults.Passed / $testResults.Total) * 100, 2))%" -ForegroundColor $(if ($testResults.Passed -eq $testResults.Total) { "Green" } else { "Yellow" }) Write-Host "" # Detailed test results Write-Host "Detailed Test Results:" -ForegroundColor Cyan Write-Host "---------------------" -ForegroundColor Cyan foreach ($test in $testResults.Tests) { $icon = if ($test.Status -eq "PASSED") { "✅" } else { "❌" } $color = if ($test.Status -eq "PASSED") { "Green" } else { "Red" } Write-Host "$icon $($test.Name)" -ForegroundColor $color if ($test.Time) { Write-Host " Time: $([math]::Round($test.Time, 2))ms" -ForegroundColor Gray } if ($test.StatusCode) { Write-Host " Status Code: $($test.StatusCode)" -ForegroundColor Gray } if ($test.Error) { Write-Host " Error: $($test.Error)" -ForegroundColor Red } } Write-Host "" Write-Host "============================================" -ForegroundColor Cyan # Exit with appropriate code if ($testResults.Failed -eq 0) { Write-Host "🎉 ALL TESTS PASSED!" -ForegroundColor Green exit 0 } else { Write-Host "⚠️ SOME TESTS FAILED!" -ForegroundColor Red exit 1 }