0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

chore: add tests

This commit is contained in:
Gao Sun 2024-06-16 21:13:00 +08:00
parent 6308ee1857
commit c0617f159d
No known key found for this signature in database
GPG key ID: 13EBE123E4773688

View file

@ -8,6 +8,25 @@ import { mockedConfig } from './mock.js';
const getConfig = vi.fn().mockResolvedValue(mockedConfig);
vi.mock('jose', () => ({
createRemoteJWKSet: vi.fn().mockReturnValue({
getSigningKey: vi.fn().mockResolvedValue({
publicKey: 'publicKey',
}),
}),
jwtVerify: vi.fn().mockResolvedValue({
payload: {
sub: '1234567890',
name: 'John Wick',
given_name: 'John',
family_name: 'Wick',
email: 'john@silverhand.io',
email_verified: true,
picture: 'https://example.com/image.jpg',
},
}),
}));
describe('google connector', () => {
describe('getAuthorizationUri', () => {
afterEach(() => {
@ -105,6 +124,31 @@ describe('google connector', () => {
});
});
it('should be able to decode ID token from Google One Tap', async () => {
const connector = await createConnector({ getConfig });
const socialUserInfo = await connector.getUserInfo(
{
credential: 'credential',
},
vi.fn()
);
expect(socialUserInfo).toStrictEqual({
id: '1234567890',
avatar: 'https://example.com/image.jpg',
name: 'John Wick',
email: 'john@silverhand.io',
rawData: {
sub: '1234567890',
name: 'John Wick',
given_name: 'John',
family_name: 'Wick',
email: 'john@silverhand.io',
email_verified: true,
picture: 'https://example.com/image.jpg',
},
});
});
it('throws SocialAccessTokenInvalid error if remote response code is 401', async () => {
nock(userInfoEndpoint).post('').reply(401);
const connector = await createConnector({ getConfig });