test-api.ps1 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. # SteamAPI Interface Verification Script
  2. # Verify all endpoints are responding
  3. $baseUrl = "http://127.0.0.1:5000"
  4. $results = @()
  5. function Test-Endpoint {
  6. param(
  7. [string]$Method,
  8. [string]$Path,
  9. [string]$Description,
  10. [object]$Body = $null
  11. )
  12. $url = "$baseUrl$Path"
  13. try {
  14. $params = @{
  15. Uri = $url
  16. Method = $Method
  17. ContentType = "application/json"
  18. TimeoutSec = 10
  19. ErrorAction = "Stop"
  20. }
  21. if ($Body) {
  22. $params.Body = ($Body | ConvertTo-Json -Compress)
  23. }
  24. $response = Invoke-WebRequest @params
  25. $statusCode = [int]$response.StatusCode
  26. return @{
  27. Path = $Path
  28. Method = $Method
  29. Description = $Description
  30. Status = "OK"
  31. StatusCode = $statusCode
  32. Message = "Endpoint is running"
  33. }
  34. }
  35. catch [System.Net.WebException] {
  36. $response = $_.Exception.Response
  37. if ($response -ne $null) {
  38. $statusCode = [int]$response.StatusCode
  39. # Any HTTP response means the endpoint is running
  40. return @{
  41. Path = $Path
  42. Method = $Method
  43. Description = $Description
  44. Status = "OK"
  45. StatusCode = $statusCode
  46. Message = "Endpoint is running (HTTP $statusCode)"
  47. }
  48. }
  49. return @{
  50. Path = $Path
  51. Method = $Method
  52. Description = $Description
  53. Status = "FAIL"
  54. StatusCode = 0
  55. Message = "Endpoint not responding: Connection failed"
  56. }
  57. }
  58. catch {
  59. return @{
  60. Path = $Path
  61. Method = $Method
  62. Description = $Description
  63. Status = "FAIL"
  64. StatusCode = 0
  65. Message = "Endpoint not responding: $($_.Exception.Message)"
  66. }
  67. }
  68. }
  69. Write-Host "========================================" -ForegroundColor Cyan
  70. Write-Host " SteamAPI Interface Verification" -ForegroundColor Cyan
  71. Write-Host "========================================" -ForegroundColor Cyan
  72. Write-Host ""
  73. # Check if port 5000 is listening
  74. Write-Host "[1] Checking port 5000 status..." -ForegroundColor Yellow
  75. $portCheck = netstat -ano | Select-String ":5000.*LISTENING"
  76. if ($portCheck) {
  77. Write-Host " Port 5000 is LISTENING" -ForegroundColor Green
  78. } else {
  79. Write-Host " Port 5000 is NOT listening" -ForegroundColor Red
  80. exit 1
  81. }
  82. Write-Host ""
  83. # Define all endpoints from Program.cs
  84. $endpoints = @(
  85. @{
  86. Method = "POST"
  87. Path = "/login"
  88. Description = "Steam Login"
  89. Body = @{ Username = "test"; Password = "test"; MaFilePath = "test.json" }
  90. },
  91. @{
  92. Method = "POST"
  93. Path = "/wallet-balance"
  94. Description = "Wallet Balance Query"
  95. Body = @{ SteamLoginSecure = "" }
  96. },
  97. @{
  98. Method = "POST"
  99. Path = "/trade-confirmations/list"
  100. Description = "Trade Confirmations List"
  101. Body = @{ MaFilePath = "test.json"; Session = $null }
  102. },
  103. @{
  104. Method = "POST"
  105. Path = "/trade-confirmations/operate"
  106. Description = "Trade Confirmation Operate"
  107. Body = @{ MaFilePath = "test.json"; Session = $null; ConfirmationId = 0; Operation = "accept" }
  108. }
  109. )
  110. Write-Host "[2] Testing all endpoints..." -ForegroundColor Yellow
  111. Write-Host ""
  112. $index = 1
  113. foreach ($endpoint in $endpoints) {
  114. $result = Test-Endpoint -Method $endpoint.Method -Path $endpoint.Path -Description $endpoint.Description -Body $endpoint.Body
  115. $results += $result
  116. $statusIcon = if ($result.Status -eq "OK") { "[OK]" } else { "[FAIL]" }
  117. $statusColor = if ($result.Status -eq "OK") { "Green" } else { "Red" }
  118. Write-Host " $index. $($result.Method) $($result.Path)" -ForegroundColor White
  119. Write-Host " Description: $($result.Description)" -ForegroundColor Gray
  120. Write-Host " Status: $statusIcon $($result.StatusCode) - $($result.Message)" -ForegroundColor $statusColor
  121. Write-Host ""
  122. $index++
  123. }
  124. # Summary
  125. Write-Host "========================================" -ForegroundColor Cyan
  126. Write-Host " Verification Result" -ForegroundColor Cyan
  127. Write-Host "========================================" -ForegroundColor Cyan
  128. $okCount = ($results | Where-Object { $_.Status -eq "OK" }).Count
  129. $failCount = ($results | Where-Object { $_.Status -eq "FAIL" }).Count
  130. Write-Host " Total endpoints: $($results.Count)"
  131. Write-Host " Passed: $okCount" -ForegroundColor Green
  132. if ($failCount -gt 0) {
  133. Write-Host " Failed: $failCount" -ForegroundColor Red
  134. }
  135. Write-Host ""
  136. if ($failCount -eq 0) {
  137. Write-Host "All endpoints are running successfully!" -ForegroundColor Green
  138. exit 0
  139. } else {
  140. Write-Host "Some endpoints failed to respond!" -ForegroundColor Red
  141. exit 1
  142. }