feat(plugins/pagerduty): update getOnCallByPolicyId response to be Promise<OnCallsResponse>

Signed-off-by: Alec Jacobs <cajacobs5401@gmail.com>
This commit is contained in:
Alec Jacobs
2022-06-03 17:05:34 -07:00
parent 7378e1710c
commit 48a7d96e72
5 changed files with 19 additions and 18 deletions
+2 -3
View File
@@ -108,14 +108,13 @@ export class PagerDutyClient implements PagerDutyApi {
return await this.getByUrl<ChangeEventsResponse>(url);
}
async getOnCallByPolicyId(policyId: string): Promise<OnCall[]> {
async getOnCallByPolicyId(policyId: string): Promise<OnCallsResponse> {
const params = `time_zone=UTC&include[]=users&escalation_policy_ids[]=${policyId}`;
const url = `${await this.config.discoveryApi.getBaseUrl(
'proxy',
)}/pagerduty/oncalls?${params}`;
const { oncalls } = await this.getByUrl<OnCallsResponse>(url);
return oncalls;
return await this.getByUrl<OnCallsResponse>(url);
}
triggerAlarm(request: TriggerAlarmRequest): Promise<Response> {
+1 -1
View File
@@ -50,7 +50,7 @@ export interface PagerDutyApi {
* Fetches the list of users in an escalation policy.
*
*/
getOnCallByPolicyId(policyId: string): Promise<OnCall[]>;
getOnCallByPolicyId(policyId: string): Promise<OnCallsResponse>;
/**
* Triggers an incident to whoever is on-call.
@@ -30,7 +30,7 @@ describe('Escalation', () => {
it('Handles an empty response', async () => {
mockPagerDutyApi.getOnCallByPolicyId = jest
.fn()
.mockImplementationOnce(async () => []);
.mockImplementationOnce(async () => ({ oncalls: [] }));
const { getByText, queryByTestId } = render(
wrapInTestApp(
@@ -48,17 +48,19 @@ describe('Escalation', () => {
it('Render a list of users', async () => {
mockPagerDutyApi.getOnCallByPolicyId = jest
.fn()
.mockImplementationOnce(async () => [
{
user: {
name: 'person1',
id: 'p1',
summary: 'person1',
email: 'person1@example.com',
html_url: 'http://a.com/id1',
} as User,
},
]);
.mockImplementationOnce(async () => ({
oncalls: [
{
user: {
name: 'person1',
id: 'p1',
summary: 'person1',
email: 'person1@example.com',
html_url: 'http://a.com/id1',
} as User,
},
],
}));
const { getByText, queryByTestId } = render(
wrapInTestApp(
@@ -37,7 +37,7 @@ export const EscalationPolicy = ({ policyId }: Props) => {
loading,
error,
} = useAsync(async () => {
const oncalls = await api.getOnCallByPolicyId(policyId);
const { oncalls } = await api.getOnCallByPolicyId(policyId);
const usersItem = oncalls
.sort((a, b) => a.escalation_level - b.escalation_level)
.map(oncall => oncall.user);
@@ -91,7 +91,7 @@ const service: Service = {
const mockPagerDutyApi: Partial<PagerDutyClient> = {
getServiceByEntity: async () => ({ service }),
getOnCallByPolicyId: async () => [],
getOnCallByPolicyId: async () => ({ oncalls: [] }),
getIncidentsByServiceId: async () => ({ incidents: [] }),
};