This commit is contained in:
2026-04-29 20:56:59 +08:00
parent fb6f455530
commit 730f485f48
200 changed files with 9881 additions and 2221 deletions

View File

@@ -26,14 +26,15 @@ import {
getAuthLoginOptions,
getAuthRiskBlocks,
getAuthSessions,
getPublicAuthUserById,
getCaptchaChallengeFromError,
getCurrentAuthUser,
getPublicAuthUserById,
liftAuthRiskBlock,
loginWithPhoneCode,
logoutAllAuthSessions,
sendPhoneLoginCode,
startWechatLogin,
updateAuthProfile,
} from './authService';
function createLocalStorageMock() {
@@ -87,6 +88,7 @@ describe('authService', () => {
publicUserCode: 'SY-00000001',
username: 'phone_00000001',
displayName: '138****8000',
avatarUrl: null,
phoneNumberMasked: '138****8000',
loginMethod: 'password',
bindingStatus: 'active',
@@ -115,6 +117,40 @@ describe('authService', () => {
expect(window.dispatchEvent).not.toHaveBeenCalled();
});
it('update profile trims nickname and posts avatar data url', async () => {
apiClientMocks.requestJson.mockResolvedValue({
user: {
id: 'user_1',
publicUserCode: 'SY-00000001',
username: 'phone_00000001',
displayName: '旅人甲',
avatarUrl: 'data:image/png;base64,AAAA',
phoneNumberMasked: '138****8000',
loginMethod: 'password',
bindingStatus: 'active',
wechatBound: false,
},
});
const user = await updateAuthProfile({
displayName: ' 旅人甲 ',
avatarDataUrl: ' data:image/png;base64,AAAA ',
});
expect(user.avatarUrl).toBe('data:image/png;base64,AAAA');
expect(apiClientMocks.requestJson).toHaveBeenCalledWith(
'/api/profile/me',
expect.objectContaining({
method: 'PATCH',
body: JSON.stringify({
displayName: '旅人甲',
avatarDataUrl: 'data:image/png;base64,AAAA',
}),
}),
'更新资料失败',
);
});
it('sends phone login code through the auth endpoint', async () => {
apiClientMocks.requestJson.mockResolvedValue({
ok: true,
@@ -175,6 +211,7 @@ describe('authService', () => {
publicUserCode: 'SY-00000004',
username: '138****8000',
displayName: '138****8000',
avatarUrl: null,
phoneNumberMasked: '138****8000',
loginMethod: 'phone',
bindingStatus: 'active',
@@ -211,6 +248,7 @@ describe('authService', () => {
publicUserCode: 'SY-00000005',
username: '138****8000',
displayName: '138****8000',
avatarUrl: null,
phoneNumberMasked: '138****8000',
loginMethod: 'wechat',
bindingStatus: 'active',
@@ -232,6 +270,7 @@ describe('authService', () => {
publicUserCode: 'SY-00000006',
username: '139****9000',
displayName: '139****9000',
avatarUrl: null,
phoneNumberMasked: '139****9000',
loginMethod: 'phone',
bindingStatus: 'active',