0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-01-27 21:39:16 -05:00

fix(core): fix did not mock request error which results in timeouts (#471)

This commit is contained in:
Darcy Ye 2022-03-30 18:31:42 +08:00 committed by GitHub
parent 0444efd844
commit 84f30fe04b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -97,8 +97,11 @@ describe('getUserInfo', () => {
});
});
it('throws SocialAccessTokenInvalid error if remote response code is 40001', async () => {
nock(userInfoEndpointUrl.origin).get(userInfoEndpointUrl.pathname).query(parameters).reply(401);
it('throws SocialAccessTokenInvalid error if errcode is 40001', async () => {
nock(userInfoEndpointUrl.origin)
.get(userInfoEndpointUrl.pathname)
.query(parameters)
.reply(200, { errcode: 40_001 });
await expect(
getUserInfo({ accessToken: 'accessToken', openid: 'openid' })
).rejects.toMatchError(new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid));
@ -119,7 +122,11 @@ describe('getUserInfo', () => {
).rejects.toMatchError(new Error('invalid openid'));
});
it('throws SocialAccessTokenInvalid error if openid is missing', async () => {
it('throws SocialAccessTokenInvalid error if response code is 401', async () => {
nock(userInfoEndpointUrl.origin)
.get(userInfoEndpointUrl.pathname)
.query(new URLSearchParams({ access_token: 'accessToken' }))
.reply(401);
await expect(getUserInfo({ accessToken: 'accessToken' })).rejects.toMatchError(
new ConnectorError(ConnectorErrorCodes.SocialAccessTokenInvalid)
);