const axios = require('axios');
|
|
// 测试小程序活动详情获取
|
async function testActivityDetail() {
|
console.log('=== 测试小程序活动详情获取 ===\n');
|
|
const baseUrl = 'http://localhost:8080/api/graphql';
|
const activityId = 1; // 假设活动ID为1
|
|
// 测试1: 不提供token的情况
|
console.log('1. 测试活动详情查询 - 无token');
|
try {
|
const response = await axios.post(baseUrl, {
|
query: `
|
query GetActivityDetailAndStatus($id: ID!) {
|
activity(id: $id) {
|
id
|
name
|
description
|
signupDeadline
|
matchTime
|
address
|
state
|
stateName
|
playerCount
|
playerMax
|
}
|
myActivityPlayer(activityId: $id) {
|
id
|
state
|
}
|
}
|
`,
|
variables: { id: activityId }
|
}, {
|
headers: {
|
'Content-Type': 'application/json'
|
}
|
});
|
|
console.log('✅ 查询成功');
|
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
} catch (error) {
|
console.log('❌ 查询失败');
|
console.log('状态码:', error.response?.status);
|
console.log('错误信息:', error.response?.data || error.message);
|
}
|
|
console.log('\n' + '='.repeat(50) + '\n');
|
|
// 测试2: 只查询公开的活动信息
|
console.log('2. 测试只查询公开活动信息');
|
try {
|
const response = await axios.post(baseUrl, {
|
query: `
|
query GetActivityDetail($id: ID!) {
|
activity(id: $id) {
|
id
|
name
|
description
|
signupDeadline
|
matchTime
|
address
|
state
|
stateName
|
playerCount
|
playerMax
|
}
|
}
|
`,
|
variables: { id: activityId }
|
}, {
|
headers: {
|
'Content-Type': 'application/json'
|
}
|
});
|
|
console.log('✅ 查询成功');
|
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
} catch (error) {
|
console.log('❌ 查询失败');
|
console.log('状态码:', error.response?.status);
|
console.log('错误信息:', error.response?.data || error.message);
|
}
|
|
console.log('\n' + '='.repeat(50) + '\n');
|
|
// 测试3: 使用有效token查询
|
console.log('3. 测试使用有效token查询');
|
const validToken = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiItODMzNDg4IiwicGhvbmUiOiJvZ3h4QTEtS3JTVlRkcUk5VDF1YUIxQlF3UEdVIiwiaWF0IjoxNzU5ODM3NjkwLCJleHAiOjE3NTk5MjQwOTB9.RjsrnxztC4o4E49Z-GsxDOuzsC-YBsS380hG8_WeZps'; // 从之前的测试获取
|
|
try {
|
const response = await axios.post(baseUrl, {
|
query: `
|
query GetActivityDetailAndStatus($id: ID!) {
|
activity(id: $id) {
|
id
|
name
|
description
|
signupDeadline
|
matchTime
|
address
|
state
|
stateName
|
playerCount
|
playerMax
|
}
|
myActivityPlayer(activityId: $id) {
|
id
|
state
|
}
|
}
|
`,
|
variables: { id: activityId }
|
}, {
|
headers: {
|
'Content-Type': 'application/json',
|
'Authorization': `Bearer ${validToken}`
|
}
|
});
|
|
console.log('✅ 查询成功');
|
console.log('响应数据:', JSON.stringify(response.data, null, 2));
|
} catch (error) {
|
console.log('❌ 查询失败');
|
console.log('状态码:', error.response?.status);
|
console.log('错误信息:', error.response?.data || error.message);
|
}
|
|
console.log('\n=== 测试完成 ===');
|
}
|
|
testActivityDetail().catch(console.error);
|