diff --git a/test/src/tests-batchUploader.ts b/test/src/tests-batchUploader.ts index 533b182bc..09c8df829 100644 --- a/test/src/tests-batchUploader.ts +++ b/test/src/tests-batchUploader.ts @@ -661,12 +661,12 @@ describe('batch uploader', () => { describe('Unit Tests', () => { describe('#queueEvent', () => { - it('should add events to the Pending Events Queue', () => { + it('should add events to the Pending Events Queue', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + const mpInstance = window.mParticle.getInstance(); const uploader = new BatchUploader(mpInstance, 1000); @@ -697,15 +697,13 @@ describe('batch uploader', () => { uploader.queueEvent(event); expect(uploader.eventsQueuedForProcessing.length).to.eql(1); - }) }); - it('should reject batches without events', () => { + it('should reject batches without events', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); const mpInstance = window.mParticle.getInstance(); @@ -716,14 +714,12 @@ describe('batch uploader', () => { expect(uploader.eventsQueuedForProcessing).to.eql([]); expect(uploader.batchesQueuedForProcessing).to.eql([]); - }) }); - it('should add events in the order they are received', () => { + it('should add events in the order they are received', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); const mpInstance = window.mParticle.getInstance(); @@ -737,7 +733,6 @@ describe('batch uploader', () => { expect(uploader.eventsQueuedForProcessing[0]).to.eql(event1); expect(uploader.eventsQueuedForProcessing[1]).to.eql(event2); expect(uploader.eventsQueuedForProcessing[2]).to.eql(event3); - }) }); }); @@ -785,11 +780,10 @@ describe('batch uploader', () => { expect(actualBatchResult.events).to.eql(actualBatch.events); }); - it('should return batches that fail to upload with 500 errors', () => { + it('should return batches that fail to upload with 500 errors', async () => { window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(async () => { + await waitForCondition(hasIdentifyReturned); fetchMock.post(urls.events, 500); @@ -835,16 +829,13 @@ describe('batch uploader', () => { expect( batchesNotUploaded[2].events[0].data.event_name ).to.equal('Test Event 3'); - }) - .catch((e) => { - }); }); it('should return batches that fail to upload with 429 errors', async () => { window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(async () => { + await waitForCondition(hasIdentifyReturned); + fetchMock.post(urls.events, 429); const newLogger = new Logger(window.mParticle.config); @@ -889,14 +880,13 @@ describe('batch uploader', () => { expect( batchesNotUploaded[2].events[0].data.event_name ).to.equal('Test Event 3'); - }) }); it('should return null if batches fail to upload with 401 errors', async () => { window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(async () => { + await waitForCondition(hasIdentifyReturned); + fetchMock.post(urls.events, 401); const newLogger = new Logger(window.mParticle.config); @@ -928,7 +918,6 @@ describe('batch uploader', () => { ); expect(batchesNotUploaded === null).to.equal(true); - }) }); it('should not throw an error when upload is called while storage has not been created yet', async () => { @@ -948,8 +937,8 @@ describe('batch uploader', () => { it('should return batches that fail to unknown HTTP errors', async () => { window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(async () => { + await waitForCondition(hasIdentifyReturned); + fetchMock.post(urls.events, 400); const newLogger = new Logger(window.mParticle.config); @@ -996,9 +985,6 @@ describe('batch uploader', () => { expect( batchesNotUploaded[2].events[0].data.event_name ).to.equal('Test Event 3'); - }) - .catch((e) => { - }); }); }); }); @@ -1016,15 +1002,15 @@ describe('batch uploader', () => { sinon.restore(); }); - it('should use local storage when enabled', (done) => { + it('should use local storage when enabled', async () => { window.mParticle.config.flags = { offlineStorage: '100', }; window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + const getItemSpy = sinon.spy(Storage.prototype, 'getItem'); const setItemSpy = sinon.spy(Storage.prototype, 'setItem'); @@ -1070,22 +1056,16 @@ describe('batch uploader', () => { expect(getItemSpy.getCall(0).lastArg).to.equal( 'mprtcl-v4_abcdef-events' ); - - done(); - }) - .catch((e) => { - }); }); - it('should not use local storage when disabled', () => { + it('should not use local storage when disabled', async () => { window.mParticle.config.flags = { // offlineStorage: '0', // Defaults to 0, but test if not included, just in case }; window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then( () => { + await waitForCondition(hasIdentifyReturned); const getItemSpy = sinon.spy(Storage.prototype, 'getItem'); const setItemSpy = sinon.spy(Storage.prototype, 'setItem'); @@ -1128,9 +1108,6 @@ describe('batch uploader', () => { expect( window.localStorage.getItem('mprtcl-v4_abcdef-events') ).to.equal(null); - }) - .catch((e) => { - }); }); }); @@ -1144,15 +1121,15 @@ describe('batch uploader', () => { window.localStorage.clear(); }); - it('should not save events or batches in local storage', done => { + it('should not save events or batches in local storage', async () => { const eventStorageKey = 'mprtcl-v4_abcdef-events'; const batchStorageKey = 'mprtcl-v4_abcdef-batches'; window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + const mpInstance = window.mParticle.getInstance(); const uploader = mpInstance._APIClient.uploader; @@ -1181,11 +1158,6 @@ describe('batch uploader', () => { window.localStorage.getItem(batchStorageKey), 'Local Storage Batches should be empty' ).to.equal(null); - - done(); - }) - .catch((e) => { - }); }); }); @@ -1209,13 +1181,13 @@ describe('batch uploader', () => { sinon.restore(); }); - it('should store events in Session Storage in order of creation', done => { + it('should store events in Session Storage in order of creation', async () => { const eventStorageKey = 'mprtcl-v4_abcdef-events'; window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + const mpInstance = window.mParticle.getInstance(); const uploader = mpInstance._APIClient.uploader; @@ -1241,12 +1213,6 @@ describe('batch uploader', () => { expect(storedEvents[2], 'Local Storage: Test Event 0').to.eql( eventQueue[2] ); - - done(); - }) - .catch((e) => { - }) - }); it('should purge events from Session Storage upon Batch Creation', async () => { @@ -1256,8 +1222,8 @@ describe('batch uploader', () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(async () => { + await waitForCondition(hasIdentifyReturned); + const mpInstance = window.mParticle.getInstance(); const uploader = mpInstance._APIClient.uploader; @@ -1288,10 +1254,6 @@ describe('batch uploader', () => { // Batch Queue should be empty because batch successfully uploaded expect(uploader.batchesQueuedForProcessing.length).to.equal(0); clock.restore(); - // done(); - }) - .catch((e) => { - }) }); it('should save batches in sequence to Local Storage when an HTTP 500 error is encountered', async () => { @@ -1301,8 +1263,7 @@ describe('batch uploader', () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(async() => { + await waitForCondition(hasIdentifyReturned); const mpInstance = window.mParticle.getInstance(); const uploader = mpInstance._APIClient.uploader; @@ -1345,20 +1306,17 @@ describe('batch uploader', () => { .event_name, 'Batch 2: Custom Event Name' ).to.equal('Test Event 0'); - }) - .catch((e) => { - }) }); - it('should save batches in sequence to Local Storage when an HTTP 429 error is encountered', () => { + it('should save batches in sequence to Local Storage when an HTTP 429 error is encountered', async () => { const batchStorageKey = 'mprtcl-v4_abcdef-batches'; fetchMock.post(urls.events, 429); window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(async () => { + await waitForCondition(hasIdentifyReturned); + const mpInstance = window.mParticle.getInstance(); const uploader = mpInstance._APIClient.uploader; @@ -1397,12 +1355,9 @@ describe('batch uploader', () => { .event_name, 'Batch 2: Custom Event Name' ).to.equal('Test Event 0'); - }) - .catch((e) => { - }) }); - it('should NOT save any batches to Local Storage when an HTTP 401 error is encountered', (done) => { + it('should NOT save any batches to Local Storage when an HTTP 401 error is encountered', async () => { // When a 401 is encountered, we assume that the batch is bad so we clear those // batches from the Upload Queue. Therefore, there should not be anything in // Offline Storage afterwards @@ -1412,9 +1367,9 @@ describe('batch uploader', () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(async () => { - const mpInstance = window.mParticle.getInstance(); + await waitForCondition(hasIdentifyReturned); + + const mpInstance = window.mParticle.getInstance(); const uploader = mpInstance._APIClient.uploader; // Init will fire a Session Start and AST. We are adding event0 @@ -1428,18 +1383,14 @@ describe('batch uploader', () => { expect(window.localStorage.getItem(batchStorageKey)).to.equal( '' ); - done(); - }) - .catch((e) => { - }) }); + // http://go/j-SDKE-301 it('should save batches in sequence to Local Storage when upload is interrupted', async () => { // Interruption in this context means that the first upload is successful, but // the next upload in sequence is not. For example, on a mobile device on the // subway or if a connection is rate limited. In this case, we should save // batches in the order they were created for a future upload attempt - const batchStorageKey = 'mprtcl-v4_abcdef-batches'; // First upload is successful @@ -1455,8 +1406,7 @@ describe('batch uploader', () => { // Set up SDK and Uploader window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(async () => { + await waitForCondition(hasIdentifyReturned); const mpInstance = window.mParticle.getInstance(); const uploader = mpInstance._APIClient.uploader; @@ -1568,13 +1518,10 @@ describe('batch uploader', () => { storedBatches[3].events[1].event_type, 'Batch 4: AST' ).to.equal('application_state_transition'); - }) - .catch((e) => { - console.log('should save batches in sequence to Local Storage when upload is interrupted') - }) }); - it('should attempt to upload batches from Offline Storage before new batches', () => { + // http://go/j-SDKE-301 + it('should attempt to upload batches from Offline Storage before new batches', async () => { // This test should verify that batches read from Offline Storage are prepended // to the upload queue before newly created batches. @@ -1585,8 +1532,7 @@ describe('batch uploader', () => { // Set up SDK and Uploader window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(async () => { + await waitForCondition(hasIdentifyReturned); const mpInstance = window.mParticle.getInstance(); const uploader = mpInstance._APIClient.uploader; @@ -1646,7 +1592,7 @@ describe('batch uploader', () => { // To verify the sequence, we should look at what has been uploaded // as the upload queue and Offline Storage should be empty - expect(fetchMock.calls().length).to.equal(4); + expect(fetchMock.calls().length).to.equal(5); const uploadedBatch1: Batch = JSON.parse( fetchMock.calls()[0][1].body as string @@ -1712,9 +1658,6 @@ describe('batch uploader', () => { uploadedBatch4.events[1].event_type, 'Batch 4: AST' ).to.equal('application_state_transition'); - }) - .catch((e) => { - }) }); describe('noFunctional', () => { diff --git a/test/src/tests-batchUploader_2.ts b/test/src/tests-batchUploader_2.ts index 105a3fe59..5c32551eb 100644 --- a/test/src/tests-batchUploader_2.ts +++ b/test/src/tests-batchUploader_2.ts @@ -44,7 +44,7 @@ describe('batch uploader', () => { fetchMock.restore(); }); - it('should organize events in the order they are processed and maintain that order when uploading', (done) => { + it('should organize events in the order they are processed and maintain that order when uploading', async () => { // Batches should be uploaded in the order they were created to prevent // any potential corruption. fetchMock.post(urls.events, 200); @@ -56,8 +56,9 @@ describe('batch uploader', () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent('Test Event 0'); // Manually initiate the upload process - turn event into batches and upload the batch @@ -108,17 +109,11 @@ describe('batch uploader', () => { expect(batch3.events.length).to.equal(2); expect(batch3.events[0].data.event_name).to.equal('Test Event 4'); expect(batch3.events[1].data.event_name).to.equal('Test Event 5'); - - done(); - - }) - .catch((e) => { - }) }); // TODO: Investigate workflow with unshift vs push // https://go.mparticle.com/work/SQDSDKS-5165 - it.skip('should keep batches in sequence for future retries when an HTTP 500 error occurs', (done) => { + it.skip('should keep batches in sequence for future retries when an HTTP 500 error occurs', () => { // If batches cannot upload, they should be added back to the Batch Queue // in the order they were created so they can be retransmitted. @@ -207,14 +202,12 @@ describe('batch uploader', () => { expect((batchQueue[2].events[2] as CustomEvent).data.event_name).to.equal( 'Test Event 6' ); - - done(); }, 0); }); // TODO: Investigate workflow with unshift vs push // https://go.mparticle.com/work/SQDSDKS-5165 - it.skip('should keep and retry batches in sequence if the transmission fails midway', (done) => { + it.skip('should keep and retry batches in sequence if the transmission fails midway', () => { // First request is successful, subsequent requests fail fetchMock.post(urls.events, 200, { overwriteRoutes: false, @@ -288,8 +281,6 @@ describe('batch uploader', () => { expect((batchQueue[1].events[2] as CustomEvent).data.event_name).to.equal( 'Test Event 6' ); - - done(); }, 0); }); }); diff --git a/test/src/tests-batchUploader_3.ts b/test/src/tests-batchUploader_3.ts index 9009250ee..1f761994b 100644 --- a/test/src/tests-batchUploader_3.ts +++ b/test/src/tests-batchUploader_3.ts @@ -49,12 +49,12 @@ describe('batch uploader', () => { window.mParticle.config.flags.eventBatchingIntervalMillis = 0; }); - it('should use custom v3 endpoint', function(done) { + it('should use custom v3 endpoint', async () => { window.mParticle._resetForTests(MPConfig); fetchMock.resetHistory(); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent('Test Event'); window.mParticle.upload(); @@ -68,16 +68,13 @@ describe('batch uploader', () => { batch.events[1].event_type.should.equal('application_state_transition'); batch.events[2].event_type.should.equal('custom_event'); batch.events[2].data.event_name.should.equal('Test Event'); - - done(); - }) }); - it('should have latitude/longitude for location when batching', function(done) { + it('should have latitude/longitude for location when batching', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.setPosition(100, 100); window.mParticle.logEvent('Test Event'); window.mParticle.upload(); @@ -87,16 +84,13 @@ describe('batch uploader', () => { endpoint.should.equal(urls.events); batch.events[2].data.location.should.have.property('latitude', 100) batch.events[2].data.location.should.have.property('longitude', 100) - - done(); - }) }); - it('should force uploads when using public `upload`', function(done) { + it('should force uploads when using public `upload`', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent('Test Event'); // Identity call // Session start, AST, and `Test Event` are queued. @@ -115,17 +109,14 @@ describe('batch uploader', () => { batch.events[1].event_type.should.equal('application_state_transition'); batch.events[2].event_type.should.equal('custom_event'); batch.events[2].data.event_name.should.equal('Test Event'); - - done(); - }) }); - it('should force uploads when a commerce event is called', function(done) { + it('should force uploads when a commerce event is called', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent('Test Event'); var product1 = window.mParticle.eCommerce.createProduct('iphone', 'iphoneSKU', 999); @@ -142,9 +133,6 @@ describe('batch uploader', () => { batch.events[2].data.event_name.should.equal('Test Event'); batch.events[3].event_type.should.equal('commerce_event'); batch.events[3].data.product_action.action.should.equal('add_to_cart'); - - done(); - }); }); it('should return pending uploads if a 500 is returned', async function() { @@ -180,12 +168,12 @@ describe('batch uploader', () => { batch.events[2].data.event_name.should.equal('Test Event'); }); - it('should send source_message_id with events to v3 endpoint', function(done) { + it('should send source_message_id with events to v3 endpoint', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent('Test Event'); window.mParticle.upload(); @@ -196,16 +184,13 @@ describe('batch uploader', () => { endpoint.should.equal(urls.events); batch.events[0].data.should.have.property('source_message_id') - - done(); - }) }); - it('should send user-defined SourceMessageId events to v3 endpoint', function(done) { + it('should send user-defined SourceMessageId events to v3 endpoint', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logBaseEvent({ messageType: 4, name: 'Test Event', @@ -224,11 +209,9 @@ describe('batch uploader', () => { endpoint.should.equal(urls.events); // event batch includes session start, ast, then last event is Test Event batch.events[batch.events.length-1].data.should.have.property('source_message_id', 'abcdefg') - - done(); - }) }); - + + // http://go/j-SDKE-301 it('should call the identity callback after a session ends if user is returning to the page after a long period of time', async () => { // Background of bug that this test fixes: // User navigates away from page and returns after some time @@ -253,12 +236,12 @@ describe('batch uploader', () => { var endSessionFunction = window.mParticle.getInstance()._SessionManager.endSession; window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(() => { - return ( - window.mParticle.getInstance()._Store?.identityCallInFlight === false - ); - }) - .then(() => { + await waitForCondition(() => { + return ( + window.mParticle.getInstance()._Store?.identityCallInFlight === false + ); + }); + // Mock end session so that the SDK doesn't actually send it. We do this // to mimic a return to page behavior, below: window.mParticle.getInstance()._SessionManager.endSession = function() {} @@ -275,12 +258,12 @@ describe('batch uploader', () => { // Initialize imitates returning to the page window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(() => { - return ( - window.mParticle.getInstance()?._Store?.identityCallInFlight === false - ); - }) - .then(async () => { + await waitForCondition(() => { + return ( + window.mParticle.getInstance()?._Store?.identityCallInFlight === false + ); + }); + // Manually initiate the upload process - turn event into batches and upload the batch await window.mParticle.getInstance()._APIClient.uploader.prepareAndUpload(); @@ -431,9 +414,6 @@ describe('batch uploader', () => { batch3SessionStart.data.session_start_unixtime_ms.should.equal( batch3AST.data.session_start_unixtime_ms ); - - }) - }) }); }); }); \ No newline at end of file diff --git a/test/src/tests-batchUploader_4.ts b/test/src/tests-batchUploader_4.ts index 41c016a29..d8040ad94 100644 --- a/test/src/tests-batchUploader_4.ts +++ b/test/src/tests-batchUploader_4.ts @@ -62,12 +62,12 @@ describe('batch uploader', () => { sinon.restore(); }); - it('should use custom v3 endpoint', function(done) { + it('should use custom v3 endpoint', async () => { window.mParticle._resetForTests(MPConfig); mockServer.requests = []; window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent('Test Event'); mockServer.requests.length.should.equal(1); @@ -80,19 +80,13 @@ describe('batch uploader', () => { batch.events[1].event_type.should.equal('application_state_transition'); batch.events[2].event_type.should.equal('custom_event'); batch.events[2].data.event_name.should.equal('Test Event'); - - done(); - }).catch((e) => { - }) }); - it('should force uploads when using public `upload`', function(done) { + it('should force uploads when using public `upload`', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { - + await waitForCondition(hasIdentifyReturned); window.mParticle.logEvent('Test Event'); @@ -109,17 +103,14 @@ describe('batch uploader', () => { batch.events[1].event_type.should.equal('application_state_transition'); batch.events[2].event_type.should.equal('custom_event'); batch.events[2].data.event_name.should.equal('Test Event'); - - done(); - }) }); - it('should trigger an upload of batch when a commerce event is called', function(done) { + it('should trigger an upload of batch when a commerce event is called', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent('Test Event'); // The only request to the server should be the identify call // Session start, AST, and Test Event are queued. @@ -136,12 +127,9 @@ describe('batch uploader', () => { batch.events[2].data.event_name.should.equal('Test Event'); batch.events[3].event_type.should.equal('commerce_event'); batch.events[3].data.product_action.action.should.equal('add_to_cart'); - - done(); - }) }); - it('should trigger an upload of batch when a UIC occurs', function(done) { + it('should trigger an upload of batch when a UIC occurs', async () => { window.mParticle._resetForTests(MPConfig); // include an identify request so that it creates a UIC window.mParticle.config.identifyRequest = { @@ -151,8 +139,8 @@ describe('batch uploader', () => { }; window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + // Requests sent should be identify call, then UIC event // Session start, AST, and Test Event are queued, and don't appear // in the mockServer.requests @@ -166,9 +154,6 @@ describe('batch uploader', () => { batch.events[0].event_type.should.equal('session_start'); batch.events[1].event_type.should.equal('application_state_transition'); - - done(); - }); }); // Originally, we had the Batch uploader set to force an upload when a UAC event @@ -176,12 +161,11 @@ describe('batch uploader', () => { // make sure the Web SDK does not regress. This test will be removed in a future // Web SDK update // TODO: https://go.mparticle.com/work/SQDSDKS-5891 - it('should NOT trigger an upload of batch when a UAC occurs', function(done) { + it('should NOT trigger an upload of batch when a UAC occurs', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); // Set a user attribute to trigger a UAC event window.mParticle.Identity.getCurrentUser().setUserAttribute('age', 25); @@ -208,12 +192,9 @@ describe('batch uploader', () => { batch.events[0].event_type.should.equal('session_start'); batch.events[1].event_type.should.equal('application_state_transition'); batch.events[2].event_type.should.equal('user_attribute_change'); - - done(); - }); }); - it('should return pending uploads if a 500 is returned', function(done) { + it('should return pending uploads if a 500 is returned', async () => { window.mParticle._resetForTests(MPConfig); mockServer.respondWith(urls.events, [ @@ -224,8 +205,8 @@ describe('batch uploader', () => { window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent('Test Event'); const pendingEvents = window.mParticle.getInstance()._APIClient.uploader.eventsQueuedForProcessing; @@ -245,11 +226,9 @@ describe('batch uploader', () => { batch.events[1].event_type.should.equal('application_state_transition'); batch.events[2].event_type.should.equal('custom_event'); batch.events[2].data.event_name.should.equal('Test Event'); - done(); - }); }); - it('should add a modified boolean of true to a batch that has been modified via a config.onCreateBatch call', function(done) { + it('should add a modified boolean of true to a batch that has been modified via a config.onCreateBatch call', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.config.onCreateBatch = function (batch: Batch) { @@ -257,20 +236,17 @@ describe('batch uploader', () => { }; window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent('Test Event'); window.mParticle.upload() const batch = JSON.parse(mockServer.secondRequest.requestBody); batch.modified.should.equal(true); - done(); - }); - }); - it('should respect rules for the batch modification', function(done) { + it('should respect rules for the batch modification', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.config.onCreateBatch = function (batch) { @@ -284,8 +260,8 @@ describe('batch uploader', () => { window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent('Test Event'); window.mParticle.upload(); @@ -296,11 +272,9 @@ describe('batch uploader', () => { batch.events[1].event_type.should.equal('application_state_transition'); batch.events[2].event_type.should.equal('custom_event'); batch.events[2].data.event_name.should.equal('Modified!'); - done(); - }); }); - it('should add a modified boolean of true to a batch that has been modified via a config.onCreateBatch call', function(done) { + it('should add a modified boolean of true to a batch that has been modified via a config.onCreateBatch call', async () => { window.mParticle._resetForTests(MPConfig); window.mParticle.config.onCreateBatch = function (batch: Batch) { @@ -309,15 +283,13 @@ describe('batch uploader', () => { window.mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent('Test Event'); window.mParticle.upload(); (mockServer.secondRequest === null).should.equal(true); - done(); - }) }); }); }); \ No newline at end of file