@@ -422,7 +422,53 @@ describe('preStartRum', () => {
422422 } )
423423 } )
424424
425- describe ( 'remote configuration' , ( ) => {
425+ describe ( 'remote configuration sync loading' , ( ) => {
426+ let interceptor : ReturnType < typeof interceptRequests >
427+
428+ beforeEach ( ( ) => {
429+ interceptor = interceptRequests ( )
430+ } )
431+
432+ it ( 'should start with the remote configuration when a remoteConfigurationId is provided' , async ( ) => {
433+ interceptor . withFetch ( ( ) =>
434+ Promise . resolve ( {
435+ ok : true ,
436+ json : ( ) => Promise . resolve ( { rum : { sessionSampleRate : 50 } } ) ,
437+ } )
438+ )
439+ const { strategy, doStartRumSpy } = createPreStartStrategyWithDefaults ( )
440+ strategy . init (
441+ {
442+ ...DEFAULT_INIT_CONFIGURATION ,
443+ remoteConfigurationId : '123' ,
444+ } ,
445+ PUBLIC_API
446+ )
447+ await collectAsyncCalls ( doStartRumSpy , 1 )
448+ expect ( doStartRumSpy . calls . mostRecent ( ) . args [ 0 ] . sessionSampleRate ) . toEqual ( 50 )
449+ } )
450+
451+ it ( 'should start with the remote configuration when remoteConfiguration.sync is true' , async ( ) => {
452+ interceptor . withFetch ( ( ) =>
453+ Promise . resolve ( {
454+ ok : true ,
455+ json : ( ) => Promise . resolve ( { rum : { sessionSampleRate : 50 } } ) ,
456+ } )
457+ )
458+ const { strategy, doStartRumSpy } = createPreStartStrategyWithDefaults ( )
459+ strategy . init (
460+ {
461+ ...DEFAULT_INIT_CONFIGURATION ,
462+ remoteConfiguration : { id : '123' , sync : true } ,
463+ } ,
464+ PUBLIC_API
465+ )
466+ await collectAsyncCalls ( doStartRumSpy , 1 )
467+ expect ( doStartRumSpy . calls . mostRecent ( ) . args [ 0 ] . sessionSampleRate ) . toEqual ( 50 )
468+ } )
469+ } )
470+
471+ describe ( 'remote configuration async loading' , ( ) => {
426472 const REMOTE_CONFIGURATION_ID = '123'
427473 let interceptor : ReturnType < typeof interceptRequests >
428474
@@ -448,7 +494,7 @@ describe('preStartRum', () => {
448494 strategy . init (
449495 {
450496 ...DEFAULT_INIT_CONFIGURATION ,
451- remoteConfigurationId : REMOTE_CONFIGURATION_ID ,
497+ remoteConfiguration : { id : REMOTE_CONFIGURATION_ID } ,
452498 sessionSampleRate : 25 ,
453499 } ,
454500 PUBLIC_API
@@ -464,7 +510,7 @@ describe('preStartRum', () => {
464510 strategy . init (
465511 {
466512 ...DEFAULT_INIT_CONFIGURATION ,
467- remoteConfigurationId : REMOTE_CONFIGURATION_ID ,
513+ remoteConfiguration : { id : REMOTE_CONFIGURATION_ID } ,
468514 } ,
469515 PUBLIC_API
470516 )
@@ -576,7 +622,29 @@ describe('preStartRum', () => {
576622 expect ( strategy . initConfiguration ) . toEqual ( initConfiguration )
577623 } )
578624
579- it ( 'exposes the user configuration when a remoteConfigurationId is provided (cache miss)' , ( ) => {
625+ it ( 'returns the initConfiguration with the remote configuration when a remoteConfigurationId is provided (sync loading)' , ( done ) => {
626+ interceptor . withFetch ( ( ) =>
627+ Promise . resolve ( {
628+ ok : true ,
629+ json : ( ) => Promise . resolve ( { rum : { sessionSampleRate : 50 } } ) ,
630+ } )
631+ )
632+ const { strategy, doStartRumSpy } = createPreStartStrategyWithDefaults ( )
633+ doStartRumSpy . and . callFake ( ( ) => {
634+ expect ( strategy . initConfiguration ?. sessionSampleRate ) . toEqual ( 50 )
635+ done ( )
636+ return { } as StartRumResult
637+ } )
638+ strategy . init (
639+ {
640+ ...DEFAULT_INIT_CONFIGURATION ,
641+ remoteConfigurationId : '123' ,
642+ } ,
643+ PUBLIC_API
644+ )
645+ } )
646+
647+ it ( 'exposes the user configuration when remoteConfiguration.id is provided (async loading, cache miss)' , ( ) => {
580648 interceptor . withFetch ( ( ) =>
581649 Promise . resolve ( {
582650 ok : true ,
@@ -587,7 +655,7 @@ describe('preStartRum', () => {
587655 const { strategy } = createPreStartStrategyWithDefaults ( )
588656 const userInitConfiguration : RumInitConfiguration = {
589657 ...DEFAULT_INIT_CONFIGURATION ,
590- remoteConfigurationId : '123' ,
658+ remoteConfiguration : { id : '123' } ,
591659 }
592660 strategy . init ( userInitConfiguration , PUBLIC_API )
593661
0 commit comments