Skip to content

Commit

Permalink
change send_pagerduty to post_pagerduty
Browse files Browse the repository at this point in the history
  • Loading branch information
pmuellr committed Aug 22, 2019
1 parent 047fef7 commit 36456f0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
import axios, { AxiosResponse } from 'axios';
import { Services } from '../../types';

interface SendPagerdutyOptions {
interface PostPagerdutyOptions {
apiUrl: string;
data: any;
headers: Record<string, string>;
services: Services;
}

// post an event to pagerduty
export async function sendPagerduty(options: SendPagerdutyOptions): Promise<AxiosResponse> {
export async function postPagerduty(options: PostPagerdutyOptions): Promise<AxiosResponse> {
const { apiUrl, data, headers } = options;
const axiosOptions = {
headers,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

jest.mock('./lib/send_pagerduty', () => ({
sendPagerduty: jest.fn(),
jest.mock('./lib/post_pagerduty', () => ({
postPagerduty: jest.fn(),
}));

import { ActionType, Services, ActionTypeExecutorOptions } from '../types';
Expand All @@ -14,10 +14,10 @@ import { taskManagerMock } from '../../../task_manager/task_manager.mock';
import { encryptedSavedObjectsMock } from '../../../encrypted_saved_objects/server/plugin.mock';
import { validateConfig, validateSecrets, validateParams } from '../lib';
import { SavedObjectsClientMock } from '../../../../../../src/core/server/mocks';
import { sendPagerduty } from './lib/send_pagerduty';
import { postPagerduty } from './lib/post_pagerduty';
import { registerBuiltInActionTypes } from './index';

const sendPagerdutyMock = sendPagerduty as jest.Mock;
const postPagerdutyMock = postPagerduty as jest.Mock;

const ACTION_TYPE_ID = '.pagerduty';
const NO_OP_FN = () => {};
Expand Down Expand Up @@ -137,22 +137,22 @@ describe('validateParams()', () => {

describe('execute()', () => {
beforeEach(() => {
sendPagerdutyMock.mockReset();
postPagerdutyMock.mockReset();
});

test('should succeed with minimal valid params', async () => {
const secrets = { routingKey: 'super-secret' };
const config = {};
const params = {};

sendPagerdutyMock.mockImplementation(() => {
postPagerdutyMock.mockImplementation(() => {
return { status: 202, data: 'data-here' };
});

const id = 'some-action-id';
const executorOptions: ActionTypeExecutorOptions = { id, config, params, secrets, services };
const actionResponse = await actionType.executor(executorOptions);
const { apiUrl, data, headers } = sendPagerdutyMock.mock.calls[0][0];
const { apiUrl, data, headers } = postPagerdutyMock.mock.calls[0][0];
expect({ apiUrl, data, headers }).toMatchInlineSnapshot(`
Object {
"apiUrl": "https://events.pagerduty.com/v2/enqueue",
Expand Down Expand Up @@ -199,14 +199,14 @@ describe('execute()', () => {
class: 'the-class',
};

sendPagerdutyMock.mockImplementation(() => {
postPagerdutyMock.mockImplementation(() => {
return { status: 202, data: 'data-here' };
});

const id = 'some-action-id';
const executorOptions: ActionTypeExecutorOptions = { id, config, params, secrets, services };
const actionResponse = await actionType.executor(executorOptions);
const { apiUrl, data, headers } = sendPagerdutyMock.mock.calls[0][0];
const { apiUrl, data, headers } = postPagerdutyMock.mock.calls[0][0];
expect({ apiUrl, data, headers }).toMatchInlineSnapshot(`
Object {
"apiUrl": "the-api-url",
Expand Down Expand Up @@ -257,14 +257,14 @@ describe('execute()', () => {
class: 'the-class',
};

sendPagerdutyMock.mockImplementation(() => {
postPagerdutyMock.mockImplementation(() => {
return { status: 202, data: 'data-here' };
});

const id = 'some-action-id';
const executorOptions: ActionTypeExecutorOptions = { id, config, params, secrets, services };
const actionResponse = await actionType.executor(executorOptions);
const { apiUrl, data, headers } = sendPagerdutyMock.mock.calls[0][0];
const { apiUrl, data, headers } = postPagerdutyMock.mock.calls[0][0];
expect({ apiUrl, data, headers }).toMatchInlineSnapshot(`
Object {
"apiUrl": "the-api-url",
Expand Down Expand Up @@ -306,14 +306,14 @@ describe('execute()', () => {
class: 'the-class',
};

sendPagerdutyMock.mockImplementation(() => {
postPagerdutyMock.mockImplementation(() => {
return { status: 202, data: 'data-here' };
});

const id = 'some-action-id';
const executorOptions: ActionTypeExecutorOptions = { id, config, params, secrets, services };
const actionResponse = await actionType.executor(executorOptions);
const { apiUrl, data, headers } = sendPagerdutyMock.mock.calls[0][0];
const { apiUrl, data, headers } = postPagerdutyMock.mock.calls[0][0];
expect({ apiUrl, data, headers }).toMatchInlineSnapshot(`
Object {
"apiUrl": "the-api-url",
Expand All @@ -340,7 +340,7 @@ describe('execute()', () => {
const config = {};
const params = {};

sendPagerdutyMock.mockImplementation(() => {
postPagerdutyMock.mockImplementation(() => {
throw new Error('doing some testing');
});

Expand All @@ -360,7 +360,7 @@ describe('execute()', () => {
const config = {};
const params = {};

sendPagerdutyMock.mockImplementation(() => {
postPagerdutyMock.mockImplementation(() => {
return { status: 429, data: 'data-here' };
});

Expand All @@ -381,7 +381,7 @@ describe('execute()', () => {
const config = {};
const params = {};

sendPagerdutyMock.mockImplementation(() => {
postPagerdutyMock.mockImplementation(() => {
return { status: 501, data: 'data-here' };
});

Expand All @@ -402,7 +402,7 @@ describe('execute()', () => {
const config = {};
const params = {};

sendPagerdutyMock.mockImplementation(() => {
postPagerdutyMock.mockImplementation(() => {
return { status: 418, data: 'data-here' };
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { i18n } from '@kbn/i18n';
import { schema, TypeOf } from '@kbn/config-schema';
import { sendPagerduty } from './lib/send_pagerduty';
import { postPagerduty } from './lib/post_pagerduty';
import { ActionType, ActionTypeExecutorOptions, ActionTypeExecutorResult } from '../types';

// uses the PagerDuty Events API v2
Expand Down Expand Up @@ -114,7 +114,7 @@ async function executor(execOptions: ActionTypeExecutorOptions): Promise<ActionT

let response;
try {
response = await sendPagerduty({ apiUrl, data, headers, services });
response = await postPagerduty({ apiUrl, data, headers, services });
} catch (err) {
const message = i18n.translate('xpack.actions.builtin.pagerduty.postingErrorMessage', {
defaultMessage: 'error in pagerduty action "{id}" posting event: {errorMessage}',
Expand Down

0 comments on commit 36456f0

Please sign in to comment.