forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Search] Use Connector API for update_service_type (elastic#176306)
## Summary Use connectors API for update service type operation
- Loading branch information
Showing
2 changed files
with
104 additions
and
31 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
packages/kbn-search-connectors/lib/update_connector_service_type.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { ElasticsearchClient } from '@kbn/core/server'; | ||
|
||
import { errors } from '@elastic/elasticsearch'; | ||
|
||
import { updateConnectorServiceType } from './update_connector_service_type'; | ||
|
||
describe('updateConnectorServiceType lib function', () => { | ||
const mockClient = { | ||
transport: { | ||
request: jest.fn(), | ||
}, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should update connector service type', async () => { | ||
mockClient.transport.request.mockImplementation(() => ({ result: 'updated' })); | ||
|
||
const connectorId = 'connectorId'; | ||
const serviceType = 'new-service-type'; | ||
|
||
const result = await updateConnectorServiceType( | ||
mockClient as unknown as ElasticsearchClient, | ||
connectorId, | ||
serviceType | ||
); | ||
expect(result).toEqual({ result: 'updated' }); | ||
|
||
expect(mockClient.transport.request).toHaveBeenNthCalledWith(1, { | ||
method: 'PUT', | ||
path: `/_connector/${connectorId}/_configuration`, | ||
body: { | ||
configuration: {}, | ||
}, | ||
}); | ||
expect(mockClient.transport.request).toHaveBeenNthCalledWith(2, { | ||
method: 'PUT', | ||
path: `/_connector/${connectorId}/_service_type`, | ||
body: { | ||
service_type: serviceType, | ||
}, | ||
}); | ||
expect(mockClient.transport.request).toHaveBeenCalledTimes(2); | ||
}); | ||
|
||
it('should not index document if there is no connector', async () => { | ||
mockClient.transport.request.mockImplementationOnce(() => { | ||
return Promise.reject( | ||
new errors.ResponseError({ | ||
statusCode: 404, | ||
body: { | ||
error: { | ||
type: `document_missing_exception`, | ||
}, | ||
}, | ||
} as any) | ||
); | ||
}); | ||
await expect( | ||
updateConnectorServiceType( | ||
mockClient as unknown as ElasticsearchClient, | ||
'connectorId', | ||
'new-service-type' | ||
) | ||
).rejects.toEqual( | ||
new errors.ResponseError({ | ||
statusCode: 404, | ||
body: { | ||
error: { | ||
type: `document_missing_exception`, | ||
}, | ||
}, | ||
} as any) | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters