@@ -7,6 +7,7 @@ import { BASE_TIMESTAMP, mockSdk } from '../index';
7
7
import { mockRrweb } from '../mocks/mockRrweb' ;
8
8
import { clearSession } from '../utils/clearSession' ;
9
9
import { useFakeTimers } from '../utils/use-fake-timers' ;
10
+ import * as SendReplayRequest from '../../src/util/sendReplayRequest' ;
10
11
11
12
useFakeTimers ( ) ;
12
13
@@ -16,12 +17,11 @@ async function advanceTimers(time: number) {
16
17
}
17
18
18
19
type MockTransportSend = jest . MockedFunction < Transport [ 'send' ] > ;
19
- type MockSendReplayRequest = jest . MockedFunction < ReplayContainer [ '_sendReplayRequest' ] > ;
20
20
21
21
describe ( 'Integration | rate-limiting behaviour' , ( ) => {
22
22
let replay : ReplayContainer ;
23
23
let mockTransportSend : MockTransportSend ;
24
- let mockSendReplayRequest : MockSendReplayRequest ;
24
+ let mockSendReplayRequest : jest . MockedFunction < any > ;
25
25
const { record : mockRecord } = mockRrweb ( ) ;
26
26
27
27
beforeAll ( async ( ) => {
@@ -33,12 +33,9 @@ describe('Integration | rate-limiting behaviour', () => {
33
33
} ,
34
34
} ) ) ;
35
35
36
- // @ts -ignore private API
37
- jest . spyOn ( replay , '_sendReplayRequest' ) ;
38
-
39
36
jest . runAllTimers ( ) ;
40
37
mockTransportSend = getCurrentHub ( ) ?. getClient ( ) ?. getTransport ( ) ?. send as MockTransportSend ;
41
- mockSendReplayRequest = replay [ '_sendReplayRequest' ] as MockSendReplayRequest ;
38
+ mockSendReplayRequest = jest . spyOn ( SendReplayRequest , 'sendReplayRequest' ) ;
42
39
} ) ;
43
40
44
41
beforeEach ( ( ) => {
@@ -52,8 +49,6 @@ describe('Integration | rate-limiting behaviour', () => {
52
49
replay [ '_loadSession' ] ( { expiry : 0 } ) ;
53
50
54
51
mockSendReplayRequest . mockClear ( ) ;
55
-
56
- replay [ '_rateLimits' ] = { } ;
57
52
} ) ;
58
53
59
54
afterEach ( async ( ) => {
@@ -92,15 +87,13 @@ describe('Integration | rate-limiting behaviour', () => {
92
87
} ,
93
88
} ,
94
89
] as TransportMakeRequestResponse [ ] ) (
95
- 'pauses recording and flushing a rate limit is hit and resumes both after the rate limit duration is over' ,
90
+ 'pauses recording and flushing a rate limit is hit and resumes both after the rate limit duration is over %j ' ,
96
91
async rateLimitResponse => {
97
92
expect ( replay . session ?. segmentId ) . toBe ( 0 ) ;
98
93
jest . spyOn ( replay , 'pause' ) ;
99
94
jest . spyOn ( replay , 'resume' ) ;
100
95
// @ts -ignore private API
101
96
jest . spyOn ( replay , '_handleRateLimit' ) ;
102
- // @ts -ignore private API
103
- jest . spyOn ( replay , '_sendReplay' ) ;
104
97
105
98
const TEST_EVENT = { data : { } , timestamp : BASE_TIMESTAMP , type : 2 } ;
106
99
@@ -115,7 +108,7 @@ describe('Integration | rate-limiting behaviour', () => {
115
108
116
109
expect ( mockRecord . takeFullSnapshot ) . not . toHaveBeenCalled ( ) ;
117
110
expect ( mockTransportSend ) . toHaveBeenCalledTimes ( 1 ) ;
118
- expect ( replay ) . toHaveLastSentReplay ( { events : JSON . stringify ( [ TEST_EVENT ] ) } ) ;
111
+ expect ( replay ) . toHaveLastSentReplay ( { recordingData : JSON . stringify ( [ TEST_EVENT ] ) } ) ;
119
112
120
113
expect ( replay [ '_handleRateLimit' ] ) . toHaveBeenCalledTimes ( 1 ) ;
121
114
// resume() was called once before we even started
@@ -136,7 +129,7 @@ describe('Integration | rate-limiting behaviour', () => {
136
129
mockRecord . _emitter ( ev ) ;
137
130
await advanceTimers ( DEFAULT_FLUSH_MIN_DELAY ) ;
138
131
expect ( replay . isPaused ( ) ) . toBe ( true ) ;
139
- expect ( replay [ '_sendReplay' ] ) . toHaveBeenCalledTimes ( 1 ) ;
132
+ expect ( mockSendReplayRequest ) . toHaveBeenCalledTimes ( 1 ) ;
140
133
expect ( mockTransportSend ) . toHaveBeenCalledTimes ( 1 ) ;
141
134
}
142
135
@@ -148,9 +141,9 @@ describe('Integration | rate-limiting behaviour', () => {
148
141
expect ( replay . resume ) . toHaveBeenCalledTimes ( 1 ) ;
149
142
expect ( replay . isPaused ( ) ) . toBe ( false ) ;
150
143
151
- expect ( replay [ '_sendReplay' ] ) . toHaveBeenCalledTimes ( 2 ) ;
144
+ expect ( mockSendReplayRequest ) . toHaveBeenCalledTimes ( 2 ) ;
152
145
expect ( replay ) . toHaveLastSentReplay ( {
153
- events : JSON . stringify ( [
146
+ recordingData : JSON . stringify ( [
154
147
{ data : { isCheckout : true } , timestamp : BASE_TIMESTAMP + DEFAULT_FLUSH_MIN_DELAY * 7 , type : 2 } ,
155
148
] ) ,
156
149
} ) ;
@@ -165,14 +158,14 @@ describe('Integration | rate-limiting behaviour', () => {
165
158
166
159
// T = base + 40
167
160
await advanceTimers ( DEFAULT_FLUSH_MIN_DELAY ) ;
168
- expect ( replay [ '_sendReplay' ] ) . toHaveBeenCalledTimes ( 3 ) ;
169
- expect ( replay ) . toHaveLastSentReplay ( { events : JSON . stringify ( [ TEST_EVENT3 ] ) } ) ;
161
+ expect ( mockSendReplayRequest ) . toHaveBeenCalledTimes ( 3 ) ;
162
+ expect ( replay ) . toHaveLastSentReplay ( { recordingData : JSON . stringify ( [ TEST_EVENT3 ] ) } ) ;
170
163
171
164
// nothing should happen afterwards
172
165
// T = base + 60
173
166
await advanceTimers ( 20_000 ) ;
174
- expect ( replay [ '_sendReplay' ] ) . toHaveBeenCalledTimes ( 3 ) ;
175
- expect ( replay ) . toHaveLastSentReplay ( { events : JSON . stringify ( [ TEST_EVENT3 ] ) } ) ;
167
+ expect ( mockSendReplayRequest ) . toHaveBeenCalledTimes ( 3 ) ;
168
+ expect ( replay ) . toHaveLastSentReplay ( { recordingData : JSON . stringify ( [ TEST_EVENT3 ] ) } ) ;
176
169
177
170
// events array should be empty
178
171
expect ( replay . eventBuffer ?. pendingLength ) . toBe ( 0 ) ;
@@ -185,8 +178,6 @@ describe('Integration | rate-limiting behaviour', () => {
185
178
jest . spyOn ( replay , 'resume' ) ;
186
179
// @ts -ignore private API
187
180
jest . spyOn ( replay , '_handleRateLimit' ) ;
188
- // @ts -ignore private API
189
- jest . spyOn ( replay , '_sendReplay' ) ;
190
181
191
182
const TEST_EVENT = { data : { } , timestamp : BASE_TIMESTAMP , type : 2 } ;
192
183
@@ -201,7 +192,7 @@ describe('Integration | rate-limiting behaviour', () => {
201
192
202
193
expect ( mockRecord . takeFullSnapshot ) . not . toHaveBeenCalled ( ) ;
203
194
expect ( mockTransportSend ) . toHaveBeenCalledTimes ( 1 ) ;
204
- expect ( replay ) . toHaveLastSentReplay ( { events : JSON . stringify ( [ TEST_EVENT ] ) } ) ;
195
+ expect ( replay ) . toHaveLastSentReplay ( { recordingData : JSON . stringify ( [ TEST_EVENT ] ) } ) ;
205
196
206
197
expect ( replay [ '_handleRateLimit' ] ) . toHaveBeenCalledTimes ( 1 ) ;
207
198
// resume() was called once before we even started
@@ -223,7 +214,7 @@ describe('Integration | rate-limiting behaviour', () => {
223
214
mockRecord . _emitter ( ev ) ;
224
215
await advanceTimers ( DEFAULT_FLUSH_MIN_DELAY ) ;
225
216
expect ( replay . isPaused ( ) ) . toBe ( true ) ;
226
- expect ( replay [ '_sendReplay' ] ) . toHaveBeenCalledTimes ( 1 ) ;
217
+ expect ( mockSendReplayRequest ) . toHaveBeenCalledTimes ( 1 ) ;
227
218
expect ( mockTransportSend ) . toHaveBeenCalledTimes ( 1 ) ;
228
219
}
229
220
@@ -235,9 +226,9 @@ describe('Integration | rate-limiting behaviour', () => {
235
226
expect ( replay . resume ) . toHaveBeenCalledTimes ( 1 ) ;
236
227
expect ( replay . isPaused ( ) ) . toBe ( false ) ;
237
228
238
- expect ( replay [ '_sendReplay' ] ) . toHaveBeenCalledTimes ( 2 ) ;
229
+ expect ( mockSendReplayRequest ) . toHaveBeenCalledTimes ( 2 ) ;
239
230
expect ( replay ) . toHaveLastSentReplay ( {
240
- events : JSON . stringify ( [
231
+ recordingData : JSON . stringify ( [
241
232
{ data : { isCheckout : true } , timestamp : BASE_TIMESTAMP + DEFAULT_FLUSH_MIN_DELAY * 13 , type : 2 } ,
242
233
] ) ,
243
234
} ) ;
@@ -252,14 +243,14 @@ describe('Integration | rate-limiting behaviour', () => {
252
243
253
244
// T = base + 65
254
245
await advanceTimers ( DEFAULT_FLUSH_MIN_DELAY ) ;
255
- expect ( replay [ '_sendReplay' ] ) . toHaveBeenCalledTimes ( 3 ) ;
256
- expect ( replay ) . toHaveLastSentReplay ( { events : JSON . stringify ( [ TEST_EVENT3 ] ) } ) ;
246
+ expect ( mockSendReplayRequest ) . toHaveBeenCalledTimes ( 3 ) ;
247
+ expect ( replay ) . toHaveLastSentReplay ( { recordingData : JSON . stringify ( [ TEST_EVENT3 ] ) } ) ;
257
248
258
249
// nothing should happen afterwards
259
250
// T = base + 85
260
251
await advanceTimers ( 20_000 ) ;
261
- expect ( replay [ '_sendReplay' ] ) . toHaveBeenCalledTimes ( 3 ) ;
262
- expect ( replay ) . toHaveLastSentReplay ( { events : JSON . stringify ( [ TEST_EVENT3 ] ) } ) ;
252
+ expect ( mockSendReplayRequest ) . toHaveBeenCalledTimes ( 3 ) ;
253
+ expect ( replay ) . toHaveLastSentReplay ( { recordingData : JSON . stringify ( [ TEST_EVENT3 ] ) } ) ;
263
254
264
255
// events array should be empty
265
256
expect ( replay . eventBuffer ?. pendingLength ) . toBe ( 0 ) ;
@@ -291,7 +282,7 @@ describe('Integration | rate-limiting behaviour', () => {
291
282
expect ( mockRecord . takeFullSnapshot ) . not . toHaveBeenCalled ( ) ;
292
283
expect ( mockTransportSend ) . toHaveBeenCalledTimes ( 1 ) ;
293
284
294
- expect ( replay ) . toHaveLastSentReplay ( { events : JSON . stringify ( [ TEST_EVENT ] ) } ) ;
285
+ expect ( replay ) . toHaveLastSentReplay ( { recordingData : JSON . stringify ( [ TEST_EVENT ] ) } ) ;
295
286
296
287
expect ( replay [ '_handleRateLimit' ] ) . toHaveBeenCalledTimes ( 1 ) ;
297
288
expect ( replay . resume ) . not . toHaveBeenCalled ( ) ;
0 commit comments