Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<ESQLSearchResponse>)
);

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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down