Skip to content

Commit

Permalink
[8.x] [ResponseOps][Connectors]Possible to open close incident in Ser…
Browse files Browse the repository at this point in the history
…viceNow (#199989) (#200726)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ResponseOps][Connectors]Possible to open close incident in
ServiceNow (#199989)](#199989)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Georgiana-Andreea
Onoleață","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-11-19T12:48:30Z","message":"[ResponseOps][Connectors]Possible
to open close incident in ServiceNow (#199989)\n\nCloses
https://github.com/elastic/kibana/issues/184646\r\n\r\n##
Summary\r\n\r\n- updated the code to include additional validation,
ensuring that\r\nupdateIncident({...}) is not called when
incidentToBeClosed object is\r\nempty, this ensured that cases where
getIncident or\r\ngetIncidentByCorrelationId return an empty object are
properly handled.\r\n\r\n- small change in Run connector flyout >
configuration tab: fixed typo,\r\n\"read-only\" instead of
\"readonly\"","sha":"5d77a1a67c5eb243b14ea0613e411cc13ec73406","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:ResponseOps","v9.0.0","backport:prev-minor","v8.17.0"],"title":"[ResponseOps][Connectors]Possible
to open close incident in
ServiceNow","number":199989,"url":"https://github.com/elastic/kibana/pull/199989","mergeCommit":{"message":"[ResponseOps][Connectors]Possible
to open close incident in ServiceNow (#199989)\n\nCloses
https://github.com/elastic/kibana/issues/184646\r\n\r\n##
Summary\r\n\r\n- updated the code to include additional validation,
ensuring that\r\nupdateIncident({...}) is not called when
incidentToBeClosed object is\r\nempty, this ensured that cases where
getIncident or\r\ngetIncidentByCorrelationId return an empty object are
properly handled.\r\n\r\n- small change in Run connector flyout >
configuration tab: fixed typo,\r\n\"read-only\" instead of
\"readonly\"","sha":"5d77a1a67c5eb243b14ea0613e411cc13ec73406"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/199989","number":199989,"mergeCommit":{"message":"[ResponseOps][Connectors]Possible
to open close incident in ServiceNow (#199989)\n\nCloses
https://github.com/elastic/kibana/issues/184646\r\n\r\n##
Summary\r\n\r\n- updated the code to include additional validation,
ensuring that\r\nupdateIncident({...}) is not called when
incidentToBeClosed object is\r\nempty, this ensured that cases where
getIncident or\r\ngetIncidentByCorrelationId return an empty object are
properly handled.\r\n\r\n- small change in Run connector flyout >
configuration tab: fixed typo,\r\n\"read-only\" instead of
\"readonly\"","sha":"5d77a1a67c5eb243b14ea0613e411cc13ec73406"}},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Georgiana-Andreea Onoleață <[email protected]>
  • Loading branch information
kibanamachine and georgianaonoleata1904 authored Nov 26, 2024
1 parent 7bcf7b1 commit e006f0d
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,23 @@ describe('ServiceNow service', () => {
`);
});

test('it should return null if no incident found, when incident to be closed is null', async () => {
requestMock.mockImplementationOnce(() => ({
data: {
result: [],
},
}));

const res = await service.closeIncident({ incidentId: '2', correlationId: null });
expect(logger.warn.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"[ServiceNow][CloseIncident] No incident found with correlation_id: null or incidentId: 2.",
]
`);

expect(res).toBeNull();
});

test('it should return null if found incident with correlation id is null', async () => {
requestMock.mockImplementationOnce(() => ({
data: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { AxiosResponse } from 'axios';

import { request } from '@kbn/actions-plugin/server/lib/axios_utils';
import { isEmpty } from 'lodash';
import {
ExternalService,
ExternalServiceParamsCreate,
Expand Down Expand Up @@ -306,7 +307,7 @@ export const createExternalService: ServiceFactory = ({
incidentToBeClosed = await getIncidentByCorrelationId(correlationId);
}

if (incidentToBeClosed === null) {
if (incidentToBeClosed === null || isEmpty(incidentToBeClosed)) {
logger.warn(
`[ServiceNow][CloseIncident] No incident found with correlation_id: ${correlationId} or incidentId: ${incidentId}.`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe('EditConnectorFlyout', () => {
});

await waitFor(() => {
expect(queryByText('This connector is readonly.')).not.toBeInTheDocument();
expect(queryByText('This connector is read-only.')).not.toBeInTheDocument();
expect(getByTestId('nameInput')).toHaveValue('My test');
expect(getByTestId('test-connector-text-field')).toHaveValue('My text field');
});
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('EditConnectorFlyout', () => {
/>
);

expect(getByText('This connector is readonly.')).toBeInTheDocument();
expect(getByText('This connector is read-only.')).toBeInTheDocument();
});

it('shows the buttons', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ describe('ReadOnlyConnectorMessage', () => {
{ wrapper: I18nProvider }
);

expect(getByText('This connector is readonly.')).toBeInTheDocument();
expect(getByText('This connector is read-only.')).toBeInTheDocument();
expect(getByTestId('read-only-link')).toHaveProperty('href', 'https://example.com/');
expect(queryByText('Extra Component')).toBeNull();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ReadOnlyConnectorMessage: React.FC<{
<>
<EuiText>
{i18n.translate('xpack.triggersActionsUI.sections.editConnectorForm.descriptionText', {
defaultMessage: 'This connector is readonly.',
defaultMessage: 'This connector is read-only.',
})}
</EuiText>
<EuiLink data-test-subj="read-only-link" href={href} target="_blank">
Expand Down

0 comments on commit e006f0d

Please sign in to comment.