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] Integrate putUpdateNative with Connectors API (elastic#175536)
## Summary - Use Connectors API endpoint `_connector/{id}/_native` to update connector `is_native` flag
- Loading branch information
Showing
2 changed files
with
73 additions
and
9 deletions.
There are no files selected for viewing
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,67 @@ | ||
/* | ||
* 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 { putUpdateNative } from './update_native'; | ||
|
||
describe('putUpdateNative lib function', () => { | ||
const mockClient = { | ||
transport: { | ||
request: jest.fn(), | ||
}, | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should update connector is_native flag', async () => { | ||
mockClient.transport.request.mockImplementation(() => ({ result: 'updated' })); | ||
|
||
await expect( | ||
putUpdateNative(mockClient as unknown as ElasticsearchClient, 'connectorId', true) | ||
).resolves.toEqual({ result: 'updated' }); | ||
expect(mockClient.transport.request).toHaveBeenCalledWith({ | ||
body: { | ||
is_native: true, | ||
}, | ||
method: 'PUT', | ||
path: '/_connector/connectorId/_native', | ||
}); | ||
}); | ||
|
||
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( | ||
putUpdateNative(mockClient as unknown as ElasticsearchClient, 'connectorId', true) | ||
).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