[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
|
$headers = @{
|
"Content-Type" = "application/json"
|
}
|
|
Write-Host "=== Complete Competition Test ==="
|
|
# Test 1: Create competition with stages
|
Write-Host "1. Creating competition with stages..."
|
$body1 = @{
|
query = 'mutation {
|
saveActivity(input: {
|
name: "Programming Contest 2024",
|
description: "Annual programming competition",
|
signupDeadline: "2024-12-31T23:59:59",
|
ratingSchemeId: 1,
|
pid: 0,
|
stages: [
|
{
|
name: "Preliminary",
|
description: "Basic programming test",
|
matchTime: "2024-11-01T09:00:00",
|
ratingSchemeId: 1,
|
playerMax: 100
|
},
|
{
|
name: "Final",
|
description: "Advanced programming challenge",
|
matchTime: "2024-11-15T09:00:00",
|
ratingSchemeId: 1,
|
playerMax: 20
|
}
|
]
|
}) {
|
id name description pid
|
stages { id name description playerMax }
|
}
|
}'
|
} | ConvertTo-Json -Depth 10
|
|
$response1 = Invoke-RestMethod -Uri "http://localhost:8080/api/graphql" -Method POST -Body $body1 -Headers $headers
|
Write-Host "Creation result:"
|
$response1 | ConvertTo-Json -Depth 10
|
|
if ($response1.data -and $response1.data.saveActivity) {
|
$competitionId = $response1.data.saveActivity.id
|
$stages = $response1.data.saveActivity.stages
|
Write-Host "Competition created successfully, ID: $competitionId"
|
Write-Host "Number of stages: $($stages.Count)"
|
|
if ($stages.Count -gt 0) {
|
$stage1Id = $stages[0].id
|
$stage2Id = if ($stages.Count -gt 1) { $stages[1].id } else { $stages[0].id }
|
|
# Test 2: Add judges to competition
|
Write-Host "`n2. Adding judges to competition..."
|
$judgeQuery = @"
|
mutation {
|
saveActivity(input: {
|
id: $competitionId,
|
name: "Programming Contest 2024",
|
description: "Annual programming competition",
|
signupDeadline: "2024-12-31T23:59:59",
|
ratingSchemeId: 1,
|
pid: 0,
|
judges: [
|
{
|
judgeId: 1,
|
judgeName: "Professor Zhang",
|
stageIds: [$stage1Id, $stage2Id]
|
},
|
{
|
judgeId: 2,
|
judgeName: "Expert Li",
|
stageIds: [$stage2Id]
|
}
|
]
|
}) {
|
id name description
|
}
|
}
|
"@
|
|
$body2 = @{ query = $judgeQuery } | ConvertTo-Json -Depth 10
|
$response2 = Invoke-RestMethod -Uri "http://localhost:8080/api/graphql" -Method POST -Body $body2 -Headers $headers
|
Write-Host "Judge addition result:"
|
$response2 | ConvertTo-Json -Depth 10
|
|
# Test 3: Read complete competition info
|
Write-Host "`n3. Reading complete competition info..."
|
$body3 = @{
|
query = "query {
|
activity(id: $competitionId) {
|
id name description pid
|
stages { id name description playerMax }
|
}
|
}"
|
} | ConvertTo-Json
|
|
$response3 = Invoke-RestMethod -Uri "http://localhost:8080/api/graphql" -Method POST -Body $body3 -Headers $headers
|
Write-Host "Read result:"
|
$response3 | ConvertTo-Json -Depth 10
|
|
Write-Host "`n=== Test Complete ==="
|
Write-Host "✓ Competition creation successful"
|
Write-Host "✓ Stage creation successful"
|
Write-Host "✓ Judge addition successful"
|
Write-Host "✓ Data reading successful"
|
}
|
} else {
|
Write-Host "Competition creation failed"
|
if ($response1.errors) {
|
Write-Host "Error details:"
|
$response1.errors | ConvertTo-Json -Depth 10
|
}
|
}
|