mirror of
https://github.com/hyperdxio/hyperdx
synced 2026-04-21 13:37:15 +00:00
tests for buildJSONExtractQuery
This commit is contained in:
parent
a72a4e8378
commit
e0a8d59fef
2 changed files with 55 additions and 2 deletions
|
|
@ -1,7 +1,7 @@
|
|||
import React from 'react';
|
||||
import { fireEvent, screen, within } from '@testing-library/react';
|
||||
|
||||
import { DBRowJsonViewer } from './DBRowJsonViewer';
|
||||
import { buildJSONExtractQuery, DBRowJsonViewer } from './DBRowJsonViewer';
|
||||
import { RowSidePanelContext } from './DBRowSidePanel';
|
||||
|
||||
// Mock Next.js router
|
||||
|
|
@ -195,4 +195,57 @@ describe('DBRowJsonViewer', () => {
|
|||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('buildJSONExtractQuery', () => {
|
||||
it('returns null when keyPath equals parsedJsonRootPath (no nested path)', () => {
|
||||
expect(
|
||||
buildJSONExtractQuery(['LogAttributes'], ['LogAttributes']),
|
||||
).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null when keyPath is shorter than parsedJsonRootPath', () => {
|
||||
expect(buildJSONExtractQuery([], ['LogAttributes'])).toBeNull();
|
||||
});
|
||||
|
||||
it('builds query for single-level path with default JSONExtractString', () => {
|
||||
expect(
|
||||
buildJSONExtractQuery(['LogAttributes', 'field1'], ['LogAttributes']),
|
||||
).toBe("JSONExtractString(LogAttributes, 'field1')");
|
||||
});
|
||||
|
||||
it('builds query for nested path', () => {
|
||||
expect(
|
||||
buildJSONExtractQuery(
|
||||
['LogAttributes', 'nested', 'field3'],
|
||||
['LogAttributes'],
|
||||
),
|
||||
).toBe("JSONExtractString(LogAttributes, 'nested', 'field3')");
|
||||
});
|
||||
|
||||
it('uses JSONExtractFloat when specified', () => {
|
||||
expect(
|
||||
buildJSONExtractQuery(
|
||||
['SpanAttributes', 'count'],
|
||||
['SpanAttributes'],
|
||||
'JSONExtractFloat',
|
||||
),
|
||||
).toBe("JSONExtractFloat(SpanAttributes, 'count')");
|
||||
});
|
||||
|
||||
it('uses JSONExtractBool when specified', () => {
|
||||
expect(
|
||||
buildJSONExtractQuery(
|
||||
['LogAttributes', 'enabled'],
|
||||
['LogAttributes'],
|
||||
'JSONExtractBool',
|
||||
),
|
||||
).toBe("JSONExtractBool(LogAttributes, 'enabled')");
|
||||
});
|
||||
|
||||
it('handles path segments that look like array indices', () => {
|
||||
expect(
|
||||
buildJSONExtractQuery(['LogAttributes', '0', 'id'], ['LogAttributes']),
|
||||
).toBe("JSONExtractString(LogAttributes, '0', 'id')");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ type JSONExtractFn =
|
|||
| 'JSONExtractFloat'
|
||||
| 'JSONExtractBool';
|
||||
|
||||
function buildJSONExtractQuery(
|
||||
export function buildJSONExtractQuery(
|
||||
keyPath: string[],
|
||||
parsedJsonRootPath: string[],
|
||||
jsonExtractFn: JSONExtractFn = 'JSONExtractString',
|
||||
|
|
|
|||
Loading…
Reference in a new issue