From 66a6f8c97d87b85ddb05e846a426319ca2ede2fc Mon Sep 17 00:00:00 2001 From: Liam Stevens <8955671+liamstevens111@users.noreply.github.com> Date: Wed, 22 Mar 2023 16:16:21 +0700 Subject: [PATCH] [#26] Change name from loginWithRefreshToken to refreshAccessToken --- src/adapters/surveyAdapter.test.ts | 6 +++--- src/adapters/surveyAdapter.ts | 12 ++++++------ src/lib/requestManager.ts | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/adapters/surveyAdapter.test.ts b/src/adapters/surveyAdapter.test.ts index a8026ee..ab067fa 100644 --- a/src/adapters/surveyAdapter.test.ts +++ b/src/adapters/surveyAdapter.test.ts @@ -46,7 +46,7 @@ describe('SurveyAdapter', () => { }); }); - describe('loginWithRefreshToken', () => { + describe('refreshAccessToken', () => { test('The refresh token endpoint is called with refresh token from the request', async () => { const scope = nock(`${process.env.REACT_APP_API_ENDPOINT}`) .defaultReplyHeaders({ @@ -61,7 +61,7 @@ describe('SurveyAdapter', () => { .reply(200); expect(scope.isDone()).toBe(false); - await SurveyAdapter.loginWithRefreshToken('refresh_token'); + await SurveyAdapter.refreshAccessToken('refresh_token'); expect(scope.isDone()).toBe(true); }); }); @@ -111,7 +111,7 @@ describe('SurveyAdapter', () => { .reply(200); expect(scope.isDone()).toBe(false); - expect(await AuthAdapter.resetPassword(mockLoginCredentials.email)); + expect(await SurveyAdapter.resetPassword(mockLoginCredentials.email)); expect(scope.isDone()).toBe(true); }); }); diff --git a/src/adapters/surveyAdapter.ts b/src/adapters/surveyAdapter.ts index 6e9a782..a52d34a 100644 --- a/src/adapters/surveyAdapter.ts +++ b/src/adapters/surveyAdapter.ts @@ -6,7 +6,7 @@ type LoginAuthType = { }; /* eslint-disable camelcase */ -export const commonParams = { +export const OauthParams = { client_id: process.env.REACT_APP_API_CLIENT_ID, client_secret: process.env.REACT_APP_API_CLIENT_SECRET, }; @@ -15,7 +15,7 @@ class SurveyAdapter extends BaseAdapter { static loginWithEmailPassword(authParams: LoginAuthType) { /* eslint-disable camelcase */ const requestParams = { - ...commonParams, + ...OauthParams, ...authParams, grant_type: 'password', }; @@ -24,10 +24,10 @@ class SurveyAdapter extends BaseAdapter { return this.prototype.postRequest('oauth/token', { data: requestParams }); } - static loginWithRefreshToken(refreshToken: string) { + static refreshAccessToken(refreshToken: string) { /* eslint-disable camelcase */ const requestParams = { - ...commonParams, + ...OauthParams, refresh_token: refreshToken, grant_type: 'refresh_token', }; @@ -39,7 +39,7 @@ class SurveyAdapter extends BaseAdapter { static logout(accessToken: string) { /* eslint-disable camelcase */ const requestParams = { - ...commonParams, + ...OauthParams, token: accessToken, }; /* eslint-enable camelcase */ @@ -49,7 +49,7 @@ class SurveyAdapter extends BaseAdapter { static resetPassword(email: string) { const requestParams = { - ...commonParams, + ...OauthParams, user: { email: email }, }; diff --git a/src/lib/requestManager.ts b/src/lib/requestManager.ts index 729f32a..8f0f5fd 100644 --- a/src/lib/requestManager.ts +++ b/src/lib/requestManager.ts @@ -29,7 +29,7 @@ export function createResponseErrorInterceptor() { if (userProfile?.auth?.refresh_token) { try { - const response = await SurveyAdapter.loginWithRefreshToken(userProfile.auth.refresh_token); + const response = await SurveyAdapter.refreshAccessToken(userProfile.auth.refresh_token); const { attributes: authInfo } = await response.data;