Fix/lens serialize (#218082)

This commit is contained in:
Peter Pisljar 2025-04-15 10:48:43 +02:00 committed by GitHub
parent 3c1f04dbb4
commit 1017c22245
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 2 deletions

View file

@ -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();
});
});

View file

@ -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;