@@ -15,7 +15,7 @@ declare global {
1515 }
1616}
1717
18- describe ( 'batch uploader' , ( ) => {
18+ describe . only ( 'batch uploader' , ( ) => {
1919 let mockServer ;
2020
2121 beforeEach ( ( ) => {
@@ -62,12 +62,12 @@ describe('batch uploader', () => {
6262 sinon . restore ( ) ;
6363 } ) ;
6464
65- it ( 'should use custom v3 endpoint' , function ( done ) {
65+ it ( 'should use custom v3 endpoint' , async ( ) => {
6666 window . mParticle . _resetForTests ( MPConfig ) ;
6767 mockServer . requests = [ ] ;
6868 window . mParticle . init ( apiKey , window . mParticle . config ) ;
69- waitForCondition ( hasIdentifyReturned )
70- . then ( ( ) => {
69+ await waitForCondition ( hasIdentifyReturned ) ;
70+
7171 window . mParticle . logEvent ( 'Test Event' ) ;
7272
7373 mockServer . requests . length . should . equal ( 1 ) ;
@@ -80,19 +80,13 @@ describe('batch uploader', () => {
8080 batch . events [ 1 ] . event_type . should . equal ( 'application_state_transition' ) ;
8181 batch . events [ 2 ] . event_type . should . equal ( 'custom_event' ) ;
8282 batch . events [ 2 ] . data . event_name . should . equal ( 'Test Event' ) ;
83-
84- done ( ) ;
85- } ) . catch ( ( e ) => {
86- } )
8783 } ) ;
8884
89- it ( 'should force uploads when using public `upload`' , function ( done ) {
85+ it ( 'should force uploads when using public `upload`' , async ( ) => {
9086 window . mParticle . _resetForTests ( MPConfig ) ;
9187
9288 window . mParticle . init ( apiKey , window . mParticle . config ) ;
93- waitForCondition ( hasIdentifyReturned )
94- . then ( ( ) => {
95-
89+ await waitForCondition ( hasIdentifyReturned ) ;
9690
9791 window . mParticle . logEvent ( 'Test Event' ) ;
9892
@@ -109,17 +103,14 @@ describe('batch uploader', () => {
109103 batch . events [ 1 ] . event_type . should . equal ( 'application_state_transition' ) ;
110104 batch . events [ 2 ] . event_type . should . equal ( 'custom_event' ) ;
111105 batch . events [ 2 ] . data . event_name . should . equal ( 'Test Event' ) ;
112-
113- done ( ) ;
114- } )
115106 } ) ;
116107
117- it ( 'should trigger an upload of batch when a commerce event is called' , function ( done ) {
108+ it ( 'should trigger an upload of batch when a commerce event is called' , async ( ) => {
118109 window . mParticle . _resetForTests ( MPConfig ) ;
119110
120111 window . mParticle . init ( apiKey , window . mParticle . config ) ;
121- waitForCondition ( hasIdentifyReturned )
122- . then ( ( ) => {
112+ await waitForCondition ( hasIdentifyReturned ) ;
113+
123114 window . mParticle . logEvent ( 'Test Event' ) ;
124115 // The only request to the server should be the identify call
125116 // Session start, AST, and Test Event are queued.
@@ -136,12 +127,9 @@ describe('batch uploader', () => {
136127 batch . events [ 2 ] . data . event_name . should . equal ( 'Test Event' ) ;
137128 batch . events [ 3 ] . event_type . should . equal ( 'commerce_event' ) ;
138129 batch . events [ 3 ] . data . product_action . action . should . equal ( 'add_to_cart' ) ;
139-
140- done ( ) ;
141- } )
142130 } ) ;
143131
144- it ( 'should trigger an upload of batch when a UIC occurs' , function ( done ) {
132+ it ( 'should trigger an upload of batch when a UIC occurs' , async ( ) => {
145133 window . mParticle . _resetForTests ( MPConfig ) ;
146134 // include an identify request so that it creates a UIC
147135 window . mParticle . config . identifyRequest = {
@@ -151,8 +139,8 @@ describe('batch uploader', () => {
151139 } ;
152140
153141 window . mParticle . init ( apiKey , window . mParticle . config ) ;
154- waitForCondition ( hasIdentifyReturned )
155- . then ( ( ) => {
142+ await waitForCondition ( hasIdentifyReturned ) ;
143+
156144 // Requests sent should be identify call, then UIC event
157145 // Session start, AST, and Test Event are queued, and don't appear
158146 // in the mockServer.requests
@@ -166,22 +154,18 @@ describe('batch uploader', () => {
166154
167155 batch . events [ 0 ] . event_type . should . equal ( 'session_start' ) ;
168156 batch . events [ 1 ] . event_type . should . equal ( 'application_state_transition' ) ;
169-
170- done ( ) ;
171- } ) ;
172157 } ) ;
173158
174159 // Originally, we had the Batch uploader set to force an upload when a UAC event
175160 // was triggered. This feature was removed and we are including this test to
176161 // make sure the Web SDK does not regress. This test will be removed in a future
177162 // Web SDK update
178163 // TODO: https://go.mparticle.com/work/SQDSDKS-5891
179- it ( 'should NOT trigger an upload of batch when a UAC occurs' , function ( done ) {
164+ it ( 'should NOT trigger an upload of batch when a UAC occurs' , async ( ) => {
180165 window . mParticle . _resetForTests ( MPConfig ) ;
181166
182167 window . mParticle . init ( apiKey , window . mParticle . config ) ;
183- waitForCondition ( hasIdentifyReturned )
184- . then ( ( ) => {
168+ await waitForCondition ( hasIdentifyReturned ) ;
185169
186170 // Set a user attribute to trigger a UAC event
187171 window . mParticle . Identity . getCurrentUser ( ) . setUserAttribute ( 'age' , 25 ) ;
@@ -208,12 +192,9 @@ describe('batch uploader', () => {
208192 batch . events [ 0 ] . event_type . should . equal ( 'session_start' ) ;
209193 batch . events [ 1 ] . event_type . should . equal ( 'application_state_transition' ) ;
210194 batch . events [ 2 ] . event_type . should . equal ( 'user_attribute_change' ) ;
211-
212- done ( ) ;
213- } ) ;
214195 } ) ;
215196
216- it ( 'should return pending uploads if a 500 is returned' , function ( done ) {
197+ it ( 'should return pending uploads if a 500 is returned' , async ( ) => {
217198 window . mParticle . _resetForTests ( MPConfig ) ;
218199
219200 mockServer . respondWith ( urls . events , [
@@ -224,8 +205,8 @@ describe('batch uploader', () => {
224205
225206 window . mParticle . init ( apiKey , window . mParticle . config ) ;
226207
227- waitForCondition ( hasIdentifyReturned )
228- . then ( ( ) => {
208+ await waitForCondition ( hasIdentifyReturned ) ;
209+
229210 window . mParticle . logEvent ( 'Test Event' ) ;
230211
231212 const pendingEvents = window . mParticle . getInstance ( ) . _APIClient . uploader . eventsQueuedForProcessing ;
@@ -245,32 +226,27 @@ describe('batch uploader', () => {
245226 batch . events [ 1 ] . event_type . should . equal ( 'application_state_transition' ) ;
246227 batch . events [ 2 ] . event_type . should . equal ( 'custom_event' ) ;
247228 batch . events [ 2 ] . data . event_name . should . equal ( 'Test Event' ) ;
248- done ( ) ;
249- } ) ;
250229 } ) ;
251230
252- it ( 'should add a modified boolean of true to a batch that has been modified via a config.onCreateBatch call' , function ( done ) {
231+ it ( 'should add a modified boolean of true to a batch that has been modified via a config.onCreateBatch call' , async ( ) => {
253232 window . mParticle . _resetForTests ( MPConfig ) ;
254233
255234 window . mParticle . config . onCreateBatch = function ( batch : Batch ) {
256235 return batch
257236 } ;
258237
259238 window . mParticle . init ( apiKey , window . mParticle . config ) ;
260- waitForCondition ( hasIdentifyReturned )
261- . then ( ( ) => {
239+ await waitForCondition ( hasIdentifyReturned ) ;
240+
262241 window . mParticle . logEvent ( 'Test Event' ) ;
263242
264243 window . mParticle . upload ( )
265244
266245 const batch = JSON . parse ( mockServer . secondRequest . requestBody ) ;
267246 batch . modified . should . equal ( true ) ;
268- done ( ) ;
269- } ) ;
270-
271247 } ) ;
272248
273- it ( 'should respect rules for the batch modification' , function ( done ) {
249+ it ( 'should respect rules for the batch modification' , async ( ) => {
274250 window . mParticle . _resetForTests ( MPConfig ) ;
275251
276252 window . mParticle . config . onCreateBatch = function ( batch ) {
@@ -284,8 +260,8 @@ describe('batch uploader', () => {
284260
285261 window . mParticle . init ( apiKey , window . mParticle . config ) ;
286262
287- waitForCondition ( hasIdentifyReturned )
288- . then ( ( ) => {
263+ await waitForCondition ( hasIdentifyReturned ) ;
264+
289265 window . mParticle . logEvent ( 'Test Event' ) ;
290266
291267 window . mParticle . upload ( ) ;
@@ -296,11 +272,9 @@ describe('batch uploader', () => {
296272 batch . events [ 1 ] . event_type . should . equal ( 'application_state_transition' ) ;
297273 batch . events [ 2 ] . event_type . should . equal ( 'custom_event' ) ;
298274 batch . events [ 2 ] . data . event_name . should . equal ( 'Modified!' ) ;
299- done ( ) ;
300- } ) ;
301275 } ) ;
302276
303- it ( 'should add a modified boolean of true to a batch that has been modified via a config.onCreateBatch call' , function ( done ) {
277+ it ( 'should add a modified boolean of true to a batch that has been modified via a config.onCreateBatch call' , async ( ) => {
304278 window . mParticle . _resetForTests ( MPConfig ) ;
305279
306280 window . mParticle . config . onCreateBatch = function ( batch : Batch ) {
@@ -309,15 +283,13 @@ describe('batch uploader', () => {
309283
310284 window . mParticle . init ( apiKey , window . mParticle . config ) ;
311285
312- waitForCondition ( hasIdentifyReturned )
313- . then ( ( ) => {
286+ await waitForCondition ( hasIdentifyReturned ) ;
287+
314288 window . mParticle . logEvent ( 'Test Event' ) ;
315289
316290 window . mParticle . upload ( ) ;
317291
318292 ( mockServer . secondRequest === null ) . should . equal ( true ) ;
319- done ( ) ;
320- } )
321293 } ) ;
322294 } ) ;
323295} ) ;
0 commit comments