Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,16 @@ const App: React.FC = () => {
<Route path={Routes.HOME} exact component={Home} />
<Route path={Routes.SIGNUP} exact component={Signup} />
<Route path={Routes.LOGIN} exact component={Login} />
<Route path={Routes.FORGOT_PASSWORD_REQUEST} exact component={ForgotPassword} />
<Route path={Routes.FORGOT_PASSWORD_RESET} exact component={ForgotPasswordReset} />
<Route
path={Routes.FORGOT_PASSWORD_REQUEST}
exact
component={ForgotPassword}
/>
<Route
path={Routes.FORGOT_PASSWORD_RESET}
exact
component={ForgotPasswordReset}
/>
<Route
path={Routes.VERIFY_EMAIL}
exact
Expand Down
13 changes: 11 additions & 2 deletions src/api/protectedApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ export interface ProtectedApiClient {
currentPassword: string;
newPassword: string;
}) => Promise<void>;
readonly deleteUser: (request: { password: string }) => Promise<void>;
}

enum ProtectedApiClientRoutes {
export enum ProtectedApiClientRoutes {
CHANGE_PASSWORD = '/api/v1/protected/user/change_password',
DELETE_USER = '/api/v1/protected/user/',
}

const changePassword = (request: {
Expand All @@ -19,12 +21,19 @@ const changePassword = (request: {
ProtectedApiClientRoutes.CHANGE_PASSWORD,
request,
)
.then((r) => r)
.then((r) => r.data)
.catch((e) => e);
};

const deleteUser = (request: { password: string }): Promise<void> => {
return AppAxiosInstance.post(ProtectedApiClientRoutes.DELETE_USER, request)
.then((r) => r.data)
.catch((e) => e);
};

const Client: ProtectedApiClient = Object.freeze({
changePassword,
deleteUser,
});

export default Client;
41 changes: 41 additions & 0 deletions src/api/test/protectedApiClient.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import ProtectedApiClient, {
ProtectedApiClientRoutes,
} from '../protectedApiClient';
import nock from 'nock';

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);
});
});
});
2 changes: 1 addition & 1 deletion src/auth/authClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const forgotPasswordReset: (
user: ForgotPasswordResetRequest,
) => Promise<void> = (user: ForgotPasswordResetRequest) =>
AuthAxiosInstance.post(API_ROUTE.FORGOT_PASSWORD_RESET, user);

const verifyEmail: (secretKey: string) => Promise<void> = (secretKey: string) =>
// eslint-disable-next-line
AuthAxiosInstance.get(API_ROUTE.VERIFY_EMAIL + secretKey).then(() => {});
Expand Down
4 changes: 2 additions & 2 deletions src/auth/test/authClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ describe('Authentication Client Tests', () => {
} catch (e) {
fail(e);
}
})
})
});
});
});
7 changes: 5 additions & 2 deletions src/containers/login/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -51,7 +51,10 @@ const Login: React.FC<LoginProps> = ({ tokens }) => {
</Paragraph>
<Paragraph>
Forgot your password? Click{' '}
<Link to={Routes.FORGOT_PASSWORD_REQUEST} component={Typography.Link}>
<Link
to={Routes.FORGOT_PASSWORD_REQUEST}
component={Typography.Link}
>
here
</Link>{' '}
to reset it.
Expand Down