From 640dd9b46c3165b922d4fa77b934d73fe51cf64b Mon Sep 17 00:00:00 2001 From: Eric Lipe Date: Thu, 21 Nov 2024 13:57:30 -0500 Subject: [PATCH] - Updated action to use correct return type when api request fails - Updated tests --- tdrs-frontend/src/actions/reports.js | 14 ++++++++++++-- tdrs-frontend/src/actions/reports.test.js | 3 ++- .../src/components/Reports/Reports.test.js | 2 ++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/tdrs-frontend/src/actions/reports.js b/tdrs-frontend/src/actions/reports.js index 1c55f14eb..e4ed33838 100644 --- a/tdrs-frontend/src/actions/reports.js +++ b/tdrs-frontend/src/actions/reports.js @@ -4,6 +4,7 @@ import axios from 'axios' import axiosInstance from '../axios-instance' import { logErrorToServer } from '../utils/eventLogger' import removeFileInputErrorState from '../utils/removeFileInputErrorState' +import { defaultFileUploadSections } from '../reducers/reports' const BACKEND_URL = process.env.REACT_APP_BACKEND_URL @@ -274,8 +275,17 @@ export const setStt = (stt) => async (dispatch) => { const response = await axiosInstance.get(URL, { withCredentials: true, }) - const data = - typeof response !== 'undefined' ? response.data : { filenames: [] } + + var data = {} + if (typeof response !== 'undefined') { + data = response.data + } else { + var sectionMap = {} + defaultFileUploadSections.forEach((section, index) => { + return (sectionMap[section] = defaultFileUploadSections.length - index) + }) + data = { filenames: sectionMap } + } const newUploadSections = Object.keys(data.filenames) dispatch({ type: SET_SELECTED_STT, payload: { stt, newUploadSections } }) } diff --git a/tdrs-frontend/src/actions/reports.test.js b/tdrs-frontend/src/actions/reports.test.js index cb111f9a6..38782094e 100644 --- a/tdrs-frontend/src/actions/reports.test.js +++ b/tdrs-frontend/src/actions/reports.test.js @@ -22,6 +22,7 @@ import { submit, SET_FILE_SUBMITTED, } from './reports' +import { defaultFileUploadSections } from '../reducers/reports' describe('actions/reports', () => { const mockStore = configureStore([thunk]) @@ -238,7 +239,7 @@ describe('actions/reports', () => { expect(actions[0].type).toBe(SET_SELECTED_STT) expect(actions[0].payload).toStrictEqual({ stt: 'florida', - newUploadSections: [], + newUploadSections: defaultFileUploadSections, }) }) diff --git a/tdrs-frontend/src/components/Reports/Reports.test.js b/tdrs-frontend/src/components/Reports/Reports.test.js index 2c97a1b5c..4b3b742dd 100644 --- a/tdrs-frontend/src/components/Reports/Reports.test.js +++ b/tdrs-frontend/src/components/Reports/Reports.test.js @@ -7,10 +7,12 @@ import configureStore from 'redux-mock-store' import appConfigureStore from '../../configureStore' import Reports from './Reports' import { SET_FILE, upload } from '../../actions/reports' +import { defaultFileUploadSections } from '../../reducers/reports' describe('Reports', () => { const initialState = { reports: { + fileUploadSections: defaultFileUploadSections, files: [ { section: 'Active Case Data',