Codex Assistant
17 小时以前 58d9f460b2f8c34430285115e2557d18333c5cab
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
const axios = require('axios');
 
const BASE_URL = 'http://localhost:8080/api';
 
// 测试用的token(用户ID=152, 评委ID=72)
let TEST_TOKEN = 'your_actual_token_here';
 
async function getValidToken() {
    try {
        console.log('尝试使用微信登录code获取token...');
        
        const wxLoginMutation = `
            mutation WxLogin($input: WxLoginRequest!) {
                wxLogin(input: $input) {
                    token
                    userInfo {
                        userId
                        name
                        phone
                        userType
                    }
                }
            }
        `;
 
        const loginResponse = await axios.post('http://localhost:8080/api/graphql', {
            query: wxLoginMutation,
            variables: {
                input: {
                    code: '0e3xj8000AMc6V11gY200KTotq3xj80L'
                }
            }
        }, {
            headers: {
                'Content-Type': 'application/json'
            }
        });
 
        if (loginResponse.data?.data?.wxLogin?.token) {
            const token = loginResponse.data.data.wxLogin.token;
            const user = loginResponse.data.data.wxLogin.userInfo;
            TEST_TOKEN = token;
            console.log('✓ 微信登录成功');
            console.log('用户信息:', user);
            console.log('Token:', token.substring(0, 20) + '...');
            return true;
        } else {
            console.log('✗ 微信登录失败:', loginResponse.data);
            return false;
        }
    } catch (error) {
        console.log('✗ 微信登录失败:', error.response?.data || error.message);
        return false;
    }
}
 
async function testReviewQueries() {
    console.log('开始测试评审相关的GraphQL查询...\n');
 
    // 先获取有效token
    const tokenObtained = await getValidToken();
    if (!tokenObtained) {
        console.log('无法获取有效token,测试终止');
        return;
    }
 
    const headers = {
        'Content-Type': 'application/json',
        'Authorization': `Bearer ${TEST_TOKEN}`
    };
 
    // 测试1: 获取未评审项目
    console.log('1. 测试获取未评审项目...');
    try {
        const unReviewedQuery = {
            query: `
                query GetUnReviewedProjects {
                    unReviewedProjects(page: 1, pageSize: 10) {
                        items {
                            id
                            projectName
                            activityName
                            stageName
                            studentName
                            submitTime
                            status
                        }
                        total
                        hasMore
                    }
                }
            `
        };
 
        const response1 = await axios.post(`${BASE_URL}/graphql`, unReviewedQuery, { headers });
        console.log('✓ 未评审项目查询成功');
        console.log('返回数据:', JSON.stringify(response1.data, null, 2));
    } catch (error) {
        console.log('✗ 未评审项目查询失败');
        console.log('错误信息:', error.response?.data || error.message);
    }
 
    console.log('\n');
 
    // 测试2: 获取已评审项目
    console.log('2. 测试获取已评审项目...');
    try {
        const reviewedQuery = {
            query: `
                query GetReviewedProjects {
                    reviewedProjects(page: 1, pageSize: 10) {
                        items {
                            id
                            projectName
                            activityName
                            stageName
                            studentName
                            submitTime
                            reviewTime
                            score
                            status
                        }
                        total
                        hasMore
                    }
                }
            `
        };
 
        const response2 = await axios.post(`${BASE_URL}/graphql`, reviewedQuery, { headers });
        console.log('✓ 已评审项目查询成功');
        console.log('返回数据:', JSON.stringify(response2.data, null, 2));
    } catch (error) {
        console.log('✗ 已评审项目查询失败');
        console.log('错误信息:', error.response?.data || error.message);
    }
 
    console.log('\n');
 
    // 测试3: 获取学员未评审项目
    console.log('3. 测试获取学员未评审项目...');
    try {
        const studentUnReviewedQuery = {
            query: `
                query GetStudentUnReviewedProjects {
                    studentUnReviewedProjects(page: 1, pageSize: 10) {
                        items {
                            id
                            projectName
                            activityName
                            stageName
                            studentName
                            submitTime
                            status
                        }
                        total
                        hasMore
                    }
                }
            `
        };
 
        const response3 = await axios.post(`${BASE_URL}/graphql`, studentUnReviewedQuery, { headers });
        console.log('✓ 学员未评审项目查询成功');
        console.log('返回数据:', JSON.stringify(response3.data, null, 2));
    } catch (error) {
        console.log('✗ 学员未评审项目查询失败');
        console.log('错误信息:', error.response?.data || error.message);
    }
 
    console.log('\n');
 
    // 测试4: 获取评审统计
    console.log('4. 测试获取评审统计...');
    try {
        const statisticsQuery = {
            query: `
                query GetReviewStatistics {
                    reviewStatistics {
                        unReviewedCount
                        reviewedCount
                        studentUnReviewedCount
                    }
                }
            `
        };
 
        const response4 = await axios.post(`${BASE_URL}/graphql`, statisticsQuery, { headers });
        console.log('✓ 评审统计查询成功');
        console.log('返回数据:', JSON.stringify(response4.data, null, 2));
    } catch (error) {
        console.log('✗ 评审统计查询失败');
        console.log('错误信息:', error.response?.data || error.message);
    }
 
    console.log('\n');
 
    // 测试5: 验证当前用户评委身份
    console.log('5. 测试验证当前用户评委身份...');
    try {
        const userProfileQuery = {
            query: `
                query GetUserProfile {
                    userProfile {
                        id
                        name
                        phone
                        userType
                        roles
                        judge {
                            id
                            name
                            title
                            company
                        }
                        player {
                            id
                            name
                            phone
                        }
                    }
                }
            `
        };
 
        const response5 = await axios.post(`${BASE_URL}/graphql`, userProfileQuery, { headers });
        console.log('✓ 用户档案查询成功');
        console.log('返回数据:', JSON.stringify(response5.data, null, 2));
        
        const userType = response5.data?.data?.userProfile?.userType;
        if (userType && userType.includes('评委')) {
            console.log('✓ 确认用户具有评委身份');
        } else {
            console.log('⚠ 用户可能不具有评委身份,userType:', userType);
        }
    } catch (error) {
        console.log('✗ 用户档案查询失败');
        console.log('错误信息:', error.response?.data || error.message);
    }
 
    console.log('\n测试完成!');
}
 
// 运行测试
testReviewQueries().catch(console.error);