@@ -32,9 +32,16 @@ const mockFetch = fetch as any
3232
3333describe ( "TelemetryClient" , ( ) => {
3434 let client : TelemetryClient
35+ let mockConsoleError : ReturnType < typeof vi . spyOn >
36+ let mockConsoleInfo : ReturnType < typeof vi . spyOn >
3537
3638 beforeEach ( ( ) => {
3739 vi . clearAllMocks ( )
40+
41+ // Create fresh console mocks for each test
42+ mockConsoleError = vi . spyOn ( console , "error" ) . mockImplementation ( ( ) => { } )
43+ mockConsoleInfo = vi . spyOn ( console , "info" ) . mockImplementation ( ( ) => { } )
44+
3845 client = new TelemetryClient ( mockAuthService , mockSettingsService , true )
3946
4047 mockAuthService . isAuthenticated . mockReturnValue ( true )
@@ -44,6 +51,11 @@ describe("TelemetryClient", () => {
4451 } )
4552 } )
4653
54+ afterEach ( ( ) => {
55+ mockConsoleError . mockRestore ( )
56+ mockConsoleInfo . mockRestore ( )
57+ } )
58+
4759 describe ( "cloud telemetry client identification" , ( ) => {
4860 it ( "should identify itself as a cloud telemetry client" , ( ) => {
4961 // Access protected method for testing
@@ -237,7 +249,7 @@ describe("TelemetryClient", () => {
237249 await client . backfillMessages ( messages , "test-task-id" )
238250
239251 expect ( mockFetch ) . not . toHaveBeenCalled ( )
240- expect ( console . error ) . toHaveBeenCalledWith (
252+ expect ( mockConsoleError ) . toHaveBeenCalledWith (
241253 "[TelemetryClient#backfillMessages] Unauthorized: No session token available." ,
242254 )
243255 } )
@@ -279,11 +291,11 @@ describe("TelemetryClient", () => {
279291 await client . backfillMessages ( messages , "test-task-id" )
280292
281293 expect ( mockFetch ) . toHaveBeenCalledWith (
282- "https://app.roocode .com/api/events/backfill" ,
294+ "https://api.test .com/api/events/backfill" ,
283295 expect . objectContaining ( {
284296 method : "POST" ,
285297 headers : {
286- Authorization : "Bearer mock -token" ,
298+ Authorization : "Bearer test -token" ,
287299 } ,
288300 body : expect . any ( FormData ) ,
289301 } ) ,
@@ -334,11 +346,11 @@ describe("TelemetryClient", () => {
334346 await client . backfillMessages ( messages , "test-task-id" )
335347
336348 expect ( mockFetch ) . toHaveBeenCalledWith (
337- "https://app.roocode .com/api/events/backfill" ,
349+ "https://api.test .com/api/events/backfill" ,
338350 expect . objectContaining ( {
339351 method : "POST" ,
340352 headers : {
341- Authorization : "Bearer mock -token" ,
353+ Authorization : "Bearer test -token" ,
342354 } ,
343355 body : expect . any ( FormData ) ,
344356 } ) ,
@@ -380,11 +392,11 @@ describe("TelemetryClient", () => {
380392 await client . backfillMessages ( messages , "test-task-id" )
381393
382394 expect ( mockFetch ) . toHaveBeenCalledWith (
383- "https://app.roocode .com/api/events/backfill" ,
395+ "https://api.test .com/api/events/backfill" ,
384396 expect . objectContaining ( {
385397 method : "POST" ,
386398 headers : {
387- Authorization : "Bearer mock -token" ,
399+ Authorization : "Bearer test -token" ,
388400 } ,
389401 body : expect . any ( FormData ) ,
390402 } ) ,
@@ -427,7 +439,7 @@ describe("TelemetryClient", () => {
427439
428440 await expect ( client . backfillMessages ( messages , "test-task-id" ) ) . resolves . not . toThrow ( )
429441
430- expect ( console . error ) . toHaveBeenCalledWith (
442+ expect ( mockConsoleError ) . toHaveBeenCalledWith (
431443 expect . stringContaining (
432444 "[TelemetryClient#backfillMessages] Error uploading messages: Error: Network error" ,
433445 ) ,
@@ -454,14 +466,19 @@ describe("TelemetryClient", () => {
454466
455467 await client . backfillMessages ( messages , "test-task-id" )
456468
457- expect ( console . error ) . toHaveBeenCalledWith (
469+ expect ( mockConsoleError ) . toHaveBeenCalledWith (
458470 "[TelemetryClient#backfillMessages] POST events/backfill -> 404 Not Found" ,
459471 )
460472 } )
461473
462474 it ( "should log debug information when debug is enabled" , async ( ) => {
463475 const client = new TelemetryClient ( mockAuthService , mockSettingsService , true )
464476
477+ // Mock successful response for debug success message
478+ mockFetch . mockResolvedValue ( {
479+ ok : true ,
480+ } as Response )
481+
465482 const messages = [
466483 {
467484 ts : 1 ,
@@ -473,10 +490,10 @@ describe("TelemetryClient", () => {
473490
474491 await client . backfillMessages ( messages , "test-task-id" )
475492
476- expect ( console . info ) . toHaveBeenCalledWith (
493+ expect ( mockConsoleInfo ) . toHaveBeenCalledWith (
477494 "[TelemetryClient#backfillMessages] Uploading 1 messages for task test-task-id" ,
478495 )
479- expect ( console . info ) . toHaveBeenCalledWith (
496+ expect ( mockConsoleInfo ) . toHaveBeenCalledWith (
480497 "[TelemetryClient#backfillMessages] Successfully uploaded messages for task test-task-id" ,
481498 )
482499 } )
@@ -487,11 +504,11 @@ describe("TelemetryClient", () => {
487504 await client . backfillMessages ( [ ] , "test-task-id" )
488505
489506 expect ( mockFetch ) . toHaveBeenCalledWith (
490- "https://app.roocode .com/api/events/backfill" ,
507+ "https://api.test .com/api/events/backfill" ,
491508 expect . objectContaining ( {
492509 method : "POST" ,
493510 headers : {
494- Authorization : "Bearer mock -token" ,
511+ Authorization : "Bearer test -token" ,
495512 } ,
496513 body : expect . any ( FormData ) ,
497514 } ) ,
0 commit comments