Skip to content

Commit 87e8b71

Browse files
Merge pull request #32 from Code-4-Community/deleteUser
added delete user route, user settings route tests, and ran prettier
2 parents 2c0d089 + 460677e commit 87e8b71

File tree

6 files changed

+70
-9
lines changed

6 files changed

+70
-9
lines changed

src/App.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,16 @@ const App: React.FC = () => {
7676
<Route path={Routes.HOME} exact component={Home} />
7777
<Route path={Routes.SIGNUP} exact component={Signup} />
7878
<Route path={Routes.LOGIN} exact component={Login} />
79-
<Route path={Routes.FORGOT_PASSWORD_REQUEST} exact component={ForgotPassword} />
80-
<Route path={Routes.FORGOT_PASSWORD_RESET} exact component={ForgotPasswordReset} />
79+
<Route
80+
path={Routes.FORGOT_PASSWORD_REQUEST}
81+
exact
82+
component={ForgotPassword}
83+
/>
84+
<Route
85+
path={Routes.FORGOT_PASSWORD_RESET}
86+
exact
87+
component={ForgotPasswordReset}
88+
/>
8189
<Route
8290
path={Routes.VERIFY_EMAIL}
8391
exact

src/api/protectedApiClient.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ export interface ProtectedApiClient {
55
currentPassword: string;
66
newPassword: string;
77
}) => Promise<void>;
8+
readonly deleteUser: (request: { password: string }) => Promise<void>;
89
}
910

10-
enum ProtectedApiClientRoutes {
11+
export enum ProtectedApiClientRoutes {
1112
CHANGE_PASSWORD = '/api/v1/protected/user/change_password',
13+
DELETE_USER = '/api/v1/protected/user/',
1214
}
1315

1416
const changePassword = (request: {
@@ -19,12 +21,19 @@ const changePassword = (request: {
1921
ProtectedApiClientRoutes.CHANGE_PASSWORD,
2022
request,
2123
)
22-
.then((r) => r)
24+
.then((r) => r.data)
25+
.catch((e) => e);
26+
};
27+
28+
const deleteUser = (request: { password: string }): Promise<void> => {
29+
return AppAxiosInstance.post(ProtectedApiClientRoutes.DELETE_USER, request)
30+
.then((r) => r.data)
2331
.catch((e) => e);
2432
};
2533

2634
const Client: ProtectedApiClient = Object.freeze({
2735
changePassword,
36+
deleteUser,
2837
});
2938

3039
export default Client;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import ProtectedApiClient, {
2+
ProtectedApiClientRoutes,
3+
} from '../protectedApiClient';
4+
import nock from 'nock';
5+
6+
const BASE_URL = 'http://localhost';
7+
8+
describe('Protected API Client Tests', () => {
9+
describe('changePassword', () => {
10+
it('makes the right request', async () => {
11+
const response = '';
12+
13+
nock(BASE_URL)
14+
.post(ProtectedApiClientRoutes.CHANGE_PASSWORD)
15+
.reply(200, response);
16+
17+
const result = await ProtectedApiClient.changePassword({
18+
currentPassword: 'password',
19+
newPassword: 'password2',
20+
});
21+
22+
expect(result).toEqual(response);
23+
});
24+
});
25+
26+
describe('deleteUser', () => {
27+
it('makes the right request', async () => {
28+
const response = '';
29+
30+
nock(BASE_URL)
31+
.post(ProtectedApiClientRoutes.DELETE_USER)
32+
.reply(200, response);
33+
34+
const result = await ProtectedApiClient.deleteUser({
35+
password: 'password',
36+
});
37+
38+
expect(result).toEqual(response);
39+
});
40+
});
41+
});

src/auth/authClient.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const forgotPasswordReset: (
7676
user: ForgotPasswordResetRequest,
7777
) => Promise<void> = (user: ForgotPasswordResetRequest) =>
7878
AuthAxiosInstance.post(API_ROUTE.FORGOT_PASSWORD_RESET, user);
79-
79+
8080
const verifyEmail: (secretKey: string) => Promise<void> = (secretKey: string) =>
8181
// eslint-disable-next-line
8282
AuthAxiosInstance.get(API_ROUTE.VERIFY_EMAIL + secretKey).then(() => {});

src/auth/test/authClient.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ describe('Authentication Client Tests', () => {
8787
} catch (e) {
8888
fail(e);
8989
}
90-
})
91-
})
90+
});
91+
});
9292
});

src/containers/login/index.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { AsyncRequestKinds } from '../../utils/asyncRequest';
88
import { C4CState } from '../../store';
99
import { UserAuthenticationReducerState } from '../../auth/ducks/types';
1010
import { ContentContainer } from '../../components';
11-
import {Routes} from '../../App';
11+
import { Routes } from '../../App';
1212

1313
const { Title, Paragraph } = Typography;
1414

@@ -51,7 +51,10 @@ const Login: React.FC<LoginProps> = ({ tokens }) => {
5151
</Paragraph>
5252
<Paragraph>
5353
Forgot your password? Click{' '}
54-
<Link to={Routes.FORGOT_PASSWORD_REQUEST} component={Typography.Link}>
54+
<Link
55+
to={Routes.FORGOT_PASSWORD_REQUEST}
56+
component={Typography.Link}
57+
>
5558
here
5659
</Link>{' '}
5760
to reset it.

0 commit comments

Comments
 (0)