From 9600781e94f6584af5e87bd72e183783ffcbe164 Mon Sep 17 00:00:00 2001 From: willmt80 Date: Wed, 3 Mar 2021 20:47:13 -0500 Subject: [PATCH 1/3] added delete user route, user settings route tests, and ran prettier --- src/App.tsx | 12 ++++++++++-- src/api/protectedApiClient.ts | 11 ++++++++++- src/api/test/protectedApiClient.test.ts | 6 ++++++ src/auth/authClient.tsx | 2 +- src/auth/test/authClient.test.ts | 4 ++-- src/containers/login/index.tsx | 7 +++++-- 6 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 src/api/test/protectedApiClient.test.ts diff --git a/src/App.tsx b/src/App.tsx index c776712..b3b0948 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -76,8 +76,16 @@ const App: React.FC = () => { - - + + Promise; + readonly deleteUser: (request: { password: string }) => Promise; } -enum ProtectedApiClientRoutes { +export enum ProtectedApiClientRoutes { CHANGE_PASSWORD = '/api/v1/protected/user/change_password', + DELETE_USER = '/api/v1/protected/user/', } const changePassword = (request: { @@ -23,8 +25,15 @@ const changePassword = (request: { .catch((e) => e); }; +const deleteUser = (request: { password: string }): Promise => { + return AppAxiosInstance.post(ProtectedApiClientRoutes.DELETE_USER, request) + .then((r) => r.data) + .catch((e) => e); +}; + const Client: ProtectedApiClient = Object.freeze({ changePassword, + deleteUser, }); export default Client; diff --git a/src/api/test/protectedApiClient.test.ts b/src/api/test/protectedApiClient.test.ts new file mode 100644 index 0000000..19954f3 --- /dev/null +++ b/src/api/test/protectedApiClient.test.ts @@ -0,0 +1,6 @@ +import ProtectedApiClient, { + ProtectedApiClientRoutes, +} from '../protectedApiClient'; +import nock from 'nock'; + +describe('Protected API Client Tests', () => {}); diff --git a/src/auth/authClient.tsx b/src/auth/authClient.tsx index 7a3f9a3..9673af6 100644 --- a/src/auth/authClient.tsx +++ b/src/auth/authClient.tsx @@ -76,7 +76,7 @@ const forgotPasswordReset: ( user: ForgotPasswordResetRequest, ) => Promise = (user: ForgotPasswordResetRequest) => AuthAxiosInstance.post(API_ROUTE.FORGOT_PASSWORD_RESET, user); - + const verifyEmail: (secretKey: string) => Promise = (secretKey: string) => // eslint-disable-next-line AuthAxiosInstance.get(API_ROUTE.VERIFY_EMAIL + secretKey).then(() => {}); diff --git a/src/auth/test/authClient.test.ts b/src/auth/test/authClient.test.ts index 5fde6e3..899a4aa 100644 --- a/src/auth/test/authClient.test.ts +++ b/src/auth/test/authClient.test.ts @@ -87,6 +87,6 @@ describe('Authentication Client Tests', () => { } catch (e) { fail(e); } - }) - }) + }); + }); }); diff --git a/src/containers/login/index.tsx b/src/containers/login/index.tsx index 175c515..53583c5 100644 --- a/src/containers/login/index.tsx +++ b/src/containers/login/index.tsx @@ -8,7 +8,7 @@ import { AsyncRequestKinds } from '../../utils/asyncRequest'; import { C4CState } from '../../store'; import { UserAuthenticationReducerState } from '../../auth/ducks/types'; import { ContentContainer } from '../../components'; -import {Routes} from '../../App'; +import { Routes } from '../../App'; const { Title, Paragraph } = Typography; @@ -51,7 +51,10 @@ const Login: React.FC = ({ tokens }) => { Forgot your password? Click{' '} - + here {' '} to reset it. From 6b4d338de3cb6344794bca649bd25c540c9b82fd Mon Sep 17 00:00:00 2001 From: willmt80 Date: Wed, 3 Mar 2021 22:25:05 -0500 Subject: [PATCH 2/3] test file --- src/api/test/protectedApiClient.test.ts | 37 ++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/src/api/test/protectedApiClient.test.ts b/src/api/test/protectedApiClient.test.ts index 19954f3..bb04392 100644 --- a/src/api/test/protectedApiClient.test.ts +++ b/src/api/test/protectedApiClient.test.ts @@ -3,4 +3,39 @@ import ProtectedApiClient, { } from '../protectedApiClient'; import nock from 'nock'; -describe('Protected API Client Tests', () => {}); +const BASE_URL = 'http://localhost'; + +describe('Protected API Client Tests', () => { + describe('changePassword', () => { + it('makes the right request', async () => { + const response = ''; + + nock(BASE_URL) + .post(ProtectedApiClientRoutes.CHANGE_PASSWORD) + .reply(200, response); + + const result = await ProtectedApiClient.changePassword({ + currentPassword: 'password', + newPassword: 'password2', + }); + + expect(result).toEqual(response); + }); + }); + + describe('deleteUser', () => { + it('makes the right request', async () => { + const response = ''; + + nock(BASE_URL) + .post(ProtectedApiClientRoutes.DELETE_USER) + .reply(200, response); + + const result = await ProtectedApiClient.deleteUser({ + password: 'password', + }); + + expect(result).toEqual(response); + }); + }); +}); \ No newline at end of file From 460677e60245272c3f2fc687b771548e396ad44a Mon Sep 17 00:00:00 2001 From: willmt80 Date: Sun, 7 Mar 2021 15:46:24 -0500 Subject: [PATCH 3/3] get the data from the change password response --- src/api/protectedApiClient.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/api/protectedApiClient.ts b/src/api/protectedApiClient.ts index 36a0c03..c1a55c5 100644 --- a/src/api/protectedApiClient.ts +++ b/src/api/protectedApiClient.ts @@ -21,7 +21,7 @@ const changePassword = (request: { ProtectedApiClientRoutes.CHANGE_PASSWORD, request, ) - .then((r) => r) + .then((r) => r.data) .catch((e) => e); };