diff --git a/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/__tests__/utils.test.ts b/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/__tests__/utils.test.ts index 8b28c55a910d..5673e83e96cf 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/__tests__/utils.test.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/__tests__/utils.test.ts @@ -4,7 +4,34 @@ import { it, } from '@jest/globals'; -import { isKeyShapeValid } from '../utils'; +import { isKeyShapeValid, normalizeKey } from '../utils'; + +describe('normalizeKey', () => { + it('returns a string key as-is', () => { + expect(normalizeKey('abc')).toBe('abc'); + }); + + it('returns a number key as-is', () => { + expect(normalizeKey(42)).toBe(42); + }); + + it('converts a single-element CompositeKeyPair array to an object', () => { + expect(normalizeKey([{ field: 'id', value: 1 }])).toEqual({ id: 1 }); + }); + + it('converts a multi-element CompositeKeyPair array to an object', () => { + const pairs = [ + { field: 'region', value: 'us' }, + { field: 'code', value: 100 }, + ]; + + expect(normalizeKey(pairs)).toEqual({ region: 'us', code: 100 }); + }); + + it('returns an empty object for an empty array', () => { + expect(normalizeKey([])).toEqual({}); + }); +}); describe('isKeyShapeValid', () => { describe('single-field keyExpr (string)', () => { diff --git a/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/utils.ts b/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/utils.ts index cb5b7bd84923..23bcee852150 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/utils.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/commands/utils.ts @@ -9,7 +9,7 @@ export const compositeKeyPairSchema = z.object({ value: z.union([z.string(), z.number()]), }).strict(); -export const compositeKeyToObject = ( +const compositeKeyToObject = ( pairs: CompositeKeyPair[], ): Record => { const result: Record = {}; diff --git a/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/utils.ts b/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/utils.ts index 15d60da45f6a..66d4595dd08d 100644 --- a/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/utils.ts +++ b/packages/devextreme/js/__internal/grids/grid_core/ai_assistant/utils.ts @@ -52,10 +52,6 @@ export const getMessageStatus = (commands: CommandResult[]): ResponseStatus => { }; /** - * Recursively converts JSON Schema array-style `type` - * (e.g. `{"type": ["string", "number"]}`) to the equivalent `anyOf` form - * (e.g. `{"anyOf": [{"type": "string"}, {"type": "number"}]}`). - * * Some structured-output APIs do not support array-style `type` fields * and require explicit `anyOf` instead. */