Skip to content

Commit

Permalink
Merge branch 'staging' into 10401-story
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzjone-flexion committed Sep 5, 2024
2 parents 90c9219 + 62ebe70 commit 7ed6d3c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
31 changes: 31 additions & 0 deletions web-client/src/presenter/actions/Login/submitLoginAction.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,37 @@ describe('submitLoginAction', () => {
};
});

it('should ignore leading/trailing spaces in password entry', async () => {
applicationContext.getUseCases().loginInteractor.mockResolvedValue({
accessToken: testAccessToken,
idToken: testIdToken,
refreshToken: testRefreshToken,
});

await runAction(submitLoginAction, {
modules: {
presenter,
},
state: {
authentication: {
form: {
code: '',
confirmPassword: '',
email: testEmail,
password: ' ' + testPassword + ' ',
},
tempPassword: '',
},
},
});
expect(
applicationContext.getUseCases().loginInteractor.mock.calls[0][1],
).toEqual({
email: testEmail,
password: testPassword,
});
});

it('should call the success path when user is authenticated successfully', async () => {
applicationContext.getUseCases().loginInteractor.mockResolvedValue({
accessToken: testAccessToken,
Expand Down
9 changes: 7 additions & 2 deletions web-client/src/presenter/actions/Login/submitLoginAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@ export const submitLoginAction = async ({
}> => {
const { email, password } = get(state.authentication.form);

const cleanedPassword = password.trim();

try {
const { accessToken, idToken, refreshToken } = await applicationContext
.getUseCases()
.loginInteractor(applicationContext, { email, password });
.loginInteractor(applicationContext, {
email,
password: cleanedPassword,
});

return path.success({ accessToken, idToken, refreshToken });
} catch (err: any) {
const originalErrorMessage = err?.originalError?.response?.data;

if (originalErrorMessage === 'NewPasswordRequired') {
return path.changePassword({ email, tempPassword: password });
return path.changePassword({ email, tempPassword: cleanedPassword });
}

if (originalErrorMessage === 'Invalid Username or Password') {
Expand Down

0 comments on commit 7ed6d3c

Please sign in to comment.