@@ -575,6 +575,66 @@ describe('rum assembly', () => {
575575 } )
576576 } )
577577 } )
578+
579+ describe ( 'STREAM event processing' , ( ) => {
580+ it ( 'should convert STREAM events to VIEW events' , ( ) => {
581+ const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults ( { } )
582+
583+ const streamData = {
584+ id : 'stream-id-123' ,
585+ document_version : 42 ,
586+ time_spent : 5000000000 , // 5 seconds in nanoseconds
587+ }
588+
589+ notifyRawRumEvent ( lifeCycle , {
590+ rawRumEvent : createRawRumEvent ( RumEventType . STREAM , {
591+ stream : streamData ,
592+ view : { id : 'original-view-id' , url : '/test' }
593+ } ) ,
594+ } )
595+
596+ expect ( serverRumEvents . length ) . toBe ( 1 )
597+ const resultEvent = serverRumEvents [ 0 ]
598+
599+ expect ( resultEvent . type ) . toBe ( 'view' )
600+ } )
601+
602+ it ( 'should map stream properties correctly in converted VIEW event' , ( ) => {
603+ const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults ( { } )
604+
605+ const streamData = {
606+ id : 'stream-id-456' ,
607+ document_version : 25 ,
608+ time_spent : 3000000000 , // 3 seconds in nanoseconds
609+ }
610+
611+ notifyRawRumEvent ( lifeCycle , {
612+ rawRumEvent : createRawRumEvent ( RumEventType . STREAM , {
613+ stream : streamData ,
614+ view : { id : 'original-view-id' , url : '/test-page' }
615+ } ) ,
616+ } )
617+
618+ expect ( serverRumEvents . length ) . toBe ( 1 )
619+ const resultEvent = serverRumEvents [ 0 ] as any
620+
621+ // Check _dd.document_version is set from stream.document_version
622+ expect ( resultEvent . _dd . document_version ) . toBe ( 25 )
623+
624+ // Check view.id is set from stream.id
625+ expect ( resultEvent . view . id ) . toBe ( 'stream-id-456' )
626+
627+ // Check view.time_spent is set from stream.time_spent
628+ expect ( resultEvent . view . time_spent ) . toBe ( 3000000000 )
629+
630+ // Check stream.time_spent is undefined in the stream object
631+ expect ( resultEvent . stream . time_spent ) . toBeUndefined ( )
632+
633+ // Check action/error/resource counts are set to 0
634+ expect ( resultEvent . view . action . count ) . toBe ( 0 )
635+ expect ( resultEvent . view . error . count ) . toBe ( 0 )
636+ expect ( resultEvent . view . resource . count ) . toBe ( 0 )
637+ } )
578638} )
579639
580640function notifyRawRumEvent < E extends RawRumEvent > (
0 commit comments