1+ import { describe , it , expect , beforeEach , afterEach } from "vitest" ;
2+ import { loadApiKeyFromEnv } from "../lib/utils" ;
3+
4+ describe ( "Google API Key Enviroment Variable" , ( ) => {
5+ const originalEnv = process . env ;
6+
7+ beforeEach ( ( ) => {
8+ process . env = { ...originalEnv } ;
9+ } ) ;
10+
11+ afterEach ( ( ) => {
12+ process . env = originalEnv ;
13+ } ) ;
14+
15+ it ( "should read GOOGLE_API_KEY for google provider" , ( ) => {
16+ process . env . GOOGLE_API_KEY = "test-google-key" ;
17+
18+ const apiKey = loadApiKeyFromEnv ( "google" , ( ) => { } ) ;
19+
20+ expect ( apiKey ) . toBe ( "test-google-key" ) ;
21+ } ) ;
22+
23+ it ( "should read GEMINI_API_KEY for google provider" , ( ) => {
24+ process . env . GEMINI_API_KEY = "test-gemini-key" ;
25+
26+ const apiKey = loadApiKeyFromEnv ( "google" , ( ) => { } ) ;
27+
28+ expect ( apiKey ) . toBe ( "test-gemini-key" ) ;
29+ } ) ;
30+
31+ it ( "should read GOOGLE_GENERATIVE_AI_API_KEY for google provider" , ( ) => {
32+ process . env . GOOGLE_GENERATIVE_AI_API_KEY = "test-gen-ai-key" ;
33+
34+ const apiKey = loadApiKeyFromEnv ( "google" , ( ) => { } ) ;
35+
36+ expect ( apiKey ) . toBe ( "test-gen-ai-key" ) ;
37+ } ) ;
38+
39+ it ( "should prioritize GEMINI_API_KEY over GOOGLE_API_KEY" , ( ) => {
40+ process . env . GEMINI_API_KEY = "gemini-key" ;
41+ process . env . GOOGLE_API_KEY = "google-key" ;
42+
43+ const apiKey = loadApiKeyFromEnv ( "google" , ( ) => { } ) ;
44+
45+ expect ( apiKey ) . toBe ( "gemini-key" )
46+ } ) ;
47+ } ) ;
0 commit comments