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

Merge branch '335-tests-depend-on-lux1-being-online' into '333-removing-overlay-does-not-work'

Resolve "tests depend on lux1 being online"

See merge request !346
parents 926252f8 af40a282
No related branches found
No related tags found
3 merge requests!347Merge 18.0.8,!346Resolve "tests depend on lux1 being online",!344Resolve "removing overlay does not work"
Pipeline #99258 passed
import { store } from '@/redux/store';
import { mockNetworkResponse } from '@/utils/mockNetworkResponse';
import { apiPath } from '@/redux/apiPath';
import { HttpStatusCode } from 'axios';
import { errorMiddlewareListener } from './error.middleware';
jest.mock('../../utils/showToast');
const mockedAxiosClient = mockNetworkResponse();
describe('errorMiddlewareListener', () => {
const dispatchSpy = jest.spyOn(store, 'dispatch');
......@@ -12,6 +17,8 @@ describe('errorMiddlewareListener', () => {
});
it('should handle error with message when action is rejected', async () => {
mockedAxiosClient.onGet(apiPath.getStacktrace('Error-2')).reply(HttpStatusCode.Ok, {});
const action = {
type: 'action/rejected',
payload: 'Error message',
......@@ -21,7 +28,7 @@ describe('errorMiddlewareListener', () => {
requestStatus: 'rejected',
},
error: {
code: 'Error 2',
code: 'Error-2',
},
};
const { getState, dispatch } = store;
......@@ -37,6 +44,7 @@ describe('errorMiddlewareListener', () => {
});
it('should handle error without message when action is rejected', async () => {
mockedAxiosClient.onGet(apiPath.getStacktrace('Error-3')).reply(HttpStatusCode.Ok, {});
const action = {
type: 'action/rejected',
payload: null,
......@@ -46,7 +54,7 @@ describe('errorMiddlewareListener', () => {
requestStatus: 'rejected',
},
error: {
code: 'Error 3',
code: 'Error-3',
},
};
const { getState, dispatch } = store;
......@@ -78,6 +86,7 @@ describe('errorMiddlewareListener', () => {
});
it('should handle error with unknown error message when action payload is not a string', async () => {
mockedAxiosClient.onGet(apiPath.getStacktrace('ERROR')).reply(HttpStatusCode.Ok, {});
const action = {
type: 'action/rejected',
payload: {},
......@@ -104,6 +113,7 @@ describe('errorMiddlewareListener', () => {
});
it('should handle error with custom message when action payload is a string', async () => {
mockedAxiosClient.onGet(apiPath.getStacktrace('ERROR')).reply(HttpStatusCode.Ok, {});
const action = {
type: 'action/rejected',
payload: 'Failed to fetch',
......@@ -133,6 +143,7 @@ describe('errorMiddlewareListener', () => {
});
it('should show modal on access denied', async () => {
mockedAxiosClient.onGet(apiPath.getStacktrace('403')).reply(HttpStatusCode.Ok, {});
const action = {
type: 'action/rejected',
payload: null,
......
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