diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/capabilities/capabilities.test.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/capabilities/capabilities.test.tsx index 30c113eb0e8036..b41d7ac1445549 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/capabilities/capabilities.test.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/capabilities/capabilities.test.tsx @@ -13,7 +13,7 @@ import { API_ERROR } from '../../translations'; jest.mock('@kbn/core-http-browser'); const mockHttp = { - get: jest.fn(), + fetch: jest.fn(), } as unknown as HttpSetup; describe('Capabilities API tests', () => { @@ -25,14 +25,15 @@ describe('Capabilities API tests', () => { it('calls the internal assistant API for fetching assistant capabilities', async () => { await getCapabilities({ http: mockHttp }); - expect(mockHttp.get).toHaveBeenCalledWith('/internal/elastic_assistant/capabilities', { + expect(mockHttp.fetch).toHaveBeenCalledWith('/internal/elastic_assistant/capabilities', { + method: 'GET', signal: undefined, version: '1', }); }); it('returns API_ERROR when the response status is error', async () => { - (mockHttp.get as jest.Mock).mockResolvedValue({ status: API_ERROR }); + (mockHttp.fetch as jest.Mock).mockResolvedValue({ status: API_ERROR }); const result = await getCapabilities({ http: mockHttp }); diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/capabilities/capabilities.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/capabilities/capabilities.tsx index 96e6660f6bc0ef..59927dbf2c4721 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/capabilities/capabilities.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/capabilities/capabilities.tsx @@ -6,7 +6,7 @@ */ import { HttpSetup, IHttpFetchError } from '@kbn/core-http-browser'; -import { API_VERSIONS, GetCapabilitiesResponse } from '@kbn/elastic-assistant-common'; +import { GetCapabilitiesResponse } from '@kbn/elastic-assistant-common'; export interface GetCapabilitiesParams { http: HttpSetup; @@ -29,10 +29,13 @@ export const getCapabilities = async ({ try { const path = `/internal/elastic_assistant/capabilities`; - return await http.get(path, { + const response = await http.fetch(path, { + method: 'GET', signal, - version: API_VERSIONS.internal.v1, + version: '1', }); + + return response as GetCapabilitiesResponse; } catch (error) { return error as IHttpFetchError; } diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/capabilities/use_capabilities.test.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/capabilities/use_capabilities.test.tsx index b7648983e6f7ad..c9e60b806d1bf3 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/capabilities/use_capabilities.test.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/capabilities/use_capabilities.test.tsx @@ -11,12 +11,11 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import type { ReactNode } from 'react'; import React from 'react'; import { useCapabilities, UseCapabilitiesParams } from './use_capabilities'; -import { API_VERSIONS } from '@kbn/elastic-assistant-common'; const statusResponse = { assistantModelEvaluation: true, assistantStreamingEnabled: false }; const http = { - get: jest.fn().mockResolvedValue(statusResponse), + fetch: jest.fn().mockResolvedValue(statusResponse), }; const toasts = { addError: jest.fn(), @@ -37,10 +36,14 @@ describe('useFetchRelatedCases', () => { wrapper: createWrapper(), }); - expect(defaultProps.http.get).toHaveBeenCalledWith('/internal/elastic_assistant/capabilities', { - version: API_VERSIONS.internal.v1, - signal: new AbortController().signal, - }); + expect(defaultProps.http.fetch).toHaveBeenCalledWith( + '/internal/elastic_assistant/capabilities', + { + method: 'GET', + version: '1', + signal: new AbortController().signal, + } + ); expect(toasts.addError).not.toHaveBeenCalled(); }); }); diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/evaluate/evaluate.test.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/evaluate/evaluate.test.tsx index d25953370e97ad..0ba1c7d76f981b 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/evaluate/evaluate.test.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/evaluate/evaluate.test.tsx @@ -7,17 +7,16 @@ import { postEvaluation } from './evaluate'; import { HttpSetup } from '@kbn/core-http-browser'; -import { API_VERSIONS } from '@kbn/elastic-assistant-common'; jest.mock('@kbn/core-http-browser'); const mockHttp = { - post: jest.fn(), + fetch: jest.fn(), } as unknown as HttpSetup; describe('postEvaluation', () => { it('calls the knowledge base API when correct resource path', async () => { - (mockHttp.post as jest.Mock).mockResolvedValue({ success: true }); + (mockHttp.fetch as jest.Mock).mockResolvedValue({ success: true }); const testProps = { http: mockHttp, evalParams: { @@ -36,7 +35,8 @@ describe('postEvaluation', () => { await postEvaluation(testProps); - expect(mockHttp.post).toHaveBeenCalledWith('/internal/elastic_assistant/evaluate', { + expect(mockHttp.fetch).toHaveBeenCalledWith('/internal/elastic_assistant/evaluate', { + method: 'POST', body: '{"dataset":{},"evalPrompt":"evalPrompt"}', headers: { 'Content-Type': 'application/json' }, query: { @@ -50,12 +50,11 @@ describe('postEvaluation', () => { runName: 'Test Run Name', }, signal: undefined, - version: API_VERSIONS.internal.v1, }); }); it('returns error when error is an error', async () => { const error = 'simulated error'; - (mockHttp.post as jest.Mock).mockImplementation(() => { + (mockHttp.fetch as jest.Mock).mockImplementation(() => { throw new Error(error); }); diff --git a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/evaluate/evaluate.tsx b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/evaluate/evaluate.tsx index 6581e22e77921a..7e4f8ed732331b 100644 --- a/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/evaluate/evaluate.tsx +++ b/x-pack/packages/kbn-elastic-assistant/impl/assistant/api/evaluate/evaluate.tsx @@ -47,7 +47,8 @@ export const postEvaluation = async ({ runName: evalParams?.runName, }; - return await http.post(path, { + const response = await http.fetch(path, { + method: 'POST', body: JSON.stringify({ dataset: JSON.parse(evalParams?.dataset ?? '[]'), evalPrompt: evalParams?.evalPrompt ?? '', @@ -57,8 +58,9 @@ export const postEvaluation = async ({ }, query, signal, - version: API_VERSIONS.internal.v1, }); + + return response as PostEvaluateResponse; } catch (error) { return error as IHttpFetchError; } @@ -85,7 +87,8 @@ export const getEvaluation = async ({ try { const path = `/internal/elastic_assistant/evaluate`; - return await http.get(path, { + return await http.fetch(path, { + method: 'GET', signal, version: API_VERSIONS.internal.v1, }); diff --git a/x-pack/plugins/elastic_assistant/server/routes/evaluate/post_evaluate.test.ts b/x-pack/plugins/elastic_assistant/server/routes/evaluate/post_evaluate.test.ts index e580c00a0b0eb1..64ec69fa5e943d 100644 --- a/x-pack/plugins/elastic_assistant/server/routes/evaluate/post_evaluate.test.ts +++ b/x-pack/plugins/elastic_assistant/server/routes/evaluate/post_evaluate.test.ts @@ -9,13 +9,17 @@ import { postEvaluateRoute } from './post_evaluate'; import { serverMock } from '../../__mocks__/server'; import { requestContextMock } from '../../__mocks__/request_context'; import { getPostEvaluateRequest } from '../../__mocks__/request'; +import type { + PostEvaluateRequestBodyInput, + PostEvaluateRequestQueryInput, +} from '@kbn/elastic-assistant-common'; -const defaultBody = { +const defaultBody: PostEvaluateRequestBodyInput = { dataset: undefined, evalPrompt: undefined, }; -const defaultQueryParams = { +const defaultQueryParams: PostEvaluateRequestQueryInput = { agents: 'agents', datasetName: undefined, evaluationType: undefined, @@ -26,7 +30,7 @@ const defaultQueryParams = { runName: undefined, }; -describe.skip('Post Evaluate Route', () => { +describe('Post Evaluate Route', () => { let server: ReturnType; let { context } = requestContextMock.createTools(); const mockGetElser = jest.fn().mockResolvedValue('.elser_model_2');