0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-03-31 22:51:25 -05:00

fix(connector): fix kook connector fail with empty banner (#7006)

This commit is contained in:
Misaka_L 2025-02-11 10:17:59 +08:00 committed by GitHub
parent 99bd856acc
commit dd8cd13c1f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 56 additions and 6 deletions

View file

@ -0,0 +1,5 @@
---
"@logto/connector-kook": patch
---
fix kook connector fail with empty banner in user information endpoint response

View file

@ -96,8 +96,8 @@ describe('Kook connector', () => {
online: false,
os: 'Websocket',
status: 0,
avatar: 'https://xxx.com/assets/bot.png/icon',
banner: 'https://xxx.com/assets/banner.png',
avatar: 'https://img.kookapp.cn/assets/bot.png/icon',
banner: 'https://img.kookapp.cn/assets/banner.png',
bot: false,
mobile_verified: true,
mobile_prefix: '86',
@ -116,13 +116,58 @@ describe('Kook connector', () => {
expect(socialUserInfo).toStrictEqual({
id: '364862',
name: 'test',
avatar: 'https://xxx.com/assets/bot.png/icon',
avatar: 'https://img.kookapp.cn/assets/bot.png/icon',
rawData: {
id: '364862',
username: 'test',
identify_num: '1670',
avatar: 'https://xxx.com/assets/bot.png/icon',
banner: 'https://xxx.com/assets/banner.png',
avatar: 'https://img.kookapp.cn/assets/bot.png/icon',
banner: 'https://img.kookapp.cn/assets/banner.png',
mobile_verified: true,
},
});
});
it('should get valid SocialUserInfo when user have not banner', async () => {
nock(userInfoEndpoint)
.get('')
.reply(200, {
code: 0,
message: '操作成功',
data: {
id: '364862',
username: 'test',
identify_num: '1670',
online: false,
os: 'Websocket',
status: 0,
avatar: 'https://img.kookapp.cn/assets/bot.png/icon',
banner: '',
bot: false,
mobile_verified: true,
mobile_prefix: '86',
mobile: '110****2333',
invited_count: 0,
},
});
const connector = await createConnector({ getConfig });
const socialUserInfo = await connector.getUserInfo(
{
code: 'code',
redirectUri: 'dummyRedirectUri',
},
vi.fn()
);
expect(socialUserInfo).toStrictEqual({
id: '364862',
name: 'test',
avatar: 'https://img.kookapp.cn/assets/bot.png/icon',
rawData: {
id: '364862',
username: 'test',
identify_num: '1670',
avatar: 'https://img.kookapp.cn/assets/bot.png/icon',
banner: '',
mobile_verified: true,
},
});

View file

@ -25,7 +25,7 @@ export const userInfoResponseGuard = z.object({
username: z.string(),
identify_num: z.string(),
avatar: z.string().url(),
banner: z.string().url(),
banner: z.union([z.string().url().nullish(), z.literal('')]),
mobile_verified: z.boolean(),
}),
});