const axios = require('axios');
|
|
// 使用与成功测试相同的配置
|
const BASE_URL = 'http://localhost:8080/api/graphql';
|
|
async function testSaveUserInfoWithoutPhone() {
|
console.log('测试保存没有电话号码的用户信息...');
|
|
// 使用有效的token(从之前的成功测试中获取)
|
const token = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiItODMzNDg4IiwicGhvbmUiOiJvZ3h4QTEtS3JTVlRkcUk5VDF1YUIxQlF3UEdVIiwiaWF0IjoxNzU5ODQwNDc2LCJleHAiOjE3NTk5MjY4NzZ9.vyGAs6TWqgHN1KRAJbTp7xMdRSh0CIy7rrbE6TqS6i0';
|
console.log('使用Token:', token.substring(0, 50) + '...');
|
|
// 测试保存没有电话号码的用户信息
|
const mutation = `
|
mutation {
|
saveUserInfo(input: {
|
name: "测试用户无电话"
|
avatar: "https://example.com/avatar.jpg"
|
gender: "male"
|
birthday: "1990-01-01"
|
}) {
|
id
|
name
|
phone
|
avatar
|
gender
|
birthday
|
}
|
}`;
|
|
const requestData = {
|
query: mutation
|
};
|
|
console.log('发送GraphQL请求测试saveUserInfo(无电话号码)...');
|
console.log('请求数据:', JSON.stringify(requestData));
|
|
try {
|
const response = await axios.post(BASE_URL, requestData, {
|
headers: {
|
'Content-Type': 'application/json',
|
'Authorization': `Bearer ${token}`
|
}
|
});
|
|
console.log('响应状态码:', response.status);
|
console.log('响应内容:', JSON.stringify(response.data));
|
|
if (response.data.errors) {
|
console.log('✅ 预期的错误:', response.data.errors);
|
} else if (response.data.data && response.data.data.saveUserInfo) {
|
console.log('❌ 意外成功: 应该拒绝没有电话号码的保存请求');
|
console.log('保存的用户信息:', response.data.data.saveUserInfo);
|
}
|
} catch (error) {
|
console.log('请求失败:', error.response?.data || error.message);
|
if (error.response?.data?.errors) {
|
console.log('✅ 预期的错误:', error.response.data.errors);
|
}
|
}
|
}
|
|
testSaveUserInfoWithoutPhone();
|