Skip to content

Commit edb0ab7

Browse files
authored
test: convert .then to async/await in legacy-alias-request test (#1088)
1 parent 26e60b4 commit edb0ab7

File tree

1 file changed

+12
-30
lines changed

1 file changed

+12
-30
lines changed

test/src/tests-legacy-alias-requests.ts

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ describe('legacy Alias Requests', function() {
6969
window.fetch = originalFetch;
7070
});
7171

72-
it('Alias request should be received when API is called validly', function(done) {
72+
it('Alias request should be received when API is called validly', () => {
7373
mockServer.requests = [];
7474
mockServer.respondWith(urls.alias, [HTTP_OK, {}, JSON.stringify({})]);
7575

@@ -100,11 +100,9 @@ describe('legacy Alias Requests', function() {
100100
expect(dataBody['source_mpid']).to.equal('sourceMpid');
101101
expect(dataBody['start_unixtime_ms']).to.equal(3);
102102
expect(dataBody['end_unixtime_ms']).to.equal(4);
103-
104-
done();
105103
});
106104

107-
it('Alias request should include scope if specified', function(done) {
105+
it('Alias request should include scope if specified', () => {
108106
mockServer.requests = [];
109107
mockServer.respondWith(urls.alias, [HTTP_OK, {}, JSON.stringify({})]);
110108

@@ -125,11 +123,9 @@ describe('legacy Alias Requests', function() {
125123
const requestBody = JSON.parse(request.requestBody);
126124
const dataBody = requestBody['data'];
127125
expect(dataBody['scope']).to.equal('mpid');
128-
129-
done();
130126
});
131127

132-
it('should reject malformed Alias Requests', function(done) {
128+
it('should reject malformed Alias Requests', () => {
133129
mParticle.config.logLevel = 'verbose';
134130
let warnMessage = null;
135131

@@ -257,12 +253,11 @@ describe('legacy Alias Requests', function() {
257253
expect(callbackResult.message).to.equal(undefined);
258254
expect(warnMessage).to.equal(null);
259255
callbackResult = null;
260-
done();
261256
});
262257

263258
});
264259

265-
it('should parse error info from Alias Requests', function(done) {
260+
it('should parse error info from Alias Requests', () => {
266261
clock.restore();
267262
mParticle.init(apiKey, window.mParticle.config);
268263
const errorMessage = 'this is a sample error message';
@@ -288,12 +283,10 @@ describe('legacy Alias Requests', function() {
288283
callbackResult = callback;
289284
callbackResult.httpCode.should.equal(HTTP_BAD_REQUEST);
290285
callbackResult.message.should.equal(errorMessage);
291-
292-
done();
293286
});
294287
});
295288

296-
it('should properly create AliasRequest', function(done) {
289+
it('should properly create AliasRequest', () => {
297290
mParticle._resetForTests(MPConfig);
298291

299292
const cookies = JSON.stringify({
@@ -329,11 +322,9 @@ describe('legacy Alias Requests', function() {
329322
expect(aliasRequest.startTime).to.equal(200);
330323
expect(aliasRequest.endTime).to.equal(400);
331324
clock.restore();
332-
333-
done();
334325
});
335326

336-
it('should fill in missing fst and lst in createAliasRequest', function(done) {
327+
it('should fill in missing fst and lst in createAliasRequest', () => {
337328
mParticle._resetForTests(MPConfig);
338329

339330
const cookies = JSON.stringify({
@@ -373,11 +364,9 @@ describe('legacy Alias Requests', function() {
373364
expect(aliasRequest.endTime).to.equal(1000);
374365

375366
clock.restore();
376-
377-
done();
378367
});
379368

380-
it('should fix startTime when default is outside max window create AliasRequest', function(done) {
369+
it('should fix startTime when default is outside max window create AliasRequest', () => {
381370
mParticle._resetForTests(MPConfig);
382371

383372
const millisPerDay = 24 * 60 * 60 * 1000;
@@ -417,11 +406,9 @@ describe('legacy Alias Requests', function() {
417406
expect(aliasRequest.startTime).to.equal(oldestAllowedStartTime);
418407
expect(aliasRequest.endTime).to.equal(new Date().getTime());
419408
clock.restore();
420-
421-
done();
422409
});
423410

424-
it('should warn if legal aliasRequest cannot be created with MParticleUser', function(done) {
411+
it('should warn if legal aliasRequest cannot be created with MParticleUser', () => {
425412
const millisPerDay = 24 * 60 * 60 * 1000;
426413

427414
mParticle.config.logLevel = 'verbose';
@@ -475,10 +462,9 @@ describe('legacy Alias Requests', function() {
475462
);
476463

477464
clock.restore();
478-
done();
479465
});
480466

481-
it("alias request should have environment 'development' when isDevelopmentMode is true", function(done) {
467+
it("alias request should have environment 'development' when isDevelopmentMode is true", () => {
482468
mParticle._resetForTests(MPConfig);
483469
window.mParticle.config.isDevelopmentMode = true;
484470

@@ -501,10 +487,10 @@ describe('legacy Alias Requests', function() {
501487
const request = mockServer.requests[0];
502488
const requestBody = JSON.parse(request.requestBody);
503489
expect(requestBody['environment']).to.equal('development');expect(requestBody.environment).to.equal('development');
504-
done()
505490
});
506491

507-
it('should have default urls if no custom urls are set in config object, but use custom urls when they are set', function(done) {
492+
// https://go/j-SDKE-301
493+
it('should have default urls if no custom urls are set in config object, but use custom urls when they are set', async () => {
508494
window.mParticle.config.v3SecureServiceUrl =
509495
'testtesttest-custom-v3secureserviceurl/v3/JS/';
510496
window.mParticle.config.configUrl =
@@ -515,8 +501,7 @@ describe('legacy Alias Requests', function() {
515501
mockServer.respondWith('https://testtesttest-custom-v3secureserviceurl/v3/JS/test_key/events', HTTP_OK, JSON.stringify({ mpid: testMPID, Store: {}}));
516502

517503
mParticle.init(apiKey, window.mParticle.config);
518-
waitForCondition(hasIdentifyReturned)
519-
.then(() => {
504+
await waitForCondition(hasIdentifyReturned);
520505

521506
mParticle.getInstance()._Store.SDKConfig.v3SecureServiceUrl.should.equal(window.mParticle.config.v3SecureServiceUrl)
522507
mParticle.getInstance()._Store.SDKConfig.configUrl.should.equal(window.mParticle.config.configUrl)
@@ -554,9 +539,6 @@ describe('legacy Alias Requests', function() {
554539
mockServer.requests[0].url.should.equal(
555540
'https://' + window.mParticle.config.aliasUrl + 'test_key/Alias'
556541
);
557-
})
558-
559-
done();
560542
});
561543

562544
});

0 commit comments

Comments
 (0)