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