@@ -182,6 +182,21 @@ describe("RooHandler", () => {
182182 handler = new RooHandler ( mockOptions )
183183 } )
184184
185+ it ( "should update API key before making request" , async ( ) => {
186+ // Set up a fresh token that will be returned when createMessage is called
187+ const freshToken = "fresh-session-token"
188+ mockGetSessionTokenFn . mockReturnValue ( freshToken )
189+
190+ const stream = handler . createMessage ( systemPrompt , messages )
191+ // Consume the stream to trigger the API call
192+ for await ( const _chunk of stream ) {
193+ // Just consume
194+ }
195+
196+ // Verify getSessionToken was called to get the fresh token
197+ expect ( mockGetSessionTokenFn ) . toHaveBeenCalled ( )
198+ } )
199+
185200 it ( "should handle streaming responses" , async ( ) => {
186201 const stream = handler . createMessage ( systemPrompt , messages )
187202 const chunks : any [ ] = [ ]
@@ -290,6 +305,25 @@ describe("RooHandler", () => {
290305 } )
291306 } )
292307
308+ it ( "should update API key before making request" , async ( ) => {
309+ // Set up a fresh token that will be returned when completePrompt is called
310+ const freshToken = "fresh-session-token"
311+ mockGetSessionTokenFn . mockReturnValue ( freshToken )
312+
313+ // Access the client's apiKey property to verify it gets updated
314+ const clientApiKeyGetter = vitest . fn ( )
315+ Object . defineProperty ( handler [ "client" ] , "apiKey" , {
316+ get : clientApiKeyGetter ,
317+ set : vitest . fn ( ) ,
318+ configurable : true ,
319+ } )
320+
321+ await handler . completePrompt ( "Test prompt" )
322+
323+ // Verify getSessionToken was called to get the fresh token
324+ expect ( mockGetSessionTokenFn ) . toHaveBeenCalled ( )
325+ } )
326+
293327 it ( "should handle API errors" , async ( ) => {
294328 mockCreate . mockRejectedValueOnce ( new Error ( "API Error" ) )
295329 await expect ( handler . completePrompt ( "Test prompt" ) ) . rejects . toThrow (
0 commit comments