CoolFace
Datasetpublic

basant307/AI_Governance_Project

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