feat(plugins/pagerduty): update getChangeEventsByServiceId response to be Promise<ChangeEventsResponse>

Signed-off-by: Alec Jacobs <cajacobs5401@gmail.com>
This commit is contained in:
Alec Jacobs
2022-06-03 16:59:59 -07:00
parent 206fc1f601
commit 7378e1710c
4 changed files with 69 additions and 68 deletions
+4 -4
View File
@@ -97,15 +97,15 @@ export class PagerDutyClient implements PagerDutyApi {
return await this.getByUrl<IncidentsResponse>(url);
}
async getChangeEventsByServiceId(serviceId: string): Promise<ChangeEvent[]> {
async getChangeEventsByServiceId(
serviceId: string,
): Promise<ChangeEventsResponse> {
const params = `limit=5&time_zone=UTC&sort_by=timestamp`;
const url = `${await this.config.discoveryApi.getBaseUrl(
'proxy',
)}/pagerduty/services/${serviceId}/change_events?${params}`;
const { change_events } = await this.getByUrl<ChangeEventsResponse>(url);
return change_events;
return await this.getByUrl<ChangeEventsResponse>(url);
}
async getOnCallByPolicyId(policyId: string): Promise<OnCall[]> {
+1 -1
View File
@@ -44,7 +44,7 @@ export interface PagerDutyApi {
* Fetches a list of change events a provided service has.
*
*/
getChangeEventsByServiceId(serviceId: string): Promise<ChangeEvent[]>;
getChangeEventsByServiceId(serviceId: string): Promise<ChangeEventsResponse>;
/**
* Fetches the list of users in an escalation policy.
@@ -30,7 +30,7 @@ describe('Incidents', () => {
it('Renders an empty state when there are no change events', async () => {
mockPagerDutyApi.getChangeEventsByServiceId = jest
.fn()
.mockImplementationOnce(async () => []);
.mockImplementationOnce(async () => ({ change_events: [] }));
const { getByText, queryByTestId } = render(
wrapInTestApp(
@@ -46,37 +46,36 @@ describe('Incidents', () => {
it('Renders all change events', async () => {
mockPagerDutyApi.getChangeEventsByServiceId = jest
.fn()
.mockImplementationOnce(
async () =>
[
{
id: 'id1',
source: 'changeSource1',
html_url: 'www.pdlink.com',
links: [
{
href: 'www.externalLink1.com',
text: 'link1',
},
],
summary: 'summary of event',
timestamp: '2020-07-17T08:42:58.315+0000',
},
{
id: 'id2',
source: 'changeSource1',
html_url: 'www.pdlink.com/link',
links: [
{
href: 'www.externalLink1.com',
text: 'link1',
},
],
summary: 'sum of EVENT',
timestamp: '2020-07-18T08:42:58.315+0000',
},
] as ChangeEvent[],
);
.mockImplementationOnce(async () => ({
change_events: [
{
id: 'id1',
source: 'changeSource1',
html_url: 'www.pdlink.com',
links: [
{
href: 'www.externalLink1.com',
text: 'link1',
},
],
summary: 'summary of event',
timestamp: '2020-07-17T08:42:58.315+0000',
},
{
id: 'id2',
source: 'changeSource1',
html_url: 'www.pdlink.com/link',
links: [
{
href: 'www.externalLink1.com',
text: 'link1',
},
],
summary: 'sum of EVENT',
timestamp: '2020-07-18T08:42:58.315+0000',
},
] as ChangeEvent[],
}));
const { getByText, getAllByTitle, queryByTestId } = render(
wrapInTestApp(
<ApiProvider apis={apis}>
@@ -95,36 +94,35 @@ describe('Incidents', () => {
it('Does not render a pagerduty link when html_url is not present in response', async () => {
mockPagerDutyApi.getChangeEventsByServiceId = jest
.fn()
.mockImplementationOnce(
async () =>
[
{
id: 'id1',
source: 'changeSource1',
links: [
{
href: 'www.externalLink1.com',
text: 'link1',
},
],
summary: 'summary of event',
timestamp: '2020-07-17T08:42:58.315+0000',
},
{
id: 'id2',
source: 'changeSource1',
html_url: 'www.pdlink.com/link',
links: [
{
href: 'www.externalLink1.com',
text: 'link1',
},
],
summary: 'sum of EVENT',
timestamp: '2020-07-18T08:42:58.315+0000',
},
] as ChangeEvent[],
);
.mockImplementationOnce(async () => ({
change_events: [
{
id: 'id1',
source: 'changeSource1',
links: [
{
href: 'www.externalLink1.com',
text: 'link1',
},
],
summary: 'summary of event',
timestamp: '2020-07-17T08:42:58.315+0000',
},
{
id: 'id2',
source: 'changeSource1',
html_url: 'www.pdlink.com/link',
links: [
{
href: 'www.externalLink1.com',
text: 'link1',
},
],
summary: 'sum of EVENT',
timestamp: '2020-07-18T08:42:58.315+0000',
},
] as ChangeEvent[],
}));
const { getByText, getAllByTitle, queryByTestId } = render(
wrapInTestApp(
<ApiProvider apis={apis}>
@@ -33,7 +33,10 @@ export const ChangeEvents = ({ serviceId, refreshEvents }: Props) => {
const api = useApi(pagerDutyApiRef);
const [{ value: changeEvents, loading, error }, getChangeEvents] = useAsyncFn(
async () => await api.getChangeEventsByServiceId(serviceId),
async () => {
const { change_events } = await api.getChangeEventsByServiceId(serviceId);
return change_events;
},
);
useEffect(() => {