diff --git a/test/src/tests-event-logging.js b/test/src/tests-event-logging.js index 6c52f6570..bd86767fa 100644 --- a/test/src/tests-event-logging.js +++ b/test/src/tests-event-logging.js @@ -29,9 +29,9 @@ describe('event logging', function() { mParticle._resetForTests(MPConfig); }); - it('should log an event', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log an event', async () => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent( 'Test Event', mParticle.EventType.Navigation, @@ -49,14 +49,11 @@ describe('event logging', function() { ); testEventBatch.should.have.property('mpid', testMPID); - - done(); - }) }); - it('should log an event with new device id when set on setDeviceId', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log an event with new device id when set on setDeviceId', async () => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent( 'Test Event', mParticle.EventType.Navigation, @@ -74,32 +71,25 @@ describe('event logging', function() { // das should be the one passed to setDeviceId() testEvent2Batch.should.have.property('mp_deviceid', 'foo-guid'); - - done(); - }) }); - it('should log an event with new device id when set via mParticle.config', function(done) { + it('should log an event with new device id when set via mParticle.config', async () => { mParticle._resetForTests(MPConfig); window.mParticle.config.deviceId = 'foo-guid'; mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); window.mParticle.logEvent('Test Event'); const testEventBatch = findBatch(fetchMock.calls(), 'Test Event'); // this das should be the SDK auto generated one testEventBatch.should.have.property('mp_deviceid', 'foo-guid'); - - done(); - }) }); - it('should allow an event to bypass server upload', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should allow an event to bypass server upload', async () => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent( 'Test Standard Upload', mParticle.EventType.Navigation, @@ -151,14 +141,11 @@ describe('event logging', function() { uploadEventBatch.should.have.property('mpid', testMPID); Should(bypassedEvent).not.be.ok(); - - done(); - }) }); - it('should allow an event to bypass server upload via logBaseEvent', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should allow an event to bypass server upload via logBaseEvent', async () => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logBaseEvent( { name: 'Test Standard Upload', @@ -217,14 +204,11 @@ describe('event logging', function() { uploadEventBatch.should.have.property('mpid', testMPID); Should(bypassedEvent).not.be.ok(); - - done(); - }) }); - it('should log an error', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log an error', async () => { + await waitForCondition(hasIdentifyReturned); + mParticle.logError('my error'); const errorEvent = findEventFromRequest(fetchMock.calls(), 'my error'); @@ -234,14 +218,11 @@ describe('event logging', function() { errorEvent.data.should.have.property('message', 'Error'); errorEvent.data.should.have.property('custom_attributes'); errorEvent.data.custom_attributes.should.have.property('m', 'my error'); - - done(); - }) }); - it('should log an error with name, message, stack', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log an error with name, message, stack', async () => { + await waitForCondition(hasIdentifyReturned); + const error = new Error('my error'); error.stack = 'my stacktrace'; @@ -259,15 +240,11 @@ describe('event logging', function() { 't', 'my stacktrace' ); - - done(); - }) - }); - it('should log an error with custom attrs', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log an error with custom attrs', async () => { + await waitForCondition(hasIdentifyReturned); + const error = new Error('my error'); error.stack = 'my stacktrace'; @@ -286,14 +263,11 @@ describe('event logging', function() { 'myData', 'my data' ); - - done(); - }) }); - it('should sanitize error custom attrs', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should sanitize error custom attrs', async () => { + await waitForCondition(hasIdentifyReturned); + const bond = sinon.spy(mParticle.getInstance().Logger, 'warning'); mParticle.logError('my error', { invalid: ['my invalid attr'], @@ -314,14 +288,11 @@ describe('event logging', function() { bond.getCalls()[0].args[0].should.eql( "For 'my error', the corresponding attribute value of 'invalid' must be a string, number, boolean, or null." ); - - done(); - }) }); - it('should log an AST with firstRun = true when first visiting a page, and firstRun = false when reloading the page', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log an AST with firstRun = true when first visiting a page, and firstRun = false when reloading the page', async () => { + await waitForCondition(hasIdentifyReturned); + const astEvent = findEventFromRequest( fetchMock.calls(), 'application_state_transition' @@ -344,12 +315,11 @@ describe('event logging', function() { fetchMock.resetHistory(); mParticle.init(apiKey, window.mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); const astEvent2 = findEventFromRequest( fetchMock.calls(), @@ -357,24 +327,20 @@ describe('event logging', function() { ); astEvent2.data.should.have.property('is_first_run', false); - - done(); - }) - }) }); - it('should log an AST on init with firstRun = false when cookies already exist', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log an AST on init with firstRun = false when cookies already exist', async () => { + await waitForCondition(hasIdentifyReturned); + // cookies currently exist, mParticle.init called from beforeEach fetchMock.resetHistory(); // log second AST - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); + mParticle.init(apiKey, window.mParticle.config); const astEvent = findEventFromRequest( @@ -382,15 +348,11 @@ describe('event logging', function() { 'application_state_transition' ); astEvent.data.should.have.property('is_first_run', false); - - done(); - }) - }); }); - it('should log a page view', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log a page view', async () => { + await waitForCondition(hasIdentifyReturned); + mParticle.logPageView(); const pageViewEvent = findEventFromRequest( @@ -409,14 +371,11 @@ describe('event logging', function() { 'title', window.document.title ); - - done(); - }) }); - it('should log custom page view', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log custom page view', async () => { + await waitForCondition(hasIdentifyReturned); + mParticle.logPageView( 'My Page View', { testattr: 1 }, @@ -442,14 +401,11 @@ describe('event logging', function() { 'MyCustom.Flag', 'Test' ); - - done(); - }) }); - it('should pass custom flags in page views', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should pass custom flags in page views', async () => { + await waitForCondition(hasIdentifyReturned); + mParticle.logPageView('test', null, { 'MyCustom.Flag': 'Test', }); @@ -466,14 +422,11 @@ describe('event logging', function() { 'MyCustom.Flag', 'Test' ); - - done(); - }) }); - it('should allow a page view to bypass server upload', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should allow a page view to bypass server upload', async () => { + await waitForCondition(hasIdentifyReturned); + mParticle.logPageView('test bypass', null, null, { shouldUploadEvent: false, }); @@ -484,13 +437,11 @@ describe('event logging', function() { ); Should(pageViewEvent).not.be.ok(); - done(); - }) }); - it('should not log a PageView event if there are invalid attrs', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should not log a PageView event if there are invalid attrs', async () => { + await waitForCondition(hasIdentifyReturned); + mParticle.logPageView('test1', 'invalid', null); const pageViewEvent = findEventFromRequest( fetchMock.calls(), @@ -498,14 +449,11 @@ describe('event logging', function() { ); Should(pageViewEvent).not.be.ok(); - - done(); - }) }); - it('should not log an event that has an invalid customFlags', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should not log an event that has an invalid customFlags', async () => { + await waitForCondition(hasIdentifyReturned); + mParticle.logPageView('test', null, 'invalid'); const pageViewEvent = findEventFromRequest( @@ -513,14 +461,11 @@ describe('event logging', function() { 'test' ); Should(pageViewEvent).not.be.ok(); - - done(); - }) }); - it('should log event with name PageView when an invalid event name is passed', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log event with name PageView when an invalid event name is passed', async () => { + await waitForCondition(hasIdentifyReturned); + fetchMock.resetHistory(); mParticle.logPageView(null); @@ -548,79 +493,61 @@ describe('event logging', function() { 'screen_view' ); pageViewEvent3.data.screen_name.should.equal('PageView'); - - done(); - }) }); - it('should log opt out', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log opt out', async () => { + await waitForCondition(hasIdentifyReturned); + mParticle.setOptOut(true); const optOutEvent = findEventFromRequest(fetchMock.calls(), 'opt_out'); optOutEvent.event_type.should.equal('opt_out'); optOutEvent.data.should.have.property('is_opted_out', true); - - done(); - }) }); - it('log event requires name', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('log event requires name', async () => { + await waitForCondition(hasIdentifyReturned); + fetchMock.resetHistory(); mParticle.logEvent(); fetchMock.calls().should.have.lengthOf(0); - - done(); - }) }); - it('log event requires valid event type', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('log event requires valid event type', async () => { + await waitForCondition(hasIdentifyReturned); + fetchMock.resetHistory(); mParticle.logEvent('test', 100); fetchMock.calls().should.have.lengthOf(0); - - done(); - }); }); - it('event attributes must be object', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('event attributes must be object', async () => { + await waitForCondition(hasIdentifyReturned); + mParticle.logEvent('Test Event', null, 1); const testEvent = findEventFromRequest(fetchMock.calls(), 'Test Event'); testEvent.data.should.have.property('custom_attributes', null); - - done(); - }); }); - it('opting out should prevent events being sent', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('opting out should prevent events being sent', async () => { + await waitForCondition(hasIdentifyReturned); + mParticle.setOptOut(true); fetchMock.resetHistory(); mParticle.logEvent('test'); fetchMock.calls().should.have.lengthOf(0); - - done(); - }); }); - it('after logging optout, and reloading, events still should not be sent until opt out is enabled when using local storage', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('after logging optout, and reloading, events still should not be sent until opt out is enabled when using local storage', async () => { + await waitForCondition(hasIdentifyReturned); + mParticle.setOptOut(true); fetchMock.resetHistory(); @@ -641,14 +568,11 @@ describe('event logging', function() { mParticle.logEvent('test'); fetchMock.calls().should.have.lengthOf(0); - - done(); - }) }); - it('after logging optout, and reloading, events still should not be sent until opt out is enabled when using cookie storage', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('after logging optout, and reloading, events still should not be sent until opt out is enabled when using cookie storage', async () => { + await waitForCondition(hasIdentifyReturned); + mParticle.config.useCookieStorage = true; mParticle.init(apiKey, window.mParticle.config); mParticle.setOptOut(true); @@ -660,47 +584,43 @@ describe('event logging', function() { mParticle.setOptOut(false); mParticle.init(apiKey, window.mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); + fetchMock.resetHistory(); mParticle.logEvent('test'); fetchMock.calls().should.have.lengthOf(1); mParticle.setOptOut(true); mParticle.init(apiKey, window.mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); + fetchMock.resetHistory(); mParticle.logEvent('test'); fetchMock.calls().should.have.lengthOf(0); - - done(); - }); - }); - }) }); - it('should log identify event', function(done) { + // http://go/j-SDKE-301 + it('should log identify event', async () => { fetchMockSuccess(urls.identify, { mpid: testMPID, is_logged_in: false }); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + mParticle.Identity.identify(); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); + const data = getIdentityEvent(mockServer.requests, 'identify'); data.should.have.properties( 'client_sdk', @@ -711,25 +631,22 @@ describe('event logging', function() { 'request_timestamp_ms', 'context' ); - }); - done(); - }); }); - it('should log logout event', function(done) { + it('should log logout event', async () => { fetchMockSuccess(urls.logout, { mpid: 'logoutMPID', is_logged_in: false }); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + mParticle.Identity.logout(); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.Identity.getCurrentUser()?.getMPID() === 'logoutMPID' ); - }) - .then(() => { + }); + const data = getIdentityEvent(fetchMock.calls(), 'logout'); data.should.have.properties( 'client_sdk', @@ -740,26 +657,22 @@ describe('event logging', function() { 'request_timestamp_ms', 'context' ); - - done(); - }) - }) }); - it('should log login event', function(done) { + it('should log login event', async () => { fetchMockSuccess(urls.login, { mpid: 'loginMPID', is_logged_in: false }); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + mParticle.Identity.login(); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.Identity.getCurrentUser()?.getMPID() === 'loginMPID' ); - }) - .then(() => { + }); + const data = getIdentityEvent(fetchMock.calls(), 'login'); data.should.have.properties( 'client_sdk', @@ -770,15 +683,11 @@ describe('event logging', function() { 'request_timestamp_ms', 'context' ); - - done(); - }) - }) }); - it('should log modify event', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log modify event', async () => { + await waitForCondition(hasIdentifyReturned); + fetchMockSuccess(urls.modify, { change_results: [ { @@ -788,11 +697,12 @@ describe('event logging', function() { ] }); mParticle.Identity.modify(); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }).then(() => { + }); + const data = getIdentityEvent(fetchMock.calls(), 'modify'); data.should.have.properties( 'client_sdk', @@ -802,27 +712,20 @@ describe('event logging', function() { 'request_timestamp_ms', 'context' ); - - done(); - }) - }) }); - it('should send das with each event logged', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should send das with each event logged', async () => { + await waitForCondition(hasIdentifyReturned); + window.mParticle.logEvent('Test Event'); const testEventBatch = findBatch(fetchMock.calls(), 'Test Event'); testEventBatch.should.have.property('mp_deviceid'); testEventBatch.mp_deviceid.length.should.equal(36); - done(); - }) }); - it('should send consent state with each event logged', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should send consent state with each event logged', async () => { + await waitForCondition(hasIdentifyReturned); const consentState = mParticle.Consent.createConsentState(); consentState.addGDPRConsentState( 'foo purpose', @@ -856,14 +759,10 @@ describe('event logging', function() { testEvent2.should.have.property('consent_state', null); - done(); - }) - }); - it('should log integration attributes with each event', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log integration attributes with each event', async () => { + await waitForCondition(hasIdentifyReturned); mParticle.setIntegrationAttribute(128, { MCID: 'abcdefg' }); mParticle.logEvent('Test Event'); const testEvent = findBatch(fetchMock.calls(), 'Test Event'); @@ -875,14 +774,10 @@ describe('event logging', function() { 'abcdefg' ); - done(); - }) - }); - it('should run the callback once when tracking succeeds', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should run the callback once when tracking succeeds', async () => { + await waitForCondition(hasIdentifyReturned); const clock = sinon.useFakeTimers(); mParticle.init(apiKey, window.mParticle.config); @@ -915,24 +810,19 @@ describe('event logging', function() { clock.restore(); - done(); - }) - }); - it('should run the callback once when tracking fails', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should run the callback once when tracking fails', async () => { + await waitForCondition(hasIdentifyReturned) const clock = sinon.useFakeTimers(); mParticle.init(apiKey, window.mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); }) - .then(() => { let successCallbackCalled = false; let numberTimesCalled = 0; @@ -963,22 +853,16 @@ describe('event logging', function() { navigator.geolocation.shouldFail = false; clock.restore(); - - done(); - }) - }) }); - it('should pass the found or existing position to the callback in startTrackingLocation', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should pass the found or existing position to the callback in startTrackingLocation', async () => { + await waitForCondition(hasIdentifyReturned); mParticle.init(apiKey, window.mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); }) - .then(() => { let currentPosition; function callback(position) { @@ -997,24 +881,18 @@ describe('event logging', function() { currentPosition.coords.longitude.should.equal(longitudeResult); clock.restore(); - - done(); - }) - }) }); - it('should run the callback if tracking already exists', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should run the callback if tracking already exists', async () => { + await waitForCondition(hasIdentifyReturned); mParticle.init(apiKey, window.mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); const clock = sinon.useFakeTimers(); @@ -1037,27 +915,21 @@ describe('event logging', function() { testEvent.data.location.longitude.should.equal(longitudeResult); clock.restore(); - - done(); - }) - }) }); - it('should log appName in the payload on v3 endpoint when set on config prior to init', function(done) { + it('should log appName in the payload on v3 endpoint when set on config prior to init', async () => { mParticle.config.appName = 'a name'; mParticle.config.flags = { eventBatchingIntervalMillis: 0, }; - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); mParticle.init(apiKey, mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); window.mParticle.logEvent('Test Event'); @@ -1069,51 +941,38 @@ describe('event logging', function() { ); delete window.mParticle.config.flags; - - done(); - }) - }) }); - it('should log AST first_run as true on new page loads, and false for when a page has previously been loaded', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log AST first_run as true on new page loads, and false for when a page has previously been loaded', async () => { + await waitForCondition(hasIdentifyReturned); mParticle._resetForTests(MPConfig); mParticle.init(apiKey, mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); }) - .then(() => { const batch = JSON.parse(fetchMock.lastOptions().body); batch.events[0].data.should.have.property('is_first_run', true); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); }) - .then(() => { mParticle.init(apiKey, mParticle.config); const batch2 = JSON.parse(fetchMock.lastOptions().body); batch2.events[0].data.should.have.property('is_first_run', false); delete window.mParticle.config.flags; - - done(); - }) - }) - }) }); - it('should log AST with launch_referral with a url', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log AST with launch_referral with a url', async () => { + await waitForCondition(hasIdentifyReturned); mParticle._resetForTests(MPConfig); mParticle.config.flags = { @@ -1121,12 +980,11 @@ describe('event logging', function() { }; mParticle.init(apiKey, mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); const batch = JSON.parse(fetchMock.lastOptions().body); @@ -1136,24 +994,18 @@ describe('event logging', function() { ); delete window.mParticle.config.flags; - - done(); - }) - }) - }); - it('should log appName in the payload on v3 endpoint when set on config prior to init', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log appName in the payload on v3 endpoint when set on config prior to init', async () => { + await waitForCondition(hasIdentifyReturned); mParticle.config.flags = { eventBatchingIntervalMillis: 0, }; - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }).then(() => { + }); mParticle.init(apiKey, mParticle.config); @@ -1168,13 +1020,9 @@ describe('event logging', function() { ); delete window.mParticle.config.flags; - - done(); - }) - }) }); - it('should log a batch to v3 with data planning in the payload', function(done) { + it('should log a batch to v3 with data planning in the payload', async () => { mParticle.config.logLevel = 'verbose'; mParticle.config.flags = { eventBatchingIntervalMillis: 0, @@ -1184,16 +1032,14 @@ describe('event logging', function() { planVersion: 10, }; - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); mParticle.init(apiKey, mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); window.mParticle.logEvent('Test Event'); const batch = JSON.parse(fetchMock.lastOptions().body); @@ -1204,15 +1050,10 @@ describe('event logging', function() { batch.context.data_plan.should.have.property('plan_id', 'plan_slug'); delete window.mParticle.config.flags; - - done(); - }) - }) }); - it('should log a batch to v3 with no version if no version is passed', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log a batch to v3 with no version if no version is passed', async () => { + await waitForCondition(hasIdentifyReturned); mParticle.config.flags = { eventBatchingIntervalMillis: 0, }; @@ -1221,12 +1062,11 @@ describe('event logging', function() { }; mParticle.init(apiKey, mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); window.mParticle.logEvent('Test Event'); const batch = JSON.parse(fetchMock.lastOptions().body); @@ -1237,15 +1077,10 @@ describe('event logging', function() { batch.context.data_plan.should.have.property('plan_id', 'plan_slug'); delete window.mParticle.config.flags; - - done(); - }) - }) }); - it('should log a batch to v3 with no context if no data plan is passed', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log a batch to v3 with no context if no data plan is passed', async () => { + await waitForCondition(hasIdentifyReturned); mParticle.config.flags = { eventBatchingIntervalMillis: 0, }; @@ -1254,12 +1089,11 @@ describe('event logging', function() { }; mParticle.init(apiKey, mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); window.mParticle.logEvent('Test Event'); const batch = JSON.parse(fetchMock.lastOptions().body); @@ -1267,15 +1101,10 @@ describe('event logging', function() { batch.should.not.have.property('context'); delete window.mParticle.config.flags; - - done(); - }) - }) }); - it('should log an error if a non slug string is passed as the dataplan planId', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log an error if a non slug string is passed as the dataplan planId', async () => { + await waitForCondition(hasIdentifyReturned); let errorMessage; mParticle.config.logLevel = 'verbose'; @@ -1295,12 +1124,11 @@ describe('event logging', function() { }; mParticle.init(apiKey, mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); window.mParticle.logEvent('Test Event'); errorMessage.should.equal( @@ -1309,15 +1137,10 @@ describe('event logging', function() { const batch = JSON.parse(fetchMock.lastOptions().body); batch.should.not.have.property('context'); delete window.mParticle.config.flags; - - done(); - }) - }) }); - it('should log consent properly to v3 endpoint ', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should log consent properly to v3 endpoint ', async () => { + await waitForCondition(hasIdentifyReturned); mParticle.config.flags = { eventBatchingIntervalMillis: 0, }; @@ -1326,12 +1149,11 @@ describe('event logging', function() { }; mParticle.init(apiKey, mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); }) - .then(() => { const user = mParticle.Identity.getCurrentUser(); // Add to your consent state const consentState = mParticle.Consent.createConsentState(); @@ -1408,26 +1230,20 @@ describe('event logging', function() { ); delete window.mParticle.config.flags; - - done(); - }) - }) }); - it('should sanitize transaction attributes in the payload on v3 endpoint', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should sanitize transaction attributes in the payload on v3 endpoint', async () => { + await waitForCondition(hasIdentifyReturned); mParticle.config.flags = { eventBatchingIntervalMillis: 0, }; mParticle.init(apiKey, mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); const product1 = mParticle.eCommerce.createProduct( 'iphone', 'iphoneSKU', @@ -1466,26 +1282,20 @@ describe('event logging', function() { batch.events[0].data.product_action.tax_amount.should.equal(0); delete window.mParticle.config.flags; - - done(); - }) - }) }); - it('should sanitize product attributes in the payload on v3 endpoint', function(done) { - waitForCondition(hasIdentifyReturned) - .then(() => { + it('should sanitize product attributes in the payload on v3 endpoint', async () => { + await waitForCondition(hasIdentifyReturned); mParticle.config.flags = { eventBatchingIntervalMillis: 0, }; mParticle.init(apiKey, mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.getInstance()._Store.identityCallInFlight === false ); - }) - .then(() => { + }); const product1 = mParticle.eCommerce.createProduct( 'iphone', 'iphoneSKU', @@ -1550,9 +1360,5 @@ describe('event logging', function() { ); delete window.mParticle.config.flags; - - done(); - }) - }) }); }); \ No newline at end of file