const axios = require('axios');
|
|
const BASE_URL = 'http://localhost:8080/api';
|
|
async function testPhoneDisplay() {
|
console.log('=== 测试电话号码回显功能 ===\n');
|
|
try {
|
// 1. 先登录获取token
|
console.log('1. 登录获取token...');
|
const loginResponse = await axios.post(`${BASE_URL}/auth/web-login`, {
|
phone: '13981970816',
|
password: '123456'
|
});
|
|
if (!loginResponse.data.token) {
|
console.log('❌ 登录失败,无法获取token');
|
return;
|
}
|
|
const token = loginResponse.data.token;
|
const userInfo = loginResponse.data.userInfo;
|
|
console.log('✅ 登录成功');
|
console.log('- Token获取成功');
|
console.log('- 登录返回的用户信息:');
|
console.log(' - 用户ID:', userInfo.userId);
|
console.log(' - 姓名:', userInfo.name);
|
console.log(' - 电话:', userInfo.phone);
|
console.log(' - 用户类型:', userInfo.userType);
|
|
// 2. 保存用户信息
|
console.log('\n2. 保存用户信息...');
|
const saveUserResponse = await axios.post(`${BASE_URL}/graphql`, {
|
query: `
|
mutation SaveUserInfo($input: SaveUserInfoInput!) {
|
saveUserInfo(input: $input) {
|
success
|
message
|
user {
|
id
|
name
|
phone
|
gender
|
birthday
|
}
|
}
|
}
|
`,
|
variables: {
|
input: {
|
name: '测试用户电话回显',
|
phone: '13981970816',
|
gender: 'MALE',
|
birthday: '1990-01-01'
|
}
|
}
|
}, {
|
headers: {
|
'Authorization': `Bearer ${token}`,
|
'Content-Type': 'application/json'
|
}
|
});
|
|
if (saveUserResponse.data.data?.saveUserInfo?.success) {
|
console.log('✅ 保存用户信息成功');
|
const savedUser = saveUserResponse.data.data.saveUserInfo.user;
|
console.log('- 保存后的用户信息:');
|
console.log(' - 用户ID:', savedUser.id);
|
console.log(' - 姓名:', savedUser.name);
|
console.log(' - 电话:', savedUser.phone);
|
console.log(' - 性别:', savedUser.gender);
|
console.log(' - 生日:', savedUser.birthday);
|
} else {
|
console.log('❌ 保存用户信息失败');
|
console.log('错误:', saveUserResponse.data.errors || saveUserResponse.data.data?.saveUserInfo?.message);
|
return;
|
}
|
|
// 3. 查询用户档案验证电话号码回显
|
console.log('\n3. 查询用户档案验证电话号码回显...');
|
const userProfileResponse = await axios.post(`${BASE_URL}/graphql`, {
|
query: `
|
query {
|
userProfile {
|
id
|
name
|
phone
|
gender
|
birthday
|
roles
|
userType
|
employee {
|
id
|
name
|
roleId
|
description
|
}
|
judge {
|
id
|
name
|
title
|
company
|
description
|
}
|
player {
|
id
|
name
|
phone
|
description
|
}
|
}
|
}
|
`
|
}, {
|
headers: {
|
'Authorization': `Bearer ${token}`,
|
'Content-Type': 'application/json'
|
}
|
});
|
|
if (userProfileResponse.data.data?.userProfile) {
|
console.log('✅ 查询用户档案成功');
|
const profile = userProfileResponse.data.data.userProfile;
|
console.log('- 用户档案信息:');
|
console.log(' - 用户ID:', profile.id);
|
console.log(' - 姓名:', profile.name);
|
console.log(' - 电话:', profile.phone);
|
console.log(' - 性别:', profile.gender);
|
console.log(' - 生日:', profile.birthday);
|
console.log(' - 角色:', profile.roles);
|
console.log(' - 用户类型:', profile.userType);
|
|
// 验证电话号码是否正确回显
|
if (profile.phone === '13981970816') {
|
console.log('✅ 电话号码回显正确: ' + profile.phone);
|
} else {
|
console.log('❌ 电话号码回显错误,期望: 13981970816,实际: ' + profile.phone);
|
}
|
|
// 验证姓名是否正确回显
|
if (profile.name === '测试用户电话回显') {
|
console.log('✅ 姓名回显正确: ' + profile.name);
|
} else {
|
console.log('❌ 姓名回显错误,期望: 测试用户电话回显,实际: ' + profile.name);
|
}
|
} else {
|
console.log('❌ 查询用户档案失败');
|
console.log('错误:', userProfileResponse.data.errors);
|
}
|
|
// 4. 重新登录验证电话号码回显
|
console.log('\n4. 重新登录验证电话号码回显...');
|
const reLoginResponse = await axios.post(`${BASE_URL}/auth/web-login`, {
|
phone: '13981970816',
|
password: '123456'
|
});
|
|
if (reLoginResponse.data.token) {
|
console.log('✅ 重新登录成功');
|
const reLoginUserInfo = reLoginResponse.data.userInfo;
|
console.log('- 重新登录返回的用户信息:');
|
console.log(' - 用户ID:', reLoginUserInfo.userId);
|
console.log(' - 姓名:', reLoginUserInfo.name);
|
console.log(' - 电话:', reLoginUserInfo.phone);
|
console.log(' - 用户类型:', reLoginUserInfo.userType);
|
|
// 验证重新登录后电话号码是否正确回显
|
if (reLoginUserInfo.phone === '13981970816') {
|
console.log('✅ 重新登录后电话号码回显正确: ' + reLoginUserInfo.phone);
|
} else {
|
console.log('❌ 重新登录后电话号码回显错误,期望: 13981970816,实际: ' + reLoginUserInfo.phone);
|
}
|
|
// 验证重新登录后姓名是否正确回显
|
if (reLoginUserInfo.name === '测试用户电话回显') {
|
console.log('✅ 重新登录后姓名回显正确: ' + reLoginUserInfo.name);
|
} else {
|
console.log('❌ 重新登录后姓名回显错误,期望: 测试用户电话回显,实际: ' + reLoginUserInfo.name);
|
}
|
} else {
|
console.log('❌ 重新登录失败');
|
console.log('错误:', reLoginResponse.data);
|
}
|
|
console.log('\n=== 测试完成 ===');
|
|
} catch (error) {
|
console.error('❌ 测试过程中发生错误:', error.response?.data || error.message);
|
}
|
}
|
|
// 运行测试
|
testPhoneDisplay();
|