Skip to content

Commit

Permalink
[ResponseOps][Connectors]Possible to open close incident in ServiceNow (
Browse files Browse the repository at this point in the history
elastic#199989)

Closes elastic#184646

## Summary

- updated the code to include additional validation, ensuring that
updateIncident({...}) is not called when incidentToBeClosed object is
empty, this ensured that cases where getIncident or
getIncidentByCorrelationId return an empty object are properly handled.

- small change in Run connector flyout > configuration tab: fixed typo,
"read-only" instead of "readonly"
  • Loading branch information
georgianaonoleata1904 authored and CAWilson94 committed Dec 12, 2024
1 parent a97b357 commit 1e0a4ce
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 1e0a4ce

Please sign in to comment.