Skip to content

Commit

Permalink
jira refactor, rename from commonFields to getFields
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Nov 5, 2020
1 parent a4bc031 commit 6a19a04
Show file tree
Hide file tree
Showing 27 changed files with 165 additions and 215 deletions.
24 changes: 12 additions & 12 deletions x-pack/plugins/actions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,21 +69,21 @@ Table of Contents
- [`secrets`](#secrets-6)
- [`params`](#params-6)
- [`subActionParams (pushToService)`](#subactionparams-pushtoservice)
- [`subActionParams (commonFields)`](#subactionparams-commonfields-1)
- [`subActionParams (getFields)`](#subactionparams-getfields-1)
- [Jira](#jira)
- [`config`](#config-7)
- [`secrets`](#secrets-7)
- [`params`](#params-7)
- [`subActionParams (pushToService)`](#subactionparams-pushtoservice-1)
- [`subActionParams (issueTypes)`](#subactionparams-issuetypes)
- [`subActionParams (commonFields)`](#subactionparams-commonfields-2)
- [`subActionParams (getFields)`](#subactionparams-getfields-2)
- [`subActionParams (pushToService)`](#subactionparams-pushtoservice-2)
- [IBM Resilient](#ibm-resilient)
- [`config`](#config-8)
- [`secrets`](#secrets-8)
- [`params`](#params-8)
- [`subActionParams (pushToService)`](#subactionparams-pushtoservice-3)
- [`subActionParams (commonFields)`](#subactionparams-commonfields-3)
- [`subActionParams (getFields)`](#subactionparams-getfields-3)
- [Command Line Utility](#command-line-utility)
- [Developing New Action Types](#developing-new-action-types)
- [licensing](#licensing)
Expand Down Expand Up @@ -566,7 +566,7 @@ The ServiceNow action uses the [V2 Table API](https://developer.servicenow.com/a

| Property | Description | Type |
| --------------- | ------------------------------------------------------------------------------------ | ------ |
| subAction | The sub action to perform. It can be `commonFields`, `pushToService`, `handshake`, and `getIncident` | string |
| subAction | The sub action to perform. It can be `getFields`, `pushToService`, `handshake`, and `getIncident` | string |
| subActionParams | The parameters of the sub action | object |

#### `subActionParams (pushToService)`
Expand All @@ -583,9 +583,9 @@ The ServiceNow action uses the [V2 Table API](https://developer.servicenow.com/a
| urgency | The name of the urgency in ServiceNow. | string _(optional)_ |
| impact | The name of the impact in ServiceNow. | string _(optional)_ |

#### `subActionParams (commonFields)`
#### `subActionParams (getFields)`

No parameters for `commonFields` sub-action. Provide an empty object `{}`.
No parameters for `getFields` sub-action. Provide an empty object `{}`.

---

Expand Down Expand Up @@ -613,7 +613,7 @@ The Jira action uses the [V2 API](https://developer.atlassian.com/cloud/jira/pla

| Property | Description | Type |
| --------------- | ----------------------------------------------------------------------------------------------------------------------- | ------ |
| subAction | The sub action to perform. It can be `commonFields`, `pushToService`, `handshake`, `getIncident`, `issueTypes`, and `fieldsByIssueType` | string |
| subAction | The sub action to perform. It can be `getFields`, `pushToService`, `handshake`, `getIncident`, `issueTypes`, and `fieldsByIssueType` | string |
| subActionParams | The parameters of the sub action | object |

#### `subActionParams (pushToService)`
Expand All @@ -634,9 +634,9 @@ The Jira action uses the [V2 API](https://developer.atlassian.com/cloud/jira/pla

No parameters for `issueTypes` sub-action. Provide an empty object `{}`.

#### `subActionParams (commonFields)`
#### `subActionParams (getFields)`

No parameters for `commonFields` sub-action. Provide an empty object `{}`.
No parameters for `getFields` sub-action. Provide an empty object `{}`.

#### `subActionParams (pushToService)`

Expand Down Expand Up @@ -666,7 +666,7 @@ ID: `.resilient`

| Property | Description | Type |
| --------------- | ------------------------------------------------------------------------------------ | ------ |
| subAction | The sub action to perform. It can be `commonFields`, `pushToService`, `handshake`, and `getIncident` | string |
| subAction | The sub action to perform. It can be `getFields`, `pushToService`, `handshake`, and `getIncident` | string |
| subActionParams | The parameters of the sub action | object |

#### `subActionParams (pushToService)`
Expand All @@ -681,9 +681,9 @@ ID: `.resilient`
| incidentTypes | An array with the ids of IBM Resilient incident types. | number[] _(optional)_ |
| severityCode | IBM Resilient id of the severity code. | number _(optional)_ |

#### `subActionParams (commonFields)`
#### `subActionParams (getFields)`

No parameters for `commonFields` sub-action. Provide an empty object `{}`.
No parameters for `getFields` sub-action. Provide an empty object `{}`.

# Command Line Utility

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

import { Logger } from '../../../../../../src/core/server';
import { externalServiceMock, mapping, apiParams, jiraCommonFields } from './mocks';
import { externalServiceMock, mapping, apiParams } from './mocks';
import { ExternalService } from './types';
import { api } from './api';
let mockedLogger: jest.Mocked<Logger>;
Expand Down Expand Up @@ -382,16 +382,6 @@ describe('api', () => {
});
});

describe('commonFields', () => {
test('it returns the fields correctly', async () => {
const res = await api.commonFields({
externalService,
params: {},
});
expect(res).toEqual(jiraCommonFields);
});
});

describe('getIssues', () => {
test('it returns the issues correctly', async () => {
const res = await api.issues({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const getIssueTypesHandler = async ({ externalService }: GetIssueTypesHandlerArg
return res;
};

const getCommonFieldsHandler = async ({ externalService }: GetCommonFieldsHandlerArgs) => {
const res = await externalService.getCommonFields();
const getFieldsHandler = async ({ externalService }: GetCommonFieldsHandlerArgs) => {
const res = await externalService.getFields();
return res;
};

Expand Down Expand Up @@ -163,7 +163,7 @@ const pushToServiceHandler = async ({
};

export const api: ExternalServiceApi = {
commonFields: getCommonFieldsHandler,
getFields: getFieldsHandler,
handshake: handshakeHandler,
pushToService: pushToServiceHandler,
getIncident: getIncidentHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface GetActionTypeParams {
}

const supportedSubActions: string[] = [
'commonFields',
'getFields',
'pushToService',
'issueTypes',
'fieldsByIssueType',
Expand Down Expand Up @@ -146,8 +146,8 @@ async function executor(
});
}

if (subAction === 'commonFields') {
data = await api.commonFields({
if (subAction === 'getFields') {
data = await api.getFields({
externalService,
params: subActionParams,
});
Expand Down
72 changes: 2 additions & 70 deletions x-pack/plugins/actions/server/builtin_action_types/jira/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ const createMock = (): jest.Mocked<ExternalService> => {
key: 'RJ-107',
title: 'Test title',
})),
getCommonFields: jest.fn().mockImplementation(() => jiraCommonFields),
getFields: jest.fn().mockImplementation(() => jiraCommonFields),
};

service.createComment.mockImplementationOnce(() =>
Expand All @@ -98,74 +98,6 @@ const createMock = (): jest.Mocked<ExternalService> => {
const externalServiceMock = {
create: createMock,
};
const jiraFields = [
{
id: 'issuetype',
key: 'issuetype',
name: 'Issue Type',
custom: false,
orderable: true,
navigable: true,
searchable: true,
clauseNames: ['issuetype', 'type'],
schema: { type: 'issuetype', system: 'issuetype' },
},
{
id: 'parent',
key: 'parent',
name: 'Parent',
custom: false,
orderable: false,
navigable: true,
searchable: false,
clauseNames: ['parent'],
},
{
id: 'summary',
key: 'summary',
name: 'Summary',
custom: false,
orderable: true,
navigable: true,
searchable: true,
clauseNames: ['summary'],
schema: { type: 'string', system: 'summary' },
},
{
id: 'reporter',
key: 'reporter',
name: 'Reporter',
custom: false,
orderable: true,
navigable: true,
searchable: true,
clauseNames: ['reporter'],
schema: { type: 'user', system: 'reporter' },
},
{
id: 'priority',
key: 'priority',
name: 'Priority',
custom: false,
orderable: true,
navigable: true,
searchable: true,
clauseNames: ['priority'],
schema: { type: 'priority', system: 'priority' },
},
{
id: 'description',
key: 'description',
name: 'Description',
custom: false,
orderable: true,
navigable: true,
searchable: true,
clauseNames: ['description'],
schema: { type: 'string', system: 'description' },
},
];
const jiraCommonFields = jiraFields.filter(({ id }) => id === 'summary' || id === 'description');
const mapping: Map<string, Partial<MapRecord>> = new Map();

mapping.set('title', {
Expand Down Expand Up @@ -226,4 +158,4 @@ const apiParams: PushToServiceApiParams = {
externalObject: { summary: 'Incident title', description: 'Incident description' },
};

export { jiraCommonFields, jiraFields, externalServiceMock, mapping, executorParams, apiParams };
export { externalServiceMock, mapping, executorParams, apiParams };
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const ExecutorSubActionGetIssueParamsSchema = schema.object({ id: schema.

export const ExecutorParamsSchema = schema.oneOf([
schema.object({
subAction: schema.literal('commonFields'),
subAction: schema.literal('getFields'),
subActionParams: ExecutorSubActionCommonFieldsParamsSchema,
}),
schema.object({
Expand Down
Loading

0 comments on commit 6a19a04

Please sign in to comment.