@@ -27,6 +27,7 @@ describe('LogEnricher Integration', () => {
2727 let mockClient : jest . Mocked < Client > ;
2828 let mockOn : jest . Mock ;
2929 let mockFetchNativeLogAttributes : jest . Mock ;
30+ let mockGetIntegrationByName : jest . Mock ;
3031
3132 const triggerAfterInit = ( ) => {
3233 const afterInitCallback = mockOn . mock . calls . find ( call => call [ 0 ] === 'afterInit' ) ?. [ 1 ] as ( ( ) => void ) | undefined ;
@@ -40,9 +41,11 @@ describe('LogEnricher Integration', () => {
4041
4142 mockOn = jest . fn ( ) ;
4243 mockFetchNativeLogAttributes = jest . fn ( ) ;
44+ mockGetIntegrationByName = jest . fn ( ) ;
4345
4446 mockClient = {
4547 on : mockOn ,
48+ getIntegrationByName : mockGetIntegrationByName ,
4649 } as unknown as jest . Mocked < Client > ;
4750
4851 ( NATIVE as jest . Mocked < typeof NATIVE > ) . fetchNativeLogAttributes = mockFetchNativeLogAttributes ;
@@ -404,4 +407,113 @@ describe('LogEnricher Integration', () => {
404407 expect ( mockOn ) . toHaveBeenCalledWith ( 'beforeCaptureLog' , expect . any ( Function ) ) ;
405408 } ) ;
406409 } ) ;
410+
411+ describe ( 'replay log functionality' , ( ) => {
412+ let logHandler : ( log : Log ) => void ;
413+ let mockLog : Log ;
414+ let mockGetIntegrationByName : jest . Mock ;
415+
416+ beforeEach ( async ( ) => {
417+ const integration = logEnricherIntegration ( ) ;
418+
419+ const mockNativeResponse : NativeDeviceContextsResponse = {
420+ contexts : {
421+ device : {
422+ brand : 'Apple' ,
423+ model : 'iPhone 14' ,
424+ family : 'iPhone' ,
425+ } as Record < string , unknown > ,
426+ os : {
427+ name : 'iOS' ,
428+ version : '16.0' ,
429+ } as Record < string , unknown > ,
430+ release : '1.0.0' as unknown as Record < string , unknown > ,
431+ } ,
432+ } ;
433+
434+ mockFetchNativeLogAttributes . mockResolvedValue ( mockNativeResponse ) ;
435+ mockGetIntegrationByName = jest . fn ( ) ;
436+
437+ mockClient = {
438+ on : mockOn ,
439+ getIntegrationByName : mockGetIntegrationByName ,
440+ } as unknown as jest . Mocked < Client > ;
441+
442+ integration . setup ( mockClient ) ;
443+
444+ triggerAfterInit ( ) ;
445+
446+ await jest . runAllTimersAsync ( ) ;
447+
448+ const beforeCaptureLogCall = mockOn . mock . calls . find ( call => call [ 0 ] === 'beforeCaptureLog' ) ;
449+ expect ( beforeCaptureLogCall ) . toBeDefined ( ) ;
450+ logHandler = beforeCaptureLogCall ! [ 1 ] as ( log : Log ) => void ;
451+
452+ mockLog = {
453+ message : 'Test log message' ,
454+ level : 'info' ,
455+ attributes : { } ,
456+ } ;
457+ } ) ;
458+
459+ it ( 'should add replay_id when MobileReplay integration is available and returns a replay ID' , ( ) => {
460+ const mockReplayId = 'replay-123-abc' ;
461+ const mockReplayIntegration = {
462+ getReplayId : jest . fn ( ) . mockReturnValue ( mockReplayId ) ,
463+ } ;
464+
465+ mockGetIntegrationByName . mockReturnValue ( mockReplayIntegration ) ;
466+
467+ logHandler ( mockLog ) ;
468+
469+ expect ( mockLog . attributes ) . toEqual ( {
470+ 'device.brand' : 'Apple' ,
471+ 'device.model' : 'iPhone 14' ,
472+ 'device.family' : 'iPhone' ,
473+ 'os.name' : 'iOS' ,
474+ 'os.version' : '16.0' ,
475+ 'sentry.release' : '1.0.0' ,
476+ 'sentry.replay_id' : mockReplayId ,
477+ } ) ;
478+ expect ( mockGetIntegrationByName ) . toHaveBeenCalledWith ( 'MobileReplay' ) ;
479+ expect ( mockReplayIntegration . getReplayId ) . toHaveBeenCalled ( ) ;
480+ } ) ;
481+
482+ it ( 'should not add replay_id when MobileReplay integration returns null' , ( ) => {
483+ const mockReplayIntegration = {
484+ getReplayId : jest . fn ( ) . mockReturnValue ( null ) ,
485+ } ;
486+
487+ mockGetIntegrationByName . mockReturnValue ( mockReplayIntegration ) ;
488+
489+ logHandler ( mockLog ) ;
490+
491+ expect ( mockLog . attributes ) . toEqual ( {
492+ 'device.brand' : 'Apple' ,
493+ 'device.model' : 'iPhone 14' ,
494+ 'device.family' : 'iPhone' ,
495+ 'os.name' : 'iOS' ,
496+ 'os.version' : '16.0' ,
497+ 'sentry.release' : '1.0.0' ,
498+ } ) ;
499+ expect ( mockGetIntegrationByName ) . toHaveBeenCalledWith ( 'MobileReplay' ) ;
500+ expect ( mockReplayIntegration . getReplayId ) . toHaveBeenCalled ( ) ;
501+ } ) ;
502+
503+ it ( 'should not add replay_id when MobileReplay integration is not available' , ( ) => {
504+ mockGetIntegrationByName . mockReturnValue ( undefined ) ;
505+
506+ logHandler ( mockLog ) ;
507+
508+ expect ( mockLog . attributes ) . toEqual ( {
509+ 'device.brand' : 'Apple' ,
510+ 'device.model' : 'iPhone 14' ,
511+ 'device.family' : 'iPhone' ,
512+ 'os.name' : 'iOS' ,
513+ 'os.version' : '16.0' ,
514+ 'sentry.release' : '1.0.0' ,
515+ } ) ;
516+ expect ( mockGetIntegrationByName ) . toHaveBeenCalledWith ( 'MobileReplay' ) ;
517+ } ) ;
518+ } ) ;
407519} ) ;
0 commit comments