Skip to content
Snippets Groups Projects
Commit addd8360 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

failed login should result in Invalid credentials error message

parent d8d1b50a
No related branches found
No related tags found
2 merge requests!223reset the pin numbers before search results are fetch (so the results will be...,!199Resolve "[MIN-321] form for reporting errors in minerva"
Pipeline #91061 passed with warnings
......@@ -5,12 +5,15 @@ import {
ToolkitStoreWithSingleSlice,
createStoreInstanceUsingSliceReducer,
} from '@/utils/createStoreInstanceUsingSliceReducer';
import { showToast } from '@/utils/showToast';
import { apiPath } from '../apiPath';
import { closeModal } from '../modal/modal.slice';
import userReducer from './user.slice';
import { UserState } from './user.types';
import { login } from './user.thunks';
jest.mock('../../utils/showToast');
const mockedAxiosClient = mockNetworkResponse();
const CREDENTIALS = {
login: 'test',
......@@ -50,4 +53,15 @@ describe('login thunk', () => {
await store.dispatch(login(CREDENTIALS));
});
it('dispatch showToast on failed login with invalid data', async () => {
mockedAxiosClient.onPost(apiPath.postLogin()).reply(HttpStatusCode.Unauthorized, loginFixture);
await store.dispatch(login(CREDENTIALS));
expect(showToast).toHaveBeenCalledWith({
message: 'Invalid credentials.',
type: 'error',
});
});
});
......@@ -6,6 +6,8 @@ import { sessionSchemaValid } from '@/models/sessionValidSchema';
import { Login, SessionValid, User, UserPrivilege } from '@/types/models';
import { USER_ROLE } from '@/constants/user';
import { getError } from '@/utils/error-report/getError';
import axios, { HttpStatusCode } from 'axios';
import { showToast } from '@/utils/showToast';
import { apiPath } from '../apiPath';
import { closeModal, openLoggedInMenuModal } from '../modal/modal.slice';
import { hasPrivilege } from './user.utils';
......@@ -60,6 +62,15 @@ export const login = createAsyncThunk(
return undefined;
} catch (error) {
if (axios.isAxiosError(error)) {
if (error?.response?.status === HttpStatusCode.Unauthorized) {
showToast({
type: 'error',
message: 'Invalid credentials.',
});
return undefined;
}
}
return Promise.reject(getError({ error, prefix: 'Login' }));
}
},
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment