@@ -18,6 +18,7 @@ describe('AuthDialog', () => {
1818 beforeEach ( ( ) => {
1919 originalEnv = { ...process . env } ;
2020 process . env . GEMINI_API_KEY = '' ;
21+ process . env . GEMINI_DEFAULT_AUTH_TYPE = '' ;
2122 vi . clearAllMocks ( ) ;
2223 } ) ;
2324
@@ -59,28 +60,165 @@ describe('AuthDialog', () => {
5960 ) ;
6061 } ) ;
6162
62- it ( 'should detect GEMINI_API_KEY environment variable' , ( ) => {
63- process . env . GEMINI_API_KEY = 'foobar' ;
63+ describe ( 'GEMINI_API_KEY environment variable' , ( ) => {
64+ it ( 'should detect GEMINI_API_KEY environment variable' , ( ) => {
65+ process . env . GEMINI_API_KEY = 'foobar' ;
6466
65- const settings : LoadedSettings = new LoadedSettings (
66- {
67- settings : {
68- selectedAuthType : undefined ,
67+ const settings : LoadedSettings = new LoadedSettings (
68+ {
69+ settings : {
70+ selectedAuthType : undefined ,
71+ } ,
72+ path : '' ,
6973 } ,
70- path : '' ,
71- } ,
72- {
73- settings : { } ,
74- path : '' ,
75- } ,
76- [ ] ,
77- ) ;
74+ {
75+ settings : { } ,
76+ path : '' ,
77+ } ,
78+ [ ] ,
79+ ) ;
7880
79- const { lastFrame } = render (
80- < AuthDialog onSelect = { ( ) => { } } settings = { settings } /> ,
81- ) ;
81+ const { lastFrame } = render (
82+ < AuthDialog onSelect = { ( ) => { } } settings = { settings } /> ,
83+ ) ;
84+
85+ expect ( lastFrame ( ) ) . toContain (
86+ 'Existing API key detected (GEMINI_API_KEY)' ,
87+ ) ;
88+ } ) ;
89+
90+ it ( 'should not show the GEMINI_API_KEY message if GEMINI_DEFAULT_AUTH_TYPE is set to something else' , ( ) => {
91+ process . env . GEMINI_API_KEY = 'foobar' ;
92+ process . env . GEMINI_DEFAULT_AUTH_TYPE = AuthType . LOGIN_WITH_GOOGLE ;
93+
94+ const settings : LoadedSettings = new LoadedSettings (
95+ {
96+ settings : {
97+ selectedAuthType : undefined ,
98+ } ,
99+ path : '' ,
100+ } ,
101+ {
102+ settings : { } ,
103+ path : '' ,
104+ } ,
105+ [ ] ,
106+ ) ;
107+
108+ const { lastFrame } = render (
109+ < AuthDialog onSelect = { ( ) => { } } settings = { settings } /> ,
110+ ) ;
111+
112+ expect ( lastFrame ( ) ) . not . toContain (
113+ 'Existing API key detected (GEMINI_API_KEY)' ,
114+ ) ;
115+ } ) ;
116+
117+ it ( 'should show the GEMINI_API_KEY message if GEMINI_DEFAULT_AUTH_TYPE is set to use api key' , ( ) => {
118+ process . env . GEMINI_API_KEY = 'foobar' ;
119+ process . env . GEMINI_DEFAULT_AUTH_TYPE = AuthType . USE_GEMINI ;
120+
121+ const settings : LoadedSettings = new LoadedSettings (
122+ {
123+ settings : {
124+ selectedAuthType : undefined ,
125+ } ,
126+ path : '' ,
127+ } ,
128+ {
129+ settings : { } ,
130+ path : '' ,
131+ } ,
132+ [ ] ,
133+ ) ;
134+
135+ const { lastFrame } = render (
136+ < AuthDialog onSelect = { ( ) => { } } settings = { settings } /> ,
137+ ) ;
138+
139+ expect ( lastFrame ( ) ) . toContain (
140+ 'Existing API key detected (GEMINI_API_KEY)' ,
141+ ) ;
142+ } ) ;
143+ } ) ;
144+
145+ describe ( 'GEMINI_DEFAULT_AUTH_TYPE environment variable' , ( ) => {
146+ it ( 'should select the auth type specified by GEMINI_DEFAULT_AUTH_TYPE' , ( ) => {
147+ process . env . GEMINI_DEFAULT_AUTH_TYPE = AuthType . LOGIN_WITH_GOOGLE ;
148+
149+ const settings : LoadedSettings = new LoadedSettings (
150+ {
151+ settings : {
152+ selectedAuthType : undefined ,
153+ } ,
154+ path : '' ,
155+ } ,
156+ {
157+ settings : { } ,
158+ path : '' ,
159+ } ,
160+ [ ] ,
161+ ) ;
162+
163+ const { lastFrame } = render (
164+ < AuthDialog onSelect = { ( ) => { } } settings = { settings } /> ,
165+ ) ;
166+
167+ // This is a bit brittle, but it's the best way to check which item is selected.
168+ expect ( lastFrame ( ) ) . toContain ( '● Login with Google' ) ;
169+ } ) ;
170+
171+ it ( 'should fall back to default if GEMINI_DEFAULT_AUTH_TYPE is not set' , ( ) => {
172+ const settings : LoadedSettings = new LoadedSettings (
173+ {
174+ settings : {
175+ selectedAuthType : undefined ,
176+ } ,
177+ path : '' ,
178+ } ,
179+ {
180+ settings : { } ,
181+ path : '' ,
182+ } ,
183+ [ ] ,
184+ ) ;
185+
186+ const { lastFrame } = render (
187+ < AuthDialog onSelect = { ( ) => { } } settings = { settings } /> ,
188+ ) ;
189+
190+ // Default is LOGIN_WITH_GOOGLE
191+ expect ( lastFrame ( ) ) . toContain ( '● Login with Google' ) ;
192+ } ) ;
193+
194+ it ( 'should show an error and fall back to default if GEMINI_DEFAULT_AUTH_TYPE is invalid' , ( ) => {
195+ process . env . GEMINI_DEFAULT_AUTH_TYPE = 'invalid-auth-type' ;
196+
197+ const settings : LoadedSettings = new LoadedSettings (
198+ {
199+ settings : {
200+ selectedAuthType : undefined ,
201+ } ,
202+ path : '' ,
203+ } ,
204+ {
205+ settings : { } ,
206+ path : '' ,
207+ } ,
208+ [ ] ,
209+ ) ;
210+
211+ const { lastFrame } = render (
212+ < AuthDialog onSelect = { ( ) => { } } settings = { settings } /> ,
213+ ) ;
214+
215+ expect ( lastFrame ( ) ) . toContain (
216+ 'Invalid value for GEMINI_DEFAULT_AUTH_TYPE: "invalid-auth-type"' ,
217+ ) ;
82218
83- expect ( lastFrame ( ) ) . toContain ( 'Existing API key detected (GEMINI_API_KEY)' ) ;
219+ // Default is LOGIN_WITH_GOOGLE
220+ expect ( lastFrame ( ) ) . toContain ( '● Login with Google' ) ;
221+ } ) ;
84222 } ) ;
85223
86224 it ( 'should prevent exiting when no auth method is selected and show error message' , async ( ) => {
0 commit comments