# Test Railway API Endpoints # Run this script after Railway deployment completes $baseUrl = "https://web-production-47eb.up.railway.app" Write-Host "๐Ÿงช Testing Railway Backend..." -ForegroundColor Cyan Write-Host "" # Test 1: Health Check Write-Host "1๏ธโƒฃ Testing Health Check..." -ForegroundColor Yellow try { $response = Invoke-WebRequest -Uri "$baseUrl/" -Method GET -UseBasicParsing $json = $response.Content | ConvertFrom-Json Write-Host "โœ… Health Check OK" -ForegroundColor Green Write-Host " Status: $($json.status)" -ForegroundColor Gray Write-Host " Message: $($json.message)" -ForegroundColor Gray Write-Host " Version: $($json.version)" -ForegroundColor Gray } catch { Write-Host "โŒ Health Check FAILED" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "" # Test 2: Database Connection Write-Host "2๏ธโƒฃ Testing Database Connection..." -ForegroundColor Yellow try { $response = Invoke-WebRequest -Uri "$baseUrl/api/database/test" -Method GET -UseBasicParsing $json = $response.Content | ConvertFrom-Json if ($json.success) { Write-Host "โœ… Database Connection OK" -ForegroundColor Green Write-Host " Message: $($json.message)" -ForegroundColor Gray } else { Write-Host "โŒ Database Connection FAILED" -ForegroundColor Red Write-Host " Message: $($json.message)" -ForegroundColor Red } } catch { Write-Host "โŒ Database Connection FAILED" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "" # Test 3: Initialize Database Write-Host "3๏ธโƒฃ Initializing Database Tables..." -ForegroundColor Yellow try { $response = Invoke-WebRequest -Uri "$baseUrl/api/database/init" -Method POST -UseBasicParsing $json = $response.Content | ConvertFrom-Json if ($json.success) { Write-Host "โœ… Database Initialized" -ForegroundColor Green Write-Host " Message: $($json.message)" -ForegroundColor Gray } else { Write-Host "โš ๏ธ Database Init Warning" -ForegroundColor Yellow Write-Host " Message: $($json.message)" -ForegroundColor Yellow } } catch { Write-Host "โŒ Database Init FAILED" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "" # Test 4: Get Latest Data Write-Host "4๏ธโƒฃ Getting Latest Data..." -ForegroundColor Yellow try { $response = Invoke-WebRequest -Uri "$baseUrl/api/data/latest" -Method GET -UseBasicParsing $json = $response.Content | ConvertFrom-Json if ($json.success) { Write-Host "โœ… Latest Data Retrieved" -ForegroundColor Green Write-Host " Suhu: $($json.data.suhu)ยฐC" -ForegroundColor Gray Write-Host " Berat: $($json.data.berat)g" -ForegroundColor Gray Write-Host " Target: $($json.data.target)g" -ForegroundColor Gray Write-Host " Status: $($json.data.status)" -ForegroundColor Gray } else { Write-Host "โŒ Get Latest Data FAILED" -ForegroundColor Red } } catch { Write-Host "โŒ Get Latest Data FAILED" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "" # Test 5: Get Statistics Write-Host "5๏ธโƒฃ Getting Statistics..." -ForegroundColor Yellow try { $response = Invoke-WebRequest -Uri "$baseUrl/api/stats" -Method GET -UseBasicParsing $json = $response.Content | ConvertFrom-Json if ($json.success) { Write-Host "โœ… Statistics Retrieved" -ForegroundColor Green Write-Host " Connected Clients: $($json.stats.connectedClients)" -ForegroundColor Gray Write-Host " Sensor Data Count: $($json.stats.sensorDataCount)" -ForegroundColor Gray Write-Host " Status History Count: $($json.stats.statusHistoryCount)" -ForegroundColor Gray Write-Host " Uptime: $([math]::Round($json.stats.uptime, 2))s" -ForegroundColor Gray } else { Write-Host "โŒ Get Statistics FAILED" -ForegroundColor Red } } catch { Write-Host "โŒ Get Statistics FAILED" -ForegroundColor Red Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red } Write-Host "" Write-Host "๐ŸŽ‰ Testing Complete!" -ForegroundColor Cyan Write-Host "" Write-Host "๐Ÿ“ Next Steps:" -ForegroundColor Yellow Write-Host " 1. Check Railway logs for any errors" -ForegroundColor Gray Write-Host " 2. Test ESP32 connection to HiveMQ" -ForegroundColor Gray Write-Host " 3. Test Flutter app connection" -ForegroundColor Gray Write-Host ""