Skip to content
Draft
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,38 @@
import { describe, it, expect } from 'vitest';
import {
EventMetadataKey,
getEventMetadataKey,
} from './event-metadata-key.js';

describe('getEventMetadataKey', () => {
it('should return the correct enum value for a valid key name', () => {
expect(getEventMetadataKey('GEMINI_CLI_START_SESSION_MODEL')).toBe(
EventMetadataKey.GEMINI_CLI_START_SESSION_MODEL,
);
expect(getEventMetadataKey('GEMINI_CLI_USER_PROMPT_LENGTH')).toBe(
EventMetadataKey.GEMINI_CLI_USER_PROMPT_LENGTH,
);
expect(getEventMetadataKey('GEMINI_CLI_END_SESSION_ID')).toBe(
EventMetadataKey.GEMINI_CLI_END_SESSION_ID,
);
});

it('should return undefined for an invalid key name', () => {
expect(getEventMetadataKey('INVALID_KEY_NAME')).toBeUndefined();
expect(getEventMetadataKey('')).toBeUndefined();
expect(getEventMetadataKey(' ')).toBeUndefined();
});

it('should return undefined for a number passed as a string', () => {
// EventMetadataKey[1] is 'GEMINI_CLI_START_SESSION_MODEL' in standard TS enums,
// but getEventMetadataKey should return undefined because typeof 'GEMINI_CLI_START_SESSION_MODEL' is string, not number.
expect(getEventMetadataKey('1')).toBeUndefined();
expect(getEventMetadataKey('0')).toBeUndefined();
});

it('should return undefined for built-in object properties', () => {
expect(getEventMetadataKey('toString')).toBeUndefined();
expect(getEventMetadataKey('valueOf')).toBeUndefined();
expect(getEventMetadataKey('__proto__')).toBeUndefined();
});
});
2 changes: 1 addition & 1 deletion packages/core/src/utils/errors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
BadRequestError,
UnauthorizedError,
ForbiddenError,
} from './errors';
} from './errors.js';

describe('toFriendlyError', () => {
it('should return the original error if it is not an object', () => {
Expand Down