lrj
3 天以前 6d519474e44855682043d3c40db2c86a6822caca
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
$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
    }
}