Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cnasikas committed Sep 1, 2020
1 parent 945abbd commit a3eb0ef
Show file tree
Hide file tree
Showing 11 changed files with 153 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ const pushToServiceHandler = async ({
currentIncident = await externalService.getIncident(externalId);
} catch (ex) {
logger.debug(
`Retrieving Incident by id ${externalId} from ServiceNow was failed with exception: ${ex}`
`Retrieving Incident by id ${externalId} from Jira was failed with exception: ${ex}`
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
* you may not use this file except in compliance with the Elastic License.
*/

/* eslint-disable @typescript-eslint/no-explicit-any */

import { TypeOf } from '@kbn/config-schema';
import {
ExecutorSubActionGetIncidentParamsSchema,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { CommentSchema, EntityInformation, IncidentConfigurationSchema } from '.
export const ExternalIncidentServiceConfiguration = {
apiUrl: schema.string(),
projectKey: schema.string(),
// TODO: to remove - set it optional for the current stage to support Case ServiceNow implementation
// TODO: to remove - set it optional for the current stage to support Case Jira implementation
incidentConfiguration: schema.nullable(IncidentConfigurationSchema),
isCaseOwned: schema.maybe(schema.boolean()),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ describe('api', () => {
expect(externalService.updateIncident).not.toHaveBeenCalled();
});

test('it calls updateIncident correctly', async () => {
test('it calls updateIncident correctly when creating an incident and having comments', async () => {
const params = { ...apiParams, externalId: null };
await api.pushToService({
externalService,
Expand All @@ -103,7 +103,7 @@ describe('api', () => {
expect(externalService.updateIncident).toHaveBeenCalledTimes(2);
expect(externalService.updateIncident).toHaveBeenNthCalledWith(1, {
incident: {
comments: 'A comment',
comments: 'A comment (added at 2020-03-13T08:34:53.450Z by Elastic User)',
description:
'Incident description (created at 2020-03-13T08:34:53.450Z by Elastic User)',
short_description:
Expand All @@ -114,7 +114,7 @@ describe('api', () => {

expect(externalService.updateIncident).toHaveBeenNthCalledWith(2, {
incident: {
comments: 'Another comment',
comments: 'Another comment (added at 2020-03-13T08:34:53.450Z by Elastic User)',
description:
'Incident description (created at 2020-03-13T08:34:53.450Z by Elastic User)',
short_description:
Expand Down Expand Up @@ -215,7 +215,7 @@ describe('api', () => {

expect(externalService.updateIncident).toHaveBeenNthCalledWith(2, {
incident: {
comments: 'A comment',
comments: 'A comment (added at 2020-03-13T08:34:53.450Z by Elastic User)',
description:
'Incident description (updated at 2020-03-13T08:34:53.450Z by Elastic User)',
short_description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { JiraActionConnector, CasesConfigurationMapping } from './types';
import { connectorConfiguration } from './config';
import { FieldMapping } from './case_mappings/field_mapping';

const ServiceNowConnectorFields: React.FC<ActionConnectorFieldsProps<JiraActionConnector>> = ({
const JiraConnectorFields: React.FC<ActionConnectorFieldsProps<JiraActionConnector>> = ({
action,
editActionSecrets,
editActionConfig,
Expand All @@ -30,7 +30,7 @@ const ServiceNowConnectorFields: React.FC<ActionConnectorFieldsProps<JiraActionC
readOnly,
docLinks,
}) => {
// TODO: remove incidentConfiguration later, when Case ServiceNow will move their fields to the level of action execution
// TODO: remove incidentConfiguration later, when Case Jira will move their fields to the level of action execution
const { apiUrl, projectKey, incidentConfiguration, isCaseOwned } = action.config;
const mapping = incidentConfiguration ? incidentConfiguration.mapping : [];

Expand Down Expand Up @@ -185,7 +185,7 @@ const ServiceNowConnectorFields: React.FC<ActionConnectorFieldsProps<JiraActionC
</EuiFormRow>
</EuiFlexItem>
</EuiFlexGroup>
{consumer === 'case' && ( // TODO: remove this block later, when Case ServiceNow will move their fields to the level of action execution
{consumer === 'case' && ( // TODO: remove this block later, when Case Jira will move their fields to the level of action execution
<>
<EuiSpacer size="l" />
<EuiFlexGroup>
Expand Down Expand Up @@ -215,4 +215,4 @@ export const createDefaultMapping = (fields: Record<string, any>): CasesConfigur
);

// eslint-disable-next-line import/no-default-export
export { ServiceNowConnectorFields as default };
export { JiraConnectorFields as default };
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ describe('JiraParamsFields renders', () => {
};

beforeEach(() => {
// jest.resetAllMocks();
useGetIssueTypesMock.mockReturnValue(useGetIssueTypesResponse);
useGetFieldsByIssueTypeMock.mockReturnValue(useGetFieldsByIssueTypeResponse);
});

test('all params fields is rendered', () => {
test('all params fields are rendered', () => {
const wrapper = mountWithIntl(
<JiraParamsFields
actionParams={actionParams}
Expand All @@ -109,7 +108,7 @@ describe('JiraParamsFields renders', () => {
expect(wrapper.find('[data-test-subj="commentsTextArea"]').length > 0).toBeTruthy();
});

test('hide issue types and fields when loading issue types', () => {
test('it shows loading when loading issue types', () => {
useGetIssueTypesMock.mockReturnValue({ ...useGetIssueTypesResponse, isLoading: true });
const wrapper = mountWithIntl(
<JiraParamsFields
Expand All @@ -122,20 +121,18 @@ describe('JiraParamsFields renders', () => {
actionConnector={connector}
/>
);
expect(wrapper.find('[data-test-subj="issueTypeSelect"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="prioritySelect"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="titleInput"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="descriptionTextArea"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="labelsComboBox"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="commentsTextArea"]').exists()).toBeFalsy();

expect(
wrapper.find('[data-test-subj="issueTypeSelect"]').first().prop('isLoading')
).toBeTruthy();
});

test('hide fields when loading fields', () => {
useGetIssueTypesMock.mockReturnValue(useGetIssueTypesResponse);
test('it shows loading when loading fields', () => {
useGetFieldsByIssueTypeMock.mockReturnValue({
...useGetFieldsByIssueTypeResponse,
isLoading: true,
});

const wrapper = mountWithIntl(
<JiraParamsFields
actionParams={actionParams}
Expand All @@ -147,12 +144,64 @@ describe('JiraParamsFields renders', () => {
actionConnector={connector}
/>
);
expect(wrapper.find('[data-test-subj="issueTypeSelect"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="prioritySelect"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="titleInput"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="descriptionTextArea"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="labelsComboBox"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="commentsTextArea"]').exists()).toBeFalsy();

expect(
wrapper.find('[data-test-subj="prioritySelect"]').first().prop('isLoading')
).toBeTruthy();
expect(
wrapper.find('[data-test-subj="labelsComboBox"]').first().prop('isLoading')
).toBeTruthy();
});

test('it disabled the fields when loading issue types', () => {
useGetIssueTypesMock.mockReturnValue({ ...useGetIssueTypesResponse, isLoading: true });

const wrapper = mountWithIntl(
<JiraParamsFields
actionParams={actionParams}
errors={{ title: [] }}
editAction={() => {}}
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
actionConnector={connector}
/>
);

expect(
wrapper.find('[data-test-subj="issueTypeSelect"]').first().prop('disabled')
).toBeTruthy();
expect(wrapper.find('[data-test-subj="prioritySelect"]').first().prop('disabled')).toBeTruthy();
expect(
wrapper.find('[data-test-subj="labelsComboBox"]').first().prop('isDisabled')
).toBeTruthy();
});

test('it disabled the fields when loading fields', () => {
useGetFieldsByIssueTypeMock.mockReturnValue({
...useGetFieldsByIssueTypeResponse,
isLoading: true,
});

const wrapper = mountWithIntl(
<JiraParamsFields
actionParams={actionParams}
errors={{ title: [] }}
editAction={() => {}}
index={0}
messageVariables={[]}
docLinks={{ ELASTIC_WEBSITE_URL: '', DOC_LINK_VERSION: '' } as DocLinksStart}
actionConnector={connector}
/>
);

expect(
wrapper.find('[data-test-subj="issueTypeSelect"]').first().prop('disabled')
).toBeTruthy();
expect(wrapper.find('[data-test-subj="prioritySelect"]').first().prop('disabled')).toBeTruthy();
expect(
wrapper.find('[data-test-subj="labelsComboBox"]').first().prop('isDisabled')
).toBeTruthy();
});

test('hide unsupported fields', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const mapping = [
export default function jiraTest({ getService }: FtrProviderContext) {
const supertest = getService('supertest');
const kibanaServer = getService('kibanaServer');
const mockServiceNow = {
const mockJira = {
config: {
apiUrl: 'www.jiraisinkibanaactions.com',
incidentConfiguration: { mapping: [...mapping] },
Expand Down Expand Up @@ -81,10 +81,10 @@ export default function jiraTest({ getService }: FtrProviderContext) {
config: {
apiUrl: jiraSimulatorURL,
projectKey: 'CK',
incidentConfiguration: { ...mockServiceNow.config.incidentConfiguration },
incidentConfiguration: { ...mockJira.config.incidentConfiguration },
isCaseOwned: true,
},
secrets: mockServiceNow.secrets,
secrets: mockJira.secrets,
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,57 @@ export function initPlugin(router: IRouter, path: string) {
});
}
);

router.get(
{
path: `${path}/rest/capabilities`,
options: {
authRequired: false,
},
validate: {},
},
async function (
context: RequestHandlerContext,
req: KibanaRequest<any, any, any, any>,
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
return jsonResponse(res, 200, {
capabilities: {},
});
}
);

router.get(
{
path: `${path}/rest/api/2/issue/createmeta`,
options: {
authRequired: false,
},
validate: {},
},
async function (
context: RequestHandlerContext,
req: KibanaRequest<any, any, any, any>,
res: KibanaResponseFactory
): Promise<IKibanaResponse<any>> {
return jsonResponse(res, 200, {
projects: [
{
issuetypes: [
{
id: '10006',
name: 'Task',
},
{
id: '10007',
name: 'Sub-task',
},
],
},
],
});
}
);
}

function jsonResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export function getAllExternalServiceSimulatorPaths(): string[] {
);
allPaths.push(`/api/_${NAME}/${ExternalServiceSimulator.SERVICENOW}/api/now/v2/table/incident`);
allPaths.push(`/api/_${NAME}/${ExternalServiceSimulator.JIRA}/rest/api/2/issue`);
allPaths.push(`/api/_${NAME}/${ExternalServiceSimulator.JIRA}/rest/api/2/createmeta`);
allPaths.push(`/api/_${NAME}/${ExternalServiceSimulator.RESILIENT}/rest/orgs/201/incidents`);
return allPaths;
}
Expand Down
Loading

0 comments on commit a3eb0ef

Please sign in to comment.