Skip to content
Snippets Groups Projects

Merge 18.0.8

Merged Piotr Gawron requested to merge merge-18.0.8 into development
3 files
+ 19
3
Compare changes
  • Side-by-side
  • Inline
Files
3
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,
Loading