Skip to content

Commit

Permalink
[Search] Integrate deleteConnectorById with Connectors API (elastic#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
jedrazb authored Jan 23, 2024
1 parent 44a8198 commit 85be1f1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
21 changes: 12 additions & 9 deletions packages/kbn-search-connectors/lib/delete_connector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

import { ElasticsearchClient } from '@kbn/core/server';

import { CONNECTORS_INDEX } from '..';

import { deleteConnectorById } from './delete_connector';

jest.mock('./cancel_syncs', () => ({
Expand All @@ -19,7 +17,9 @@ import { cancelSyncs } from './cancel_syncs';

describe('deleteConnector lib function', () => {
const mockClient = {
delete: jest.fn(),
transport: {
request: jest.fn(),
},
};

beforeEach(() => {
Expand All @@ -28,14 +28,17 @@ describe('deleteConnector lib function', () => {
});

it('should delete connector and cancel syncs', async () => {
mockClient.delete.mockImplementation(() => true);
mockClient.transport.request.mockImplementation(() => ({
acknowledged: true,
}));

await deleteConnectorById(mockClient as unknown as ElasticsearchClient, 'connectorId');
await expect(
deleteConnectorById(mockClient as unknown as ElasticsearchClient, 'connectorId')
).resolves.toEqual({ acknowledged: true });
expect(cancelSyncs as jest.Mock).toHaveBeenCalledWith(mockClient, 'connectorId');
expect(mockClient.delete).toHaveBeenCalledWith({
id: 'connectorId',
index: CONNECTORS_INDEX,
refresh: 'wait_for',
expect(mockClient.transport.request).toHaveBeenCalledWith({
method: 'DELETE',
path: '/_connector/connectorId',
});
jest.useRealTimers();
});
Expand Down
7 changes: 5 additions & 2 deletions packages/kbn-search-connectors/lib/delete_connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
* Side Public License, v 1.
*/

import { AcknowledgedResponseBase } from '@elastic/elasticsearch/lib/api/types';
import { ElasticsearchClient } from '@kbn/core-elasticsearch-server';
import { CONNECTORS_INDEX } from '..';
import { cancelSyncs } from './cancel_syncs';

export const deleteConnectorById = async (client: ElasticsearchClient, id: string) => {
Expand All @@ -17,5 +17,8 @@ export const deleteConnectorById = async (client: ElasticsearchClient, id: strin
return promise;
};
await Promise.all([cancelSyncs(client, id), timeout]);
return await client.delete({ id, index: CONNECTORS_INDEX, refresh: 'wait_for' });
return await client.transport.request<AcknowledgedResponseBase>({
method: 'DELETE',
path: `/_connector/${id}`,
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { EuiConfirmModal, EuiFieldText, EuiForm, EuiFormRow } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { Connector } from '@kbn/search-connectors';
import { AcknowledgedResponseBase } from '@elastic/elasticsearch/lib/api/types';
import { useMutation } from '@tanstack/react-query';
import React, { useEffect, useState } from 'react';
import { useKibanaServices } from '../../hooks/use_kibana';
Expand All @@ -28,10 +28,10 @@ export const DeleteConnectorModal: React.FC<DeleteConnectorModalProps> = ({
const { http } = useKibanaServices();
const { isLoading, isSuccess, mutate } = useMutation({
mutationFn: async () => {
const result = await http.delete<{ connector: Connector }>(
const result = await http.delete<AcknowledgedResponseBase>(
`/internal/serverless_search/connectors/${connectorId}`
);
return result.connector;
return result.acknowledged;
},
});

Expand Down

0 comments on commit 85be1f1

Please sign in to comment.