diff --git a/__tests__/lhisp-oauth-client.test.ts b/__tests__/lhisp-oauth-client.test.ts index 4a1434b..487fbce 100644 --- a/__tests__/lhisp-oauth-client.test.ts +++ b/__tests__/lhisp-oauth-client.test.ts @@ -13,7 +13,8 @@ const clientSecret = "testClientSecret"; const baseClientParams = { apiUrl, authUrl, clientId, clientSecret }; const basicAuth = `Basic ${Buffer.from(`${clientId}:${clientSecret}`).toString('base64')}`; const contentTypeApplicationJson = "application/json"; -const defaultGrantType='{"grant_type":"client_credentials"}'; +const defaultGrantValue='client_credentials'; +const defaultGrantType=`{"grant_type":"${defaultGrantValue}"}`; describe("lhisp-oauth-client", ()=>{ it("Shoud Get Access Token with Standard Config", async ()=>{ @@ -99,6 +100,35 @@ describe("lhisp-oauth-client", ()=>{ data: '{"grant_type":"PermissaoCustom"}', })); }); + + it("Shoud Get Access Token with Auth Scope", async ()=>{ + const cli = getOauthClient({ + ...baseClientParams, + authScope: 'EscopoCustom', + }); + mockedAxios.request.mockReset(); + mockedAxios.request.mockResolvedValueOnce({ + data: mockedAccessToken + }); + + const now = Date.now(); + const accessToken = await cli.getAccessToken(); + expect(accessToken).toBeDefined(); + expect(accessToken.token_type).toBe(mockedAccessToken.token_type); + expect(accessToken.access_token).toBe(mockedAccessToken.access_token); + expect(accessToken.expires_in).toBe(mockedAccessToken.expires_in); + expect(accessToken.scope).toBe(mockedAccessToken.scope); + expect(accessToken.created_at).toBeGreaterThanOrEqual(now); + expect(mockedAxios.request).toBeCalledWith(expect.objectContaining({ + url: authUrl, + method: "POST", + headers: { + Authorization: basicAuth, + 'Content-Type': contentTypeApplicationJson, + }, + data: `{"grant_type":"${defaultGrantValue}","scope":"EscopoCustom"}`, + })); + }); }); function getOauthClient(opt:LhispOauthClientConstructorParams=baseClientParams){