Skip to content

Commit d5fd2f8

Browse files
committed
test: converted .then to async/await for batchUploader_3 test
1 parent dc0c5da commit d5fd2f8

1 file changed

Lines changed: 32 additions & 52 deletions

File tree

test/src/tests-batchUploader_3.ts

Lines changed: 32 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,12 @@ describe('batch uploader', () => {
4949
window.mParticle.config.flags.eventBatchingIntervalMillis = 0;
5050
});
5151

52-
it('should use custom v3 endpoint', function(done) {
52+
it('should use custom v3 endpoint', async () => {
5353
window.mParticle._resetForTests(MPConfig);
5454
fetchMock.resetHistory();
5555
window.mParticle.init(apiKey, window.mParticle.config);
56-
waitForCondition(hasIdentifyReturned)
57-
.then(() => {
56+
await waitForCondition(hasIdentifyReturned);
57+
5858
window.mParticle.logEvent('Test Event');
5959

6060
window.mParticle.upload();
@@ -68,16 +68,13 @@ describe('batch uploader', () => {
6868
batch.events[1].event_type.should.equal('application_state_transition');
6969
batch.events[2].event_type.should.equal('custom_event');
7070
batch.events[2].data.event_name.should.equal('Test Event');
71-
72-
done();
73-
})
7471
});
7572

76-
it('should have latitude/longitude for location when batching', function(done) {
73+
it('should have latitude/longitude for location when batching', async () => {
7774
window.mParticle._resetForTests(MPConfig);
7875
window.mParticle.init(apiKey, window.mParticle.config);
79-
waitForCondition(hasIdentifyReturned)
80-
.then(() => {
76+
await waitForCondition(hasIdentifyReturned);
77+
8178
window.mParticle.setPosition(100, 100);
8279
window.mParticle.logEvent('Test Event');
8380
window.mParticle.upload();
@@ -87,16 +84,13 @@ describe('batch uploader', () => {
8784
endpoint.should.equal(urls.events);
8885
batch.events[2].data.location.should.have.property('latitude', 100)
8986
batch.events[2].data.location.should.have.property('longitude', 100)
90-
91-
done();
92-
})
9387
});
9488

95-
it('should force uploads when using public `upload`', function(done) {
89+
it('should force uploads when using public `upload`', async () => {
9690
window.mParticle._resetForTests(MPConfig);
9791
window.mParticle.init(apiKey, window.mParticle.config);
98-
waitForCondition(hasIdentifyReturned)
99-
.then(() => {
92+
await waitForCondition(hasIdentifyReturned);
93+
10094
window.mParticle.logEvent('Test Event');
10195
// Identity call
10296
// Session start, AST, and `Test Event` are queued.
@@ -115,17 +109,14 @@ describe('batch uploader', () => {
115109
batch.events[1].event_type.should.equal('application_state_transition');
116110
batch.events[2].event_type.should.equal('custom_event');
117111
batch.events[2].data.event_name.should.equal('Test Event');
118-
119-
done();
120-
})
121112
});
122113

123-
it('should force uploads when a commerce event is called', function(done) {
114+
it('should force uploads when a commerce event is called', async () => {
124115
window.mParticle._resetForTests(MPConfig);
125116
window.mParticle.init(apiKey, window.mParticle.config);
126117

127-
waitForCondition(hasIdentifyReturned)
128-
.then(() => {
118+
await waitForCondition(hasIdentifyReturned);
119+
129120
window.mParticle.logEvent('Test Event');
130121

131122
var product1 = window.mParticle.eCommerce.createProduct('iphone', 'iphoneSKU', 999);
@@ -142,9 +133,6 @@ describe('batch uploader', () => {
142133
batch.events[2].data.event_name.should.equal('Test Event');
143134
batch.events[3].event_type.should.equal('commerce_event');
144135
batch.events[3].data.product_action.action.should.equal('add_to_cart');
145-
146-
done();
147-
});
148136
});
149137

150138
it('should return pending uploads if a 500 is returned', async function() {
@@ -180,12 +168,12 @@ describe('batch uploader', () => {
180168
batch.events[2].data.event_name.should.equal('Test Event');
181169
});
182170

183-
it('should send source_message_id with events to v3 endpoint', function(done) {
171+
it('should send source_message_id with events to v3 endpoint', async () => {
184172
window.mParticle._resetForTests(MPConfig);
185173
window.mParticle.init(apiKey, window.mParticle.config);
186174

187-
waitForCondition(hasIdentifyReturned)
188-
.then(() => {
175+
await waitForCondition(hasIdentifyReturned);
176+
189177
window.mParticle.logEvent('Test Event');
190178

191179
window.mParticle.upload();
@@ -196,16 +184,13 @@ describe('batch uploader', () => {
196184

197185
endpoint.should.equal(urls.events);
198186
batch.events[0].data.should.have.property('source_message_id')
199-
200-
done();
201-
})
202187
});
203188

204-
it('should send user-defined SourceMessageId events to v3 endpoint', function(done) {
189+
it('should send user-defined SourceMessageId events to v3 endpoint', async () => {
205190
window.mParticle._resetForTests(MPConfig);
206191
window.mParticle.init(apiKey, window.mParticle.config);
207-
waitForCondition(hasIdentifyReturned)
208-
.then(() => {
192+
await waitForCondition(hasIdentifyReturned);
193+
209194
window.mParticle.logBaseEvent({
210195
messageType: 4,
211196
name: 'Test Event',
@@ -224,11 +209,9 @@ describe('batch uploader', () => {
224209
endpoint.should.equal(urls.events);
225210
// event batch includes session start, ast, then last event is Test Event
226211
batch.events[batch.events.length-1].data.should.have.property('source_message_id', 'abcdefg')
227-
228-
done();
229-
})
230212
});
231-
213+
214+
// http://go/j-SDKE-301
232215
it('should call the identity callback after a session ends if user is returning to the page after a long period of time', async () => {
233216
// Background of bug that this test fixes:
234217
// User navigates away from page and returns after some time
@@ -253,12 +236,12 @@ describe('batch uploader', () => {
253236
var endSessionFunction = window.mParticle.getInstance()._SessionManager.endSession;
254237

255238
window.mParticle.init(apiKey, window.mParticle.config);
256-
waitForCondition(() => {
257-
return (
258-
window.mParticle.getInstance()._Store?.identityCallInFlight === false
259-
);
260-
})
261-
.then(() => {
239+
await waitForCondition(() => {
240+
return (
241+
window.mParticle.getInstance()._Store?.identityCallInFlight === false
242+
);
243+
});
244+
262245
// Mock end session so that the SDK doesn't actually send it. We do this
263246
// to mimic a return to page behavior, below:
264247
window.mParticle.getInstance()._SessionManager.endSession = function() {}
@@ -275,12 +258,12 @@ describe('batch uploader', () => {
275258

276259
// Initialize imitates returning to the page
277260
window.mParticle.init(apiKey, window.mParticle.config);
278-
waitForCondition(() => {
279-
return (
280-
window.mParticle.getInstance()?._Store?.identityCallInFlight === false
281-
);
282-
})
283-
.then(async () => {
261+
await waitForCondition(() => {
262+
return (
263+
window.mParticle.getInstance()?._Store?.identityCallInFlight === false
264+
);
265+
});
266+
284267
// Manually initiate the upload process - turn event into batches and upload the batch
285268
await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload();
286269

@@ -431,9 +414,6 @@ describe('batch uploader', () => {
431414
batch3SessionStart.data.session_start_unixtime_ms.should.equal(
432415
batch3AST.data.session_start_unixtime_ms
433416
);
434-
435-
})
436-
})
437417
});
438418
});
439419
});

0 commit comments

Comments
 (0)