diff --git a/TASKS.md b/TASKS.md index 3db0cfb..4a37d27 100644 --- a/TASKS.md +++ b/TASKS.md @@ -36,7 +36,7 @@ - [x] Add startup migration application. ## Testing & Quality -- [ ] Happy-path smoke test script (manual or minimal automated) for phase flow. +- [x] Happy-path smoke test script (manual or minimal automated) for phase flow. - [ ] Lint/format via `dotnet format` (optional) and ensure build succeeds. ## Deployment diff --git a/scripts/smoke.ps1 b/scripts/smoke.ps1 new file mode 100644 index 0000000..88fc184 --- /dev/null +++ b/scripts/smoke.ps1 @@ -0,0 +1,78 @@ +Param( + [string]$BaseUrl = "http://localhost:5116", + [string]$AdminKey = $env:ADMIN_PASSWORD +) + +if (-not $AdminKey) { + Write-Error "Set ADMIN_PASSWORD env var or pass -AdminKey." + exit 1 +} + +$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession + +function Invoke-Json { + param( + [Parameter(Mandatory=$true)][string]$Method, + [Parameter(Mandatory=$true)][string]$Path, + [object]$Body = $null, + [hashtable]$Headers = @{} + ) + $uri = "$BaseUrl$Path" + $params = @{ + Method = $Method + Uri = $uri + WebSession = $session + Headers = $Headers + } + if ($Body) { $params.Body = ($Body | ConvertTo-Json -Depth 5); $params.ContentType = "application/json" } + try { + $response = Invoke-WebRequest @params -ErrorAction Stop + if ($response.Content) { return ($response.Content | ConvertFrom-Json) } + return $null + } catch { + Write-Error "Request failed: $Method $uri`n$($_.Exception.Message)" + if ($_.Exception.Response -and $_.Exception.Response.GetResponseStream()) { + $reader = New-Object IO.StreamReader $_.Exception.Response.GetResponseStream() + Write-Error "Response body:`n$($reader.ReadToEnd())" + } + exit 1 + } +} + +Write-Host "1) Health check" +Invoke-Json -Method GET -Path "/health" | Out-Host + +Write-Host "`n2) Admin reset" +Invoke-Json -Method POST -Path "/api/admin/reset" -Headers @{ "X-Admin-Key" = $AdminKey } | Out-Host + +Write-Host "`n3) Set player name" +$me = Invoke-Json -Method POST -Path "/api/me/name" -Body @{ name = "SmokeTester" } +$me | Out-Host + +Write-Host "`n4) Submit three suggestions" +$ids = @() +1..3 | ForEach-Object { + $resp = Invoke-Json -Method POST -Path "/api/suggestions" -Body @{ + name = "Game $_" + genre = "Genre $_" + description = "Autogenerated suggestion $_" + } + $ids += $resp.id + $resp | Out-Host +} + +Write-Host "`n5) Reveal phase" +Invoke-Json -Method POST -Path "/api/admin/phase" -Headers @{ "X-Admin-Key" = $AdminKey } -Body @{ phase = "Reveal" } | Out-Host +Invoke-Json -Method GET -Path "/api/suggestions/all" | Out-Host + +Write-Host "`n6) Vote phase" +Invoke-Json -Method POST -Path "/api/admin/phase" -Headers @{ "X-Admin-Key" = $AdminKey } -Body @{ phase = "Vote" } | Out-Host +Invoke-Json -Method POST -Path "/api/votes" -Body @{ suggestionId = $ids[0]; score = 10 } | Out-Host +Invoke-Json -Method POST -Path "/api/votes" -Body @{ suggestionId = $ids[1]; score = 7 } | Out-Host +Invoke-Json -Method POST -Path "/api/votes" -Body @{ suggestionId = $ids[2]; score = 5 } | Out-Host + +Write-Host "`n7) Results phase" +Invoke-Json -Method POST -Path "/api/admin/phase" -Headers @{ "X-Admin-Key" = $AdminKey } -Body @{ phase = "Results" } | Out-Host +Invoke-Json -Method GET -Path "/api/results" | Out-Host + +Write-Host "`nSmoke test completed."