Skip to content

Commit 74714d8

Browse files
authored
AI Assistant: improve utils test coverage (#33622)
1 parent 685ce5f commit 74714d8

3 files changed

Lines changed: 29 additions & 6 deletions

File tree

packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/__tests__/utils.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,34 @@ import {
44
it,
55
} from '@jest/globals';
66

7-
import { isKeyShapeValid } from '../utils';
7+
import { isKeyShapeValid, normalizeKey } from '../utils';
8+
9+
describe('normalizeKey', () => {
10+
it('returns a string key as-is', () => {
11+
expect(normalizeKey('abc')).toBe('abc');
12+
});
13+
14+
it('returns a number key as-is', () => {
15+
expect(normalizeKey(42)).toBe(42);
16+
});
17+
18+
it('converts a single-element CompositeKeyPair array to an object', () => {
19+
expect(normalizeKey([{ field: 'id', value: 1 }])).toEqual({ id: 1 });
20+
});
21+
22+
it('converts a multi-element CompositeKeyPair array to an object', () => {
23+
const pairs = [
24+
{ field: 'region', value: 'us' },
25+
{ field: 'code', value: 100 },
26+
];
27+
28+
expect(normalizeKey(pairs)).toEqual({ region: 'us', code: 100 });
29+
});
30+
31+
it('returns an empty object for an empty array', () => {
32+
expect(normalizeKey([])).toEqual({});
33+
});
34+
});
835

936
describe('isKeyShapeValid', () => {
1037
describe('single-field keyExpr (string)', () => {

packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const compositeKeyPairSchema = z.object({
99
value: z.union([z.string(), z.number()]),
1010
}).strict();
1111

12-
export const compositeKeyToObject = (
12+
const compositeKeyToObject = (
1313
pairs: CompositeKeyPair[],
1414
): Record<string, string | number> => {
1515
const result: Record<string, string | number> = {};

packages/devextreme/js/__internal/grids/grid_core/ai_assistant/utils.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ export const getMessageStatus = (commands: CommandResult[]): ResponseStatus => {
5252
};
5353

5454
/**
55-
* Recursively converts JSON Schema array-style `type`
56-
* (e.g. `{"type": ["string", "number"]}`) to the equivalent `anyOf` form
57-
* (e.g. `{"anyOf": [{"type": "string"}, {"type": "number"}]}`).
58-
*
5955
* Some structured-output APIs do not support array-style `type` fields
6056
* and require explicit `anyOf` instead.
6157
*/

0 commit comments

Comments
 (0)