$headers = @{
|
"Content-Type" = "application/json"
|
}
|
|
Write-Host "=== 完整比赛管理测试流程 ==="
|
|
# 测试1: 创建比赛和阶段
|
Write-Host "1. 创建比赛和阶段..."
|
$body1 = @{
|
query = 'mutation {
|
saveActivity(input: {
|
name: "编程大赛2024",
|
description: "年度编程竞赛",
|
signupDeadline: "2024-12-31T23:59:59",
|
ratingSchemeId: 1,
|
pid: 0,
|
stages: [
|
{
|
name: "初赛",
|
description: "编程基础测试",
|
matchTime: "2024-11-01T09:00:00",
|
ratingSchemeId: 1,
|
playerMax: 100
|
},
|
{
|
name: "决赛",
|
description: "高级编程挑战",
|
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 "创建结果:"
|
$response1 | ConvertTo-Json -Depth 10
|
|
if ($response1.data -and $response1.data.saveActivity) {
|
$competitionId = $response1.data.saveActivity.id
|
$stages = $response1.data.saveActivity.stages
|
Write-Host "比赛创建成功,ID: $competitionId"
|
Write-Host "阶段数量: $($stages.Count)"
|
|
if ($stages.Count -gt 0) {
|
$stage1Id = $stages[0].id
|
$stage2Id = if ($stages.Count -gt 1) { $stages[1].id } else { $stages[0].id }
|
|
# 测试2: 添加评委到比赛
|
Write-Host "`n2. 添加评委到比赛..."
|
$body2 = @{
|
query = "mutation {
|
saveActivity(input: {
|
id: $competitionId,
|
name: `"编程大赛2024`",
|
description: `"年度编程竞赛`",
|
signupDeadline: `"2024-12-31T23:59:59`",
|
ratingSchemeId: 1,
|
pid: 0,
|
judges: [
|
{
|
judgeId: 1,
|
judgeName: `"张教授`",
|
stageIds: [$stage1Id, $stage2Id]
|
},
|
{
|
judgeId: 2,
|
judgeName: `"李专家`",
|
stageIds: [$stage2Id]
|
}
|
]
|
}) {
|
id name description
|
}
|
}"
|
} | ConvertTo-Json -Depth 10
|
|
$response2 = Invoke-RestMethod -Uri "http://localhost:8080/api/graphql" -Method POST -Body $body2 -Headers $headers
|
Write-Host "添加评委结果:"
|
$response2 | ConvertTo-Json -Depth 10
|
|
# 测试3: 读取完整比赛信息
|
Write-Host "`n3. 读取完整比赛信息..."
|
$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 "读取结果:"
|
$response3 | ConvertTo-Json -Depth 10
|
|
# 测试4: 修改比赛信息
|
Write-Host "`n4. 修改比赛信息..."
|
$body4 = @{
|
query = "mutation {
|
saveActivity(input: {
|
id: $competitionId,
|
name: `"编程大赛2024 (已更新)`",
|
description: `"年度编程竞赛 - 更新版`",
|
signupDeadline: `"2024-12-31T23:59:59`",
|
ratingSchemeId: 1,
|
pid: 0,
|
stages: [
|
{
|
id: $stage1Id,
|
name: `"初赛 (更新)`",
|
description: `"编程基础测试 - 更新版`",
|
matchTime: `"2024-11-01T09:00:00`",
|
ratingSchemeId: 1,
|
playerMax: 150
|
},
|
{
|
id: $stage2Id,
|
name: `"决赛`",
|
description: `"高级编程挑战`",
|
matchTime: `"2024-11-15T09:00:00`",
|
ratingSchemeId: 1,
|
playerMax: 20
|
},
|
{
|
name: `"加赛`",
|
description: `"额外挑战赛`",
|
matchTime: `"2024-11-20T09:00:00`",
|
ratingSchemeId: 1,
|
playerMax: 10
|
}
|
]
|
}) {
|
id name description
|
stages { id name description playerMax }
|
}
|
}"
|
} | ConvertTo-Json -Depth 10
|
|
$response4 = Invoke-RestMethod -Uri "http://localhost:8080/api/graphql" -Method POST -Body $body4 -Headers $headers
|
Write-Host "修改结果:"
|
$response4 | ConvertTo-Json -Depth 10
|
|
Write-Host "`n=== 测试完成 ==="
|
Write-Host "✓ 比赛创建成功"
|
Write-Host "✓ 阶段创建成功"
|
Write-Host "✓ 评委添加成功"
|
Write-Host "✓ 数据读取成功"
|
Write-Host "✓ 数据修改成功"
|
}
|
} else {
|
Write-Host "比赛创建失败"
|
if ($response1.errors) {
|
Write-Host "错误信息:"
|
$response1.errors | ConvertTo-Json -Depth 10
|
}
|
}
|