Skip to content

Commit

Permalink
[#26] Change name from loginWithRefreshToken to refreshAccessToken
Browse files Browse the repository at this point in the history
  • Loading branch information
liamstevens111 committed Mar 22, 2023
1 parent 3c9628b commit 66a6f8c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/adapters/surveyAdapter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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);
});
});
Expand Down Expand Up @@ -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);
});
});
Expand Down
12 changes: 6 additions & 6 deletions src/adapters/surveyAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -15,7 +15,7 @@ class SurveyAdapter extends BaseAdapter {
static loginWithEmailPassword(authParams: LoginAuthType) {
/* eslint-disable camelcase */
const requestParams = {
...commonParams,
...OauthParams,
...authParams,
grant_type: 'password',
};
Expand All @@ -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',
};
Expand All @@ -39,7 +39,7 @@ class SurveyAdapter extends BaseAdapter {
static logout(accessToken: string) {
/* eslint-disable camelcase */
const requestParams = {
...commonParams,
...OauthParams,
token: accessToken,
};
/* eslint-enable camelcase */
Expand All @@ -49,7 +49,7 @@ class SurveyAdapter extends BaseAdapter {

static resetPassword(email: string) {
const requestParams = {
...commonParams,
...OauthParams,
user: { email: email },
};

Expand Down
2 changes: 1 addition & 1 deletion src/lib/requestManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 66a6f8c

Please sign in to comment.