1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
import { describe, it, expect } from 'vitest';
import { partListUnionToString } from './geminiRequest.js';
import { type Part } from '@google/genai';
describe('partListUnionToString', () => {
it('should return the string value if the input is a string', () => {
const result = partListUnionToString('hello');
expect(result).toBe('hello');
});
it('should return a concatenated string if the input is an array of strings', () => {
const result = partListUnionToString(['hello', ' ', 'world']);
expect(result).toBe('hello world');
});
it('should handle videoMetadata', () => {
const part: Part = { videoMetadata: {} };
const result = partListUnionToString(part);
expect(result).toBe('[Video Metadata]');
});
it('should handle thought', () => {
const part: Part = { thought: true };
const result = partListUnionToString(part);
expect(result).toBe('[Thought: true]');
});
it('should handle codeExecutionResult', () => {
const part: Part = { codeExecutionResult: {} };
const result = partListUnionToString(part);
expect(result).toBe('[Code Execution Result]');
});
it('should handle executableCode', () => {
const part: Part = { executableCode: {} };
const result = partListUnionToString(part);
expect(result).toBe('[Executable Code]');
});
it('should handle fileData', () => {
const part: Part = {
fileData: { mimeType: 'text/plain', fileUri: 'file.txt' },
};
const result = partListUnionToString(part);
expect(result).toBe('[File Data]');
});
it('should handle functionCall', () => {
const part: Part = { functionCall: { name: 'myFunction' } };
const result = partListUnionToString(part);
expect(result).toBe('[Function Call: myFunction]');
});
it('should handle functionResponse', () => {
const part: Part = {
functionResponse: { name: 'myFunction', response: {} },
};
const result = partListUnionToString(part);
expect(result).toBe('[Function Response: myFunction]');
});
it('should handle inlineData', () => {
const part: Part = { inlineData: { mimeType: 'image/png', data: '...' } };
const result = partListUnionToString(part);
expect(result).toBe('<image/png>');
});
it('should handle text', () => {
const part: Part = { text: 'hello' };
const result = partListUnionToString(part);
expect(result).toBe('hello');
});
it('should return an empty string for an unknown part type', () => {
const part: Part = {};
const result = partListUnionToString(part);
expect(result).toBe('');
});
});
|