feat(plugins/pagerduty): update getIncidentsByServiceId response to be Promise<IncidentsResponse>
Signed-off-by: Alec Jacobs <cajacobs5401@gmail.com>
This commit is contained in:
@@ -88,14 +88,13 @@ export class PagerDutyClient implements PagerDutyApi {
|
||||
return response;
|
||||
}
|
||||
|
||||
async getIncidentsByServiceId(serviceId: string): Promise<Incident[]> {
|
||||
async getIncidentsByServiceId(serviceId: string): Promise<IncidentsResponse> {
|
||||
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<IncidentsResponse>(url);
|
||||
|
||||
return incidents;
|
||||
return await this.getByUrl<IncidentsResponse>(url);
|
||||
}
|
||||
|
||||
async getChangeEventsByServiceId(serviceId: string): Promise<ChangeEvent[]> {
|
||||
|
||||
@@ -38,7 +38,7 @@ export interface PagerDutyApi {
|
||||
* Fetches a list of incidents a provided service has.
|
||||
*
|
||||
*/
|
||||
getIncidentsByServiceId(serviceId: string): Promise<Incident[]>;
|
||||
getIncidentsByServiceId(serviceId: string): Promise<IncidentsResponse>;
|
||||
|
||||
/**
|
||||
* Fetches a list of change events a provided service has.
|
||||
|
||||
@@ -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(
|
||||
<ApiProvider apis={apis}>
|
||||
|
||||
@@ -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(() => {
|
||||
|
||||
@@ -92,7 +92,7 @@ const service: Service = {
|
||||
const mockPagerDutyApi: Partial<PagerDutyClient> = {
|
||||
getServiceByEntity: async () => ({ service }),
|
||||
getOnCallByPolicyId: async () => [],
|
||||
getIncidentsByServiceId: async () => [],
|
||||
getIncidentsByServiceId: async () => ({ incidents: [] }),
|
||||
};
|
||||
|
||||
const apis = TestApiRegistry.from(
|
||||
|
||||
Reference in New Issue
Block a user