diff --git a/plugins/pagerduty/src/api/client.ts b/plugins/pagerduty/src/api/client.ts index 50d9c7cdd9..ac5afdae79 100644 --- a/plugins/pagerduty/src/api/client.ts +++ b/plugins/pagerduty/src/api/client.ts @@ -88,14 +88,13 @@ export class PagerDutyClient implements PagerDutyApi { return response; } - async getIncidentsByServiceId(serviceId: string): Promise { + async getIncidentsByServiceId(serviceId: string): Promise { const params = `time_zone=UTC&sort_by=created_at&statuses[]=triggered&statuses[]=acknowledged&service_ids[]=${serviceId}`; const url = `${await this.config.discoveryApi.getBaseUrl( 'proxy', )}/pagerduty/incidents?${params}`; - const { incidents } = await this.getByUrl(url); - return incidents; + return await this.getByUrl(url); } async getChangeEventsByServiceId(serviceId: string): Promise { diff --git a/plugins/pagerduty/src/api/types.ts b/plugins/pagerduty/src/api/types.ts index 8ec95c285b..9ecd233bab 100644 --- a/plugins/pagerduty/src/api/types.ts +++ b/plugins/pagerduty/src/api/types.ts @@ -38,7 +38,7 @@ export interface PagerDutyApi { * Fetches a list of incidents a provided service has. * */ - getIncidentsByServiceId(serviceId: string): Promise; + getIncidentsByServiceId(serviceId: string): Promise; /** * Fetches a list of change events a provided service has. diff --git a/plugins/pagerduty/src/components/Incident/Incidents.test.tsx b/plugins/pagerduty/src/components/Incident/Incidents.test.tsx index 74e7d82e8b..ad69bc083e 100644 --- a/plugins/pagerduty/src/components/Incident/Incidents.test.tsx +++ b/plugins/pagerduty/src/components/Incident/Incidents.test.tsx @@ -30,7 +30,7 @@ describe('Incidents', () => { it('Renders an empty state when there are no incidents', async () => { mockPagerDutyApi.getIncidentsByServiceId = jest .fn() - .mockImplementationOnce(async () => []); + .mockImplementationOnce(async () => ({ incidents: [] })); const { getByText, queryByTestId } = render( wrapInTestApp( @@ -44,9 +44,10 @@ describe('Incidents', () => { }); it('Renders all incidents', async () => { - mockPagerDutyApi.getIncidentsByServiceId = jest.fn().mockImplementationOnce( - async () => - [ + mockPagerDutyApi.getIncidentsByServiceId = jest + .fn() + .mockImplementationOnce(async () => ({ + incidents: [ { id: 'id1', status: 'triggered', @@ -83,7 +84,7 @@ describe('Incidents', () => { serviceId: 'sId2', }, ] as Incident[], - ); + })); const { getByText, getAllByTitle, queryByTestId } = render( wrapInTestApp( diff --git a/plugins/pagerduty/src/components/Incident/Incidents.tsx b/plugins/pagerduty/src/components/Incident/Incidents.tsx index 06dd50bdaa..2e0e201c79 100644 --- a/plugins/pagerduty/src/components/Incident/Incidents.tsx +++ b/plugins/pagerduty/src/components/Incident/Incidents.tsx @@ -34,7 +34,12 @@ export const Incidents = ({ serviceId, refreshIncidents }: Props) => { const api = useApi(pagerDutyApiRef); const [{ value: incidents, loading, error }, getIncidents] = useAsyncFn( - async () => await api.getIncidentsByServiceId(serviceId), + async () => { + const { incidents: foundIncidents } = await api.getIncidentsByServiceId( + serviceId, + ); + return foundIncidents; + }, ); useEffect(() => { diff --git a/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx b/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx index 68eea5990c..dce1bb536a 100644 --- a/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx +++ b/plugins/pagerduty/src/components/PagerDutyCard/index.test.tsx @@ -92,7 +92,7 @@ const service: Service = { const mockPagerDutyApi: Partial = { getServiceByEntity: async () => ({ service }), getOnCallByPolicyId: async () => [], - getIncidentsByServiceId: async () => [], + getIncidentsByServiceId: async () => ({ incidents: [] }), }; const apis = TestApiRegistry.from(