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);
|