From 3113c0288f433665dcf6392d859569a65760d26a Mon Sep 17 00:00:00 2001 From: Yulong Ruan Date: Wed, 17 Jul 2024 22:27:12 +0800 Subject: [PATCH] fix tests Signed-off-by: Yulong Ruan --- .../data/common/search/opensearch_search/types.ts | 2 -- src/plugins/data/server/search/routes/search.test.ts | 10 ++++++++-- src/plugins/data/server/search/types.ts | 4 +++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/plugins/data/common/search/opensearch_search/types.ts b/src/plugins/data/common/search/opensearch_search/types.ts index 58090c7f00bb..f90a3f1de245 100644 --- a/src/plugins/data/common/search/opensearch_search/types.ts +++ b/src/plugins/data/common/search/opensearch_search/types.ts @@ -31,7 +31,6 @@ import { SearchResponse } from 'elasticsearch'; import { Search } from '@opensearch-project/opensearch/api/requestParams'; import { IOpenSearchDashboardsSearchRequest, IOpenSearchDashboardsSearchResponse } from '../types'; -import { OpenSearchDashboardsRequest } from '../../../../../../src/core/server'; export const OPENSEARCH_SEARCH_STRATEGY = 'opensearch'; export const OPENSEARCH_SEARCH_WITH_LONG_NUMERALS_STRATEGY = 'opensearch-with-long-numerals'; @@ -60,7 +59,6 @@ export interface IOpenSearchSearchRequest indexType?: string; language?: string; dataSourceId?: string; - rawRequest?: OpenSearchDashboardsRequest; } export type IOpenSearchSearchResponse = IOpenSearchDashboardsSearchResponse< diff --git a/src/plugins/data/server/search/routes/search.test.ts b/src/plugins/data/server/search/routes/search.test.ts index 12afc8a577f9..d31d443dcef8 100644 --- a/src/plugins/data/server/search/routes/search.test.ts +++ b/src/plugins/data/server/search/routes/search.test.ts @@ -94,7 +94,10 @@ describe('Search service', () => { await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse); expect(mockDataStart.search.search).toBeCalled(); - expect(mockDataStart.search.search.mock.calls[0][1]).toStrictEqual(mockBody); + expect(mockDataStart.search.search.mock.calls[0][1]).toStrictEqual({ + ...mockBody, + rawRequest: mockRequest, + }); expect(mockResponse.ok).toBeCalled(); expect(mockResponse.ok.mock.calls[0][0]).toEqual({ body: response, @@ -125,7 +128,10 @@ describe('Search service', () => { await handler((mockContext as unknown) as RequestHandlerContext, mockRequest, mockResponse); expect(mockDataStart.search.search).toBeCalled(); - expect(mockDataStart.search.search.mock.calls[0][1]).toStrictEqual(mockBody); + expect(mockDataStart.search.search.mock.calls[0][1]).toStrictEqual({ + ...mockBody, + rawRequest: mockRequest, + }); expect(mockResponse.customError).toBeCalled(); const error: any = mockResponse.customError.mock.calls[0][0]; expect(error.body.message).toBe('oh no'); diff --git a/src/plugins/data/server/search/types.ts b/src/plugins/data/server/search/types.ts index 6927d1289673..c50006023727 100644 --- a/src/plugins/data/server/search/types.ts +++ b/src/plugins/data/server/search/types.ts @@ -72,7 +72,9 @@ export interface ISearchSetup { } export interface ISearchStart< - SearchStrategyRequest extends IOpenSearchDashboardsSearchRequest = IOpenSearchSearchRequest, + SearchStrategyRequest extends IOpenSearchDashboardsSearchRequest = IOpenSearchSearchRequest & { + rawRequest?: OpenSearchDashboardsRequest; + }, SearchStrategyResponse extends IOpenSearchDashboardsSearchResponse = IOpenSearchSearchResponse > { aggs: AggsStart;