Skip to content

Commit

Permalink
add test for oauth endpoint error
Browse files Browse the repository at this point in the history
  • Loading branch information
frangio committed Nov 3, 2019
1 parent 59e368c commit 7754192
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1049,3 +1049,41 @@ test("auth.hook() creates token and uses it for succeeding requests", async () =

expect(mock.done()).toBe(true);
});


test("oauth endpoint error", async () => {
const requestMock = request.defaults({
headers: {
"user-agent": "test"
},
request: {
fetch: fetchMock.sandbox().post(
"https://github.com/login/oauth/access_token", {
status: 200,
body: JSON.stringify({
error: "incorrect_client_credentials",
error_description: "The client_id and/or client_secret passed are incorrect.",
}),
headers: {
"Content-Type": "application/json; charset=utf-8"
}
}),
},
});

const auth = createAppAuth({
id: APP_ID,
privateKey: PRIVATE_KEY,
clientId: "12345678901234567890",
clientSecret: "1234567890123456789012345678901234567890",
request: requestMock,
});

await expect(
auth({
type: 'oauth',
code: '12345678901234567890',
redirectUrl: 'https://example.com/login',
})
).rejects.toThrow('client_id');
});

0 comments on commit 7754192

Please sign in to comment.