From b8b59108a64b279f5519b871919d6df03db02b6c Mon Sep 17 00:00:00 2001 From: Gregor Martynus Date: Fri, 8 Nov 2019 14:26:58 -0800 Subject: [PATCH] test: auth.hook() uses app auth for "https://api.github.com/app/installations" --- test/index.test.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/index.test.ts b/test/index.test.ts index 55df1b4ac..568190dd5 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -1050,6 +1050,41 @@ test("auth.hook() creates token and uses it for succeeding requests", async () = expect(mock.done()).toBe(true); }); +test("auth.hook() uses app auth for full URLs", async () => { + const mock = fetchMock + .sandbox() + .getOnce("https://api.github.com/app/installations?per_page=100", [], { + headers: { + authorization: `bearer ${BEARER}` + } + }); + + const auth = createAppAuth({ + id: APP_ID, + privateKey: PRIVATE_KEY + }); + + const requestWithMock = request.defaults({ + headers: { + "user-agent": "test" + }, + request: { + fetch: mock + } + }); + const requestWithAuth = requestWithMock.defaults({ + request: { + hook: auth.hook + } + }); + + await requestWithAuth("GET https://api.github.com/app/installations", { + per_page: 100 + }); + + expect(mock.done()).toBe(true); +}); + test("oauth endpoint error", async () => { const requestMock = request.defaults({ headers: {