From 2e908ee42b38c48f2cc188b2f9e59ab19d5d2e6f Mon Sep 17 00:00:00 2001 From: "Jason R. Stevens, CFA" Date: Fri, 18 Aug 2023 09:00:36 -0500 Subject: [PATCH 1/2] :white_check_mark: add coverage for promoApiUrl prop in getToken --- __tests__/getToken.test.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/__tests__/getToken.test.ts b/__tests__/getToken.test.ts index e49054d..d8ed286 100644 --- a/__tests__/getToken.test.ts +++ b/__tests__/getToken.test.ts @@ -14,8 +14,15 @@ describe('getToken', () => { clientSecret ); - it('returns a string', async () => { + it('returns a string using the default api route', async () => { let resultToken: string = await getToken(accessTokenSigned); expect(typeof resultToken).toBe('string'); }); + it('returns a string using a default api route', async () => { + let resultToken: string = await getToken( + accessTokenSigned, + 'https://feature.promo.api.tincre.dev' + ); + expect(typeof resultToken).toBe('string'); + }); }); From 4f531a21eb69f8bf13e2bf0657d12d0d3346d19a Mon Sep 17 00:00:00 2001 From: "Jason R. Stevens, CFA" Date: Fri, 18 Aug 2023 09:00:39 -0500 Subject: [PATCH 2/2] :sparkles: add customizable api url promoApiUrl prop --- src/getToken.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/getToken.tsx b/src/getToken.tsx index 3777fe8..7d31fb9 100644 --- a/src/getToken.tsx +++ b/src/getToken.tsx @@ -21,10 +21,17 @@ import fetch from 'cross-fetch'; * @param accessToken string JWT-encoded access token per * https://tincre.dev/docs/guides/how-to-auth. * + * @param promoApiUrl string | undefined base url for the Promo API, e.g. https://promo.api.tincre.dev. + * * @returns a usable refresh token you can store on the client. */ -export async function getToken(accessToken: string): Promise { - const url = 'https://promo.api.tincre.dev/token'; +export async function getToken( + accessToken: string, + promoApiUrl?: string +): Promise { + const url = promoApiUrl + ? promoApiUrl + '/token' + : 'https://promo.api.tincre.dev/token'; let refreshToken: string; // Example POST method implementation: // Default options are marked with * @@ -37,7 +44,6 @@ export async function getToken(accessToken: string): Promise { headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${accessToken}`, - // 'Content-Type': 'application/x-www-form-urlencoded', }, }); console.debug(`getToken: awaiting response JSON`);