-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '8.11' into backport/8.11/pr-169708
- Loading branch information
Showing
31 changed files
with
351 additions
and
14 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Large diffs are not rendered by default.
Oops, something went wrong.
79 changes: 79 additions & 0 deletions
79
x-pack/plugins/elastic_assistant/server/lib/executor.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,79 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { executeAction } from './executor'; | ||
import { KibanaRequest } from '@kbn/core-http-server'; | ||
import { RequestBody } from './langchain/types'; | ||
import { PluginStartContract as ActionsPluginStart } from '@kbn/actions-plugin/server'; | ||
const request = { | ||
body: { | ||
params: {}, | ||
}, | ||
} as KibanaRequest<unknown, unknown, RequestBody>; | ||
|
||
describe('executeAction', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
it('should execute an action with the provided connectorId and request body params', async () => { | ||
const actions = { | ||
getActionsClientWithRequest: jest.fn().mockResolvedValue({ | ||
execute: jest.fn().mockResolvedValue({ | ||
status: 'ok', | ||
data: { | ||
message: 'Test message', | ||
}, | ||
}), | ||
}), | ||
} as unknown as ActionsPluginStart; | ||
|
||
const connectorId = '12345'; | ||
|
||
const response = await executeAction({ actions, request, connectorId }); | ||
|
||
expect(actions.getActionsClientWithRequest).toHaveBeenCalledWith(request); | ||
expect(actions.getActionsClientWithRequest).toHaveBeenCalledTimes(1); | ||
expect(response.connector_id).toBe(connectorId); | ||
expect(response.data).toBe('Test message'); | ||
expect(response.status).toBe('ok'); | ||
}); | ||
|
||
it('should throw an error if action result status is "error"', async () => { | ||
const actions = { | ||
getActionsClientWithRequest: jest.fn().mockResolvedValue({ | ||
execute: jest.fn().mockResolvedValue({ | ||
status: 'error', | ||
message: 'Error message', | ||
serviceMessage: 'Service error message', | ||
}), | ||
}), | ||
} as unknown as ActionsPluginStart; | ||
const connectorId = '12345'; | ||
|
||
await expect(executeAction({ actions, request, connectorId })).rejects.toThrowError( | ||
'Action result status is error: Error message - Service error message' | ||
); | ||
}); | ||
|
||
it('should throw an error if content of response data is not a string', async () => { | ||
const actions = { | ||
getActionsClientWithRequest: jest.fn().mockResolvedValue({ | ||
execute: jest.fn().mockResolvedValue({ | ||
status: 'ok', | ||
data: { | ||
message: 12345, | ||
}, | ||
}), | ||
}), | ||
} as unknown as ActionsPluginStart; | ||
const connectorId = '12345'; | ||
|
||
await expect(executeAction({ actions, request, connectorId })).rejects.toThrowError( | ||
'Action result status is error: content should be a string, but it had an unexpected type: number' | ||
); | ||
}); | ||
}); |
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
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
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