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
[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
    }
}