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

add login to error data

parent 3001bc4e
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"
/* eslint-disable no-magic-numbers */
import { createErrorData } from '@/utils/error-report/errorReporting';
import { apiPath } from '@/redux/apiPath';
import { HttpStatusCode } from 'axios';
import { loginFixture } from '@/models/fixtures/loginFixture';
import { userPrivilegesFixture } from '@/models/fixtures/userPrivilegesFixture';
import { login } from '@/redux/user/user.thunks';
import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
import { store } from '@/redux/store';
const mockedAxiosClient = mockNetworkResponse();
const CREDENTIALS = {
login: 'test',
password: 'password',
};
describe('createErrorData', () => {
it('should add stacktrace', () => {
const error = createErrorData(new Error('hello'));
expect(error.stacktrace).not.toEqual('');
});
it('should add url', () => {
const error = createErrorData(new Error('hello'));
expect(error.url).not.toBeNull();
});
it('should add guest login when not logged', () => {
const error = createErrorData(new Error('hello'));
expect(error.login).toBe('anonymous');
});
it('should add login when logged', async () => {
mockedAxiosClient.onPost(apiPath.postLogin()).reply(HttpStatusCode.Ok, loginFixture);
mockedAxiosClient
.onGet(apiPath.userPrivileges(loginFixture.login))
.reply(HttpStatusCode.Ok, userPrivilegesFixture);
await store.dispatch(login(CREDENTIALS));
const error = createErrorData(new Error('hello'));
expect(error.login).not.toBe('anonymous');
expect(error.login).toBe(loginFixture.login);
});
});
/* eslint-disable no-console */
import { ErrorData } from '@/utils/error-report/ErrorData';
import { SerializedError } from '@reduxjs/toolkit';
// eslint-disable-next-line import/no-cycle
import { store } from '@/redux/store';
export const createErrorData = (error: Error | SerializedError | undefined): ErrorData => {
let stacktrace = '';
......@@ -8,9 +10,14 @@ export const createErrorData = (error: Error | SerializedError | undefined): Err
stacktrace = error.stack !== undefined ? error.stack : '';
}
let { login } = store.getState().user;
if (!login) {
login = 'anonymous';
}
const errorData: ErrorData = {
url: window.location.href,
login: null, // TODO provide user login
login,
browser: null, // TODO
comment: null,
email: null, // TODO
......
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