From 550a693cf44e07aefef2ebf6a986206382455b9f Mon Sep 17 00:00:00 2001 From: pieterlukasse Date: Wed, 15 Nov 2023 19:32:43 +0100 Subject: [PATCH 1/2] fix: change test to reproduce error handling issue --- src/Analysis/GWASResults/Views/Home/Home.stories.jsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Analysis/GWASResults/Views/Home/Home.stories.jsx b/src/Analysis/GWASResults/Views/Home/Home.stories.jsx index 6cd489919d..445e82ff70 100644 --- a/src/Analysis/GWASResults/Views/Home/Home.stories.jsx +++ b/src/Analysis/GWASResults/Views/Home/Home.stories.jsx @@ -144,7 +144,14 @@ export const MockedError = MockTemplate.bind({}); MockedError.parameters = { msw: { handlers: [ - rest.post('', (req, res, ctx) => res(ctx.delay(800), ctx.status(403))), + rest.get( + 'http://:argowrapperpath/ga4gh/wes/v2/workflows', + (req, res, ctx) => { + const { argowrapperpath } = req.params; + console.log(argowrapperpath); + return res(ctx.delay(1000), ctx.status(500), ctx.json({"test":123})); + } + ), ], }, }; From d770619c3d7e063831b3a6f26015bd9b3c0efc5b Mon Sep 17 00:00:00 2001 From: pieterlukasse Date: Wed, 15 Nov 2023 19:40:33 +0100 Subject: [PATCH 2/2] fix: move /workflows call and add error handling --- src/Analysis/GWASResults/Utils/gwasWorkflowApi.js | 11 +++++++++++ src/Analysis/GWASResults/Views/Home/Home.jsx | 10 +--------- src/Analysis/GWASResults/Views/Home/Home.test.jsx | 1 + 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/Analysis/GWASResults/Utils/gwasWorkflowApi.js b/src/Analysis/GWASResults/Utils/gwasWorkflowApi.js index eb1a536fa7..5d0b7b6dd7 100644 --- a/src/Analysis/GWASResults/Utils/gwasWorkflowApi.js +++ b/src/Analysis/GWASResults/Utils/gwasWorkflowApi.js @@ -30,6 +30,17 @@ const getDataFromUrl = async ( return response.json(); }; +export const fetchGwasWorkflows = async () => { + const currentTeamProject = localStorage.getItem('teamProject'); + const workflowsEndpoint = `${gwasWorkflowPath}workflows?team_projects=${currentTeamProject}`; + const response = await fetch(workflowsEndpoint, { headers }); + if (!response.ok) { + const message = `An error has occured: ${response.status}`; + throw new Error(message); + } + return response.json(); +}; + export const fetchPresignedUrlForWorkflowArtifact = async ( workflowName, workflowUid, diff --git a/src/Analysis/GWASResults/Views/Home/Home.jsx b/src/Analysis/GWASResults/Views/Home/Home.jsx index b0f6fe5cbb..20608fc8e3 100644 --- a/src/Analysis/GWASResults/Views/Home/Home.jsx +++ b/src/Analysis/GWASResults/Views/Home/Home.jsx @@ -2,20 +2,12 @@ import React from 'react'; import { Spin } from 'antd'; import { useQuery } from 'react-query'; import HomeTable from './HomeTable/HomeTable'; -import { gwasWorkflowPath } from '../../../../localconf'; import LoadingErrorMessage from '../../../SharedUtils/LoadingErrorMessage/LoadingErrorMessage'; import ManageColumns from './ManageColumns/ManageColumns'; +import { fetchGwasWorkflows } from '../../Utils/gwasWorkflowApi'; const Home = () => { const refetchInterval = 5000; - - async function fetchGwasWorkflows() { - const currentTeamProject = localStorage.getItem('teamProject'); - const workflowsEndpoint = `${gwasWorkflowPath}workflows?team_projects=${currentTeamProject}`; - const getWorkflows = await fetch(workflowsEndpoint); - return getWorkflows.json(); - } - const { data, status } = useQuery('workflows', fetchGwasWorkflows, { refetchInterval, }); diff --git a/src/Analysis/GWASResults/Views/Home/Home.test.jsx b/src/Analysis/GWASResults/Views/Home/Home.test.jsx index bcda1884fc..18749687ad 100644 --- a/src/Analysis/GWASResults/Views/Home/Home.test.jsx +++ b/src/Analysis/GWASResults/Views/Home/Home.test.jsx @@ -46,6 +46,7 @@ describe('Home component', () => { it('should render the HomeTable component with data when test data is loaded', async () => { jest.spyOn(window, 'fetch').mockResolvedValueOnce({ + ok: true, json: jest.fn().mockResolvedValueOnce(TableData), }); render(testJSX());