@@ -29,10 +29,9 @@ describe('Unit | util | prepareReplayEvent', () => {
29
29
30
30
it ( 'works' , async ( ) => {
31
31
const client = getClient ( ) ! ;
32
- const scope = getCurrentScope ( ) ! ;
32
+ const scope = getCurrentScope ( ) ;
33
33
34
34
expect ( client ) . toBeDefined ( ) ;
35
- expect ( scope ) . toBeDefined ( ) ;
36
35
37
36
const replayId = 'replay-ID' ;
38
37
const event : ReplayEvent = {
@@ -78,6 +77,131 @@ describe('Unit | util | prepareReplayEvent', () => {
78
77
name : 'sentry.javascript.testSdk' ,
79
78
version : '1.0.0' ,
80
79
} ,
80
+ user : {
81
+ ip_address : '{{auto}}' ,
82
+ } ,
83
+ sdkProcessingMetadata : expect . any ( Object ) ,
84
+ breadcrumbs : undefined ,
85
+ } ) ;
86
+ } ) ;
87
+
88
+ it ( 'sets user' , async ( ) => {
89
+ const client = getClient ( ) ! ;
90
+ const scope = getCurrentScope ( ) . clone ( ) ;
91
+
92
+ scope . setUser ( { id : 'user-id' } ) ;
93
+
94
+ expect ( client ) . toBeDefined ( ) ;
95
+
96
+ const replayId = 'replay-ID' ;
97
+ const event : ReplayEvent = {
98
+ type : REPLAY_EVENT_NAME ,
99
+ timestamp : 1670837008.634 ,
100
+ error_ids : [ 'error-ID' ] ,
101
+ trace_ids : [ 'trace-ID' ] ,
102
+ urls : [ 'https://sentry.io/' ] ,
103
+ replay_id : replayId ,
104
+ replay_type : 'session' ,
105
+ segment_id : 3 ,
106
+ contexts : {
107
+ replay : {
108
+ error_sample_rate : 1.0 ,
109
+ session_sample_rate : 0.1 ,
110
+ } ,
111
+ } ,
112
+ } ;
113
+
114
+ const replayEvent = await prepareReplayEvent ( { scope, client, replayId, event } ) ;
115
+
116
+ expect ( client . getSdkMetadata ) . toHaveBeenCalledTimes ( 1 ) ;
117
+
118
+ expect ( replayEvent ) . toEqual ( {
119
+ type : 'replay_event' ,
120
+ timestamp : 1670837008.634 ,
121
+ error_ids : [ 'error-ID' ] ,
122
+ trace_ids : [ 'trace-ID' ] ,
123
+ urls : [ 'https://sentry.io/' ] ,
124
+ replay_id : 'replay-ID' ,
125
+ replay_type : 'session' ,
126
+ segment_id : 3 ,
127
+ platform : 'javascript' ,
128
+ event_id : 'replay-ID' ,
129
+ environment : 'production' ,
130
+ contexts : {
131
+ replay : {
132
+ error_sample_rate : 1.0 ,
133
+ session_sample_rate : 0.1 ,
134
+ } ,
135
+ } ,
136
+ sdk : {
137
+ name : 'sentry.javascript.testSdk' ,
138
+ version : '1.0.0' ,
139
+ } ,
140
+ user : {
141
+ id : 'user-id' ,
142
+ ip_address : '{{auto}}' ,
143
+ } ,
144
+ sdkProcessingMetadata : expect . any ( Object ) ,
145
+ 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
+ } ,
173
+ } ;
174
+
175
+ const replayEvent = await prepareReplayEvent ( { scope, client, replayId, event } ) ;
176
+
177
+ expect ( client . getSdkMetadata ) . toHaveBeenCalledTimes ( 1 ) ;
178
+
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' ,
189
+ 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
+ } ,
81
205
sdkProcessingMetadata : expect . any ( Object ) ,
82
206
breadcrumbs : undefined ,
83
207
} ) ;
0 commit comments