0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-03 21:48:55 -05:00
logto/packages/connectors/connector-oauth2/src/utils.test.ts
Gao Sun 6b322a537c
refactor: add connector packages
the initial commit to move all connector packages to the main
repo.
2023-04-01 15:53:14 +08:00

51 lines
1.4 KiB
TypeScript

import type { ProfileMap, UserProfile } from './types.js';
import { userProfileMapping } from './utils.js';
describe('userProfileMapping', () => {
it('should return valid profile (`id` is string and `avatar` not correctly mapped)', () => {
const keyMapping: ProfileMap = {
id: 'id',
email: 'email',
phone: 'phone',
name: 'name',
avatar: 'avatar',
};
const originUserProfile = {
id: '123456',
email: 'octcat@github.com',
phone: null,
name: 'Oct Cat',
avatar_url: 'avatar.png',
};
const profile: UserProfile = userProfileMapping(originUserProfile, keyMapping);
expect(profile).toMatchObject({
id: '123456',
email: 'octcat@github.com',
name: 'Oct Cat',
});
});
it('should return valid profile (`id` is number and `avatar` correctly mapped)', () => {
const keyMapping: ProfileMap = {
id: 'id',
email: 'email',
phone: 'phone',
name: 'name',
avatar: 'avatar_url',
};
const originUserProfile = {
id: 123_456,
email: 'octcat@github.com',
phone: undefined,
name: 'Oct Cat',
avatar_url: 'avatar.png',
};
const profile: UserProfile = userProfileMapping(originUserProfile, keyMapping);
expect(profile).toMatchObject({
id: '123456',
email: 'octcat@github.com',
name: 'Oct Cat',
avatar: 'avatar.png',
});
});
});