From 1a6bf13bf4f118d5d13bec38e486ddcc78e9d993 Mon Sep 17 00:00:00 2001 From: Tran Manh Date: Wed, 5 Jul 2023 11:29:23 +0700 Subject: [PATCH] [#16] Implement backend for refresh token --- src/adapters/Authentication/index.test.ts | 22 +++++++++++++++++++++- src/adapters/Authentication/index.ts | 8 ++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/adapters/Authentication/index.test.ts b/src/adapters/Authentication/index.test.ts index da15b34..e1aeb80 100644 --- a/src/adapters/Authentication/index.test.ts +++ b/src/adapters/Authentication/index.test.ts @@ -1,7 +1,7 @@ import { post } from 'adapters/Base'; import { config } from 'config'; -import { signIn } from '.'; +import { refreshToken, signIn } from '.'; jest.mock('adapters/Base'); jest.mock('config'); @@ -40,4 +40,24 @@ describe('AuthenticationAdapter', () => { }); }); }); + + describe('refreshToken', () => { + describe('given a refresh token', () => { + it('calls the post method from the base adapter', () => { + const token = 'refresh token'; + + const expectedPath = 'oauth/token'; + const expectedPayload = { + grantType: 'refresh_token', + clientId: config().clientId, + clientSecret: config().clientSecret, + refreshToken: token, + }; + + refreshToken(token); + + expect(post).toHaveBeenCalledWith(expectedPath, expectedPayload); + }); + }); + }); }); diff --git a/src/adapters/Authentication/index.ts b/src/adapters/Authentication/index.ts index bbc6194..1cb4cc4 100644 --- a/src/adapters/Authentication/index.ts +++ b/src/adapters/Authentication/index.ts @@ -9,3 +9,11 @@ export const signIn = (email: string, password: string) => email: email, password: password, }); + +export const refreshToken = (refreshToken: string) => + post('oauth/token', { + clientId: config().clientId, + clientSecret: config().clientSecret, + grantType: 'refresh_token', + refreshToken: refreshToken, + });