diff --git a/src/platform/plugins/shared/data/common/search/expressions/esql.test.ts b/src/platform/plugins/shared/data/common/search/expressions/esql.test.ts new file mode 100644 index 0000000000000..8bdf796dc575e --- /dev/null +++ b/src/platform/plugins/shared/data/common/search/expressions/esql.test.ts @@ -0,0 +1,51 @@ +/* + * 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", the "GNU Affero General Public License v3.0 only", 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", the "GNU Affero General Public + * License v3.0 only", or the "Server Side Public License, v 1". + */ + +import { of } from 'rxjs'; +import { UiSettingsCommon } from '@kbn/data-views-plugin/common'; +import { getEsqlFn } from './esql'; +import { ExecutionContext } from '@kbn/expressions-plugin/common'; +import { ESQLSearchResponse } from '@kbn/es-types'; +import { IKibanaSearchResponse } from '@kbn/search-types'; + +describe('getEsqlFn', () => { + it('should always return a fully serializable table', async () => { + const mockSearch = jest.fn().mockReturnValue( + of({ + rawResponse: { + values: [['value1']], + columns: [{ name: 'column1', type: 'string' }], + }, + } as IKibanaSearchResponse) + ); + + const esqlFn = getEsqlFn({ + getStartDependencies: async () => ({ + search: mockSearch, + uiSettings: {} as UiSettingsCommon, + }), + }); + + const input = null; // Mock input + const args = { + query: 'SELECT * FROM index', + }; + + const context = { + abortSignal: new AbortController().signal, + inspectorAdapters: {}, + getKibanaRequest: jest.fn(), + } as unknown as ExecutionContext; + + const result = await esqlFn.fn(input, args, context).toPromise(); + + expect(result?.type).toEqual('datatable'); + expect(() => JSON.stringify(result)).not.toThrow(); + }); +}); diff --git a/src/platform/plugins/shared/data/common/search/expressions/esql.ts b/src/platform/plugins/shared/data/common/search/expressions/esql.ts index b2c6c15ad2426..327641e460af1 100644 --- a/src/platform/plugins/shared/data/common/search/expressions/esql.ts +++ b/src/platform/plugins/shared/data/common/search/expressions/esql.ts @@ -345,8 +345,8 @@ export const getEsqlFn = ({ getStartDependencies }: EsqlFnArguments) => { const appliedTimeRange = input?.timeRange ? { - from: DateMath.parse(input.timeRange.from), - to: DateMath.parse(input.timeRange.to, { roundUp: true }), + from: DateMath.parse(input.timeRange.from)?.toISOString(), + to: DateMath.parse(input.timeRange.to, { roundUp: true })?.toISOString(), } : undefined;