Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,43 @@ describe('Create case', () => {
).toBe(true);
});

it('should succeed even when pushing to an external service fails', async () => {
const failPushCaseToExternalService = jest.fn().mockRejectedValue(new Error('Push failed'));
usePostPushToServiceMock.mockImplementation(() => ({
isLoading: false,
isError: false,
mutateAsync: failPushCaseToExternalService,
}));

renderWithTestingProviders(
<FormContext
selectedOwner={SECURITY_SOLUTION_OWNER}
onSuccess={onFormSubmitSuccess}
afterCaseCreated={afterCaseCreated}
currentConfiguration={currentConfiguration}
>
<CreateCaseFormFields {...defaultCreateCaseForm} connectors={connectorsMock} />
<SubmitCaseButton />
</FormContext>
);

await waitForFormToRender();
await fillFormReactTestingLib({ user });

await user.click(screen.getByTestId('dropdown-connectors'));

await waitFor(() => {
expect(screen.getByTestId('dropdown-connector-resilient-2')).toBeInTheDocument();
});

await user.click(screen.getByTestId('dropdown-connector-resilient-2'));
await user.click(screen.getByTestId('create-case-submit'));

await waitFor(() => {
expect(onFormSubmitSuccess).toHaveBeenCalled();
});
});

describe('Permissions', () => {
it('should not push to service if the user does not have access to actions', async () => {
const coreStart = coreMock.createStart();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,18 @@ export const FormContext: React.FC<Props> = ({
}

if (theCase?.id && data.connector.id !== 'none') {
await pushCaseToExternalService({
caseId: theCase.id,
connector: data.connector,
});
try {
await pushCaseToExternalService({
caseId: theCase.id,
connector: data.connector,
});
} catch (error) {
// Catch the error but do not interrupt the flow.
// The case has been created successfully at this point.
// The only thing that failed was pushing to the external service.
// Changes to the connector fields can be made later on by the user.
// They will be notified about the connector failure.
}
}

if (onSuccess && theCase) {
Expand Down