@@ -77,21 +77,20 @@ describe('Unit | util | prepareReplayEvent', () => {
7777 name : 'sentry.javascript.testSdk' ,
7878 version : '1.0.0' ,
7979 } ,
80- user : {
81- ip_address : '{{auto}}' ,
82- } ,
8380 sdkProcessingMetadata : expect . any ( Object ) ,
8481 breadcrumbs : undefined ,
8582 } ) ;
8683 } ) ;
8784
88- it ( 'sets user ' , async ( ) => {
85+ it ( 'emits hooks ' , async ( ) => {
8986 const client = getClient ( ) ! ;
9087 const scope = getCurrentScope ( ) . clone ( ) ;
9188
92- scope . setUser ( { id : 'user-id' } ) ;
89+ const preprocessEvent = vi . fn ( ) ;
90+ const postprocessEvent = vi . fn ( ) ;
9391
94- expect ( client ) . toBeDefined ( ) ;
92+ const removeHook1 = client . on ( 'preprocessEvent' , preprocessEvent ) ;
93+ const removeHook2 = client . on ( 'postprocessEvent' , postprocessEvent ) ;
9594
9695 const replayId = 'replay-ID' ;
9796 const event : ReplayEvent = {
@@ -111,11 +110,7 @@ describe('Unit | util | prepareReplayEvent', () => {
111110 } ,
112111 } ;
113112
114- const replayEvent = await prepareReplayEvent ( { scope, client, replayId, event } ) ;
115-
116- expect ( client . getSdkMetadata ) . toHaveBeenCalledTimes ( 1 ) ;
117-
118- expect ( replayEvent ) . toEqual ( {
113+ const processedEvent = {
119114 type : 'replay_event' ,
120115 timestamp : 1670837008.634 ,
121116 error_ids : [ 'error-ID' ] ,
@@ -137,73 +132,25 @@ describe('Unit | util | prepareReplayEvent', () => {
137132 name : 'sentry.javascript.testSdk' ,
138133 version : '1.0.0' ,
139134 } ,
140- user : {
141- id : 'user-id' ,
142- ip_address : '{{auto}}' ,
143- } ,
144135 sdkProcessingMetadata : expect . any ( Object ) ,
145136 breadcrumbs : undefined ,
146- } ) ;
147- } ) ;
148-
149- it ( 'allows to set user.ip_address=null' , async ( ) => {
150- const client = getClient ( ) ! ;
151- const scope = getCurrentScope ( ) . clone ( ) ;
152-
153- scope . setUser ( { id : 'user-id' , ip_address : null } ) ;
154-
155- expect ( client ) . toBeDefined ( ) ;
156-
157- const replayId = 'replay-ID' ;
158- const event : ReplayEvent = {
159- type : REPLAY_EVENT_NAME ,
160- timestamp : 1670837008.634 ,
161- error_ids : [ 'error-ID' ] ,
162- trace_ids : [ 'trace-ID' ] ,
163- urls : [ 'https://sentry.io/' ] ,
164- replay_id : replayId ,
165- replay_type : 'session' ,
166- segment_id : 3 ,
167- contexts : {
168- replay : {
169- error_sample_rate : 1.0 ,
170- session_sample_rate : 0.1 ,
171- } ,
172- } ,
173137 } ;
174138
175- const replayEvent = await prepareReplayEvent ( { scope, client, replayId, event } ) ;
139+ await prepareReplayEvent ( { scope, client, replayId, event } ) ;
176140
177- expect ( client . getSdkMetadata ) . toHaveBeenCalledTimes ( 1 ) ;
141+ expect ( preprocessEvent ) . toHaveBeenCalledTimes ( 1 ) ;
142+ expect ( preprocessEvent ) . toHaveBeenCalledWith ( event , {
143+ event_id : 'replay-ID' ,
144+ integrations : [ ] ,
145+ } ) ;
178146
179- expect ( replayEvent ) . toEqual ( {
180- type : 'replay_event' ,
181- timestamp : 1670837008.634 ,
182- error_ids : [ 'error-ID' ] ,
183- trace_ids : [ 'trace-ID' ] ,
184- urls : [ 'https://sentry.io/' ] ,
185- replay_id : 'replay-ID' ,
186- replay_type : 'session' ,
187- segment_id : 3 ,
188- platform : 'javascript' ,
147+ expect ( postprocessEvent ) . toHaveBeenCalledTimes ( 1 ) ;
148+ expect ( postprocessEvent ) . toHaveBeenCalledWith ( processedEvent , {
189149 event_id : 'replay-ID' ,
190- environment : 'production' ,
191- contexts : {
192- replay : {
193- error_sample_rate : 1.0 ,
194- session_sample_rate : 0.1 ,
195- } ,
196- } ,
197- sdk : {
198- name : 'sentry.javascript.testSdk' ,
199- version : '1.0.0' ,
200- } ,
201- user : {
202- id : 'user-id' ,
203- ip_address : null ,
204- } ,
205- sdkProcessingMetadata : expect . any ( Object ) ,
206- breadcrumbs : undefined ,
150+ integrations : [ ] ,
207151 } ) ;
152+
153+ removeHook1 ( ) ;
154+ removeHook2 ( ) ;
208155 } ) ;
209156} ) ;
0 commit comments