From 77541925888adaaff88fceb022cd5625db1c5eee Mon Sep 17 00:00:00 2001 From: Francisco Giordano Date: Sat, 2 Nov 2019 21:53:02 -0300 Subject: [PATCH] add test for oauth endpoint error --- test/index.test.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/index.test.ts b/test/index.test.ts index 433f3af3e..86b02b96c 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -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'); +});