Skip to content

Commit d0a451c

Browse files
committed
feat: use consoleFetchJSON
Assisted-By: Claude Code
1 parent b9ce5f8 commit d0a451c

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

web/src/components/Incidents/api.spec.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
};
99

1010
import { createAlertsQuery, fetchDataForIncidentsAndAlerts } from './api';
11-
import { PrometheusResponse } from '@openshift-console/dynamic-plugin-sdk';
11+
import { PrometheusResponse, consoleFetchJSON } from '@openshift-console/dynamic-plugin-sdk';
1212
import { buildPrometheusUrl } from '../utils';
1313

1414
// Mock the SDK
1515
jest.mock('@openshift-console/dynamic-plugin-sdk', () => ({
1616
PrometheusEndpoint: {
1717
QUERY_RANGE: 'api/v1/query_range',
1818
},
19+
consoleFetchJSON: jest.fn(),
1920
}));
2021

2122
// Mock the global utils to avoid window access side effects
@@ -126,8 +127,8 @@ describe('fetchDataForIncidentsAndAlerts', () => {
126127
},
127128
};
128129

129-
const fetch = jest
130-
.fn()
130+
const mockConsoleFetchJSON = consoleFetchJSON as jest.MockedFunction<typeof consoleFetchJSON>;
131+
mockConsoleFetchJSON
131132
.mockResolvedValueOnce(mockPrometheusResponse1)
132133
.mockResolvedValueOnce(mockPrometheusResponse2);
133134

@@ -136,14 +137,14 @@ describe('fetchDataForIncidentsAndAlerts', () => {
136137
'ALERTS{alertname="test", severity="critical", namespace="test"}',
137138
'ALERTS{alertname="test2", severity="warning", namespace="test2"}',
138139
];
139-
const result = await fetchDataForIncidentsAndAlerts(fetch, range, customQuery);
140+
const result = await fetchDataForIncidentsAndAlerts(mockConsoleFetchJSON, range, customQuery);
140141
expect(result).toEqual({
141142
status: 'success',
142143
data: {
143144
resultType: 'matrix',
144145
result: [result1, result2],
145146
},
146147
});
147-
expect(fetch).toHaveBeenCalledTimes(2);
148+
expect(mockConsoleFetchJSON).toHaveBeenCalledTimes(2);
148149
});
149150
});

web/src/components/Incidents/api.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
/* eslint-disable max-len */
22

3-
import { PrometheusEndpoint, PrometheusResponse } from '@openshift-console/dynamic-plugin-sdk';
3+
import {
4+
consoleFetchJSON,
5+
PrometheusEndpoint,
6+
PrometheusResponse,
7+
} from '@openshift-console/dynamic-plugin-sdk';
48
import { getPrometheusBasePath, buildPrometheusUrl } from '../utils';
59
import { PROMETHEUS_QUERY_INTERVAL_SECONDS } from './utils';
610

@@ -132,7 +136,7 @@ export const fetchDataForIncidentsAndAlerts = async (
132136
} as PrometheusResponse);
133137
}
134138

135-
return fetch(url);
139+
return consoleFetchJSON(url);
136140
});
137141

138142
const responses = await Promise.all(promises);

0 commit comments

Comments
 (0)