feat(plugins/pagerduty): update getOnCallByPolicyId response to be Promise<OnCallsResponse>
Signed-off-by: Alec Jacobs <cajacobs5401@gmail.com>
This commit is contained in:
@@ -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> {
|
||||
|
||||
@@ -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: [] }),
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user