diff --git a/src/redux/statistics/statistics.reducers.test.ts b/src/redux/statistics/statistics.reducers.test.ts index 6d620db1720db9fa9f929ed84fe94c1cb32d8b0c..45a0b8430eb9cca2df2a7eae9fcb08c5487cd4a6 100644 --- a/src/redux/statistics/statistics.reducers.test.ts +++ b/src/redux/statistics/statistics.reducers.test.ts @@ -7,6 +7,7 @@ import { mockNetworkResponse } from '@/utils/mockNetworkResponse'; import { HttpStatusCode } from 'axios'; import { waitFor } from '@testing-library/react'; import { statisticsFixture } from '@/models/fixtures/statisticsFixture'; +import { unwrapResult } from '@reduxjs/toolkit'; import { StatisticsState } from './statistics.types'; import statisticsReducer from './statistics.slice'; import { apiPath } from '../apiPath'; @@ -56,11 +57,12 @@ describe('statistics reducer', () => { .onGet(apiPath.getStatisticsById(PROJECT_ID)) .reply(HttpStatusCode.NotFound, undefined); - const { type, payload } = await store.dispatch(getStatisticsById(PROJECT_ID)); + const action = await store.dispatch(getStatisticsById(PROJECT_ID)); + const { loading } = store.getState().statistics; - expect(type).toBe('statistics/getStatisticsById/rejected'); - expect(payload).toBe( + expect(action.type).toBe('statistics/getStatisticsById/rejected'); + expect(() => unwrapResult(action)).toThrow( "Failed to fetch statistics: The page you're looking for doesn't exist. Please verify the URL and try again.", ); diff --git a/src/redux/statistics/statistics.thunks.ts b/src/redux/statistics/statistics.thunks.ts index 1a683a4e3ea3e50238f1fce85b47dbde93b59b98..dcaf0100818bce4c9d6a5c90f5698fc11adcbfa7 100644 --- a/src/redux/statistics/statistics.thunks.ts +++ b/src/redux/statistics/statistics.thunks.ts @@ -3,14 +3,14 @@ import { Statistics } from '@/types/models'; import { validateDataUsingZodSchema } from '@/utils/validateDataUsingZodSchema'; import { createAsyncThunk } from '@reduxjs/toolkit'; import { statisticsSchema } from '@/models/statisticsSchema'; -import { getErrorMessage } from '@/utils/getErrorMessage'; import { ThunkConfig } from '@/types/store'; +import { getError } from '@/utils/error-report/getError'; import { apiPath } from '../apiPath'; import { STATISTICS_FETCHING_ERROR_PREFIX } from './statistics.constants'; export const getStatisticsById = createAsyncThunk<Statistics | undefined, string, ThunkConfig>( 'statistics/getStatisticsById', - async (id, { rejectWithValue }) => { + async id => { try { const response = await axiosInstance.get<Statistics>(apiPath.getStatisticsById(id)); @@ -18,8 +18,7 @@ export const getStatisticsById = createAsyncThunk<Statistics | undefined, string return isDataValid ? response.data : undefined; } catch (error) { - const errorMessage = getErrorMessage({ error, prefix: STATISTICS_FETCHING_ERROR_PREFIX }); - return rejectWithValue(errorMessage); + return Promise.reject(getError({ error, prefix: STATISTICS_FETCHING_ERROR_PREFIX })); } }, );