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

add email of logged user to error data

parent 2832ccca
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"
......@@ -12,6 +12,7 @@ export const loginReducer = (builder: ActionReducerMapBuilder<UserState>): void
state.loading = 'succeeded';
state.role = action.payload?.role || null;
state.login = action.payload?.login || null;
state.userData = action.payload?.userData || null;
})
.addCase(login.rejected, state => {
state.authenticated = false;
......@@ -48,6 +49,7 @@ export const logoutReducer = (builder: ActionReducerMapBuilder<UserState>): void
state.loading = 'succeeded';
state.role = null;
state.login = null;
state.userData = null;
})
.addCase(logout.rejected, state => {
state.loading = 'failed';
......
......@@ -54,6 +54,7 @@ export const login = createAsyncThunk(
return {
login: loginName,
role,
userData,
};
}
......
......@@ -2,7 +2,7 @@ import { createErrorData } from '@/utils/error-report/errorReporting';
import { apiPath } from '@/redux/apiPath';
import { HttpStatusCode } from 'axios';
import { loginFixture } from '@/models/fixtures/loginFixture';
import { login } from '@/redux/user/user.thunks';
import { login, logout } from '@/redux/user/user.thunks';
import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
import { store } from '@/redux/store';
import { getConfiguration } from '@/redux/configuration/configuration.thunks';
......@@ -61,4 +61,20 @@ describe('createErrorData', () => {
const error = createErrorData(new Error());
expect(error.version).not.toBeNull();
});
it('should add email when logged', async () => {
mockedAxiosClient.onPost(apiPath.postLogin()).reply(HttpStatusCode.Ok, loginFixture);
mockedAxiosClient.onGet(apiPath.user(loginFixture.login)).reply(HttpStatusCode.Ok, userFixture);
await store.dispatch(login(CREDENTIALS));
const error = createErrorData(new Error());
expect(error.email).toBe(userFixture.email);
});
it('email should be empty when not logged', async () => {
mockedAxiosClient.onPost(apiPath.logout()).reply(HttpStatusCode.Ok, {});
await store.dispatch(logout());
const error = createErrorData(new Error());
expect(error.email).toBeNull();
});
});
......@@ -14,6 +14,12 @@ export const createErrorData = (error: Error | SerializedError | undefined): Err
if (!login) {
login = 'anonymous';
}
const { userData } = store.getState().user;
let email = null;
if (userData) {
email = userData.email;
}
const configuration = store.getState().configuration.main.data;
const version = configuration ? configuration.version : null;
......@@ -22,7 +28,7 @@ export const createErrorData = (error: Error | SerializedError | undefined): Err
login,
browser: navigator.userAgent,
comment: null,
email: null, // TODO
email,
javaStacktrace: null, // TODO
stacktrace,
timestamp: Math.floor(+new Date() / ONE_THOUSAND),
......
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