From 1568bb2eafcfb8cb4f06cf2ad8d779b28f506b1d Mon Sep 17 00:00:00 2001 From: Jaissica Date: Mon, 6 Oct 2025 22:17:18 -0400 Subject: [PATCH] test: converted .then to async/await in tests-forwarders --- test/src/tests-forwarders.ts | 164 ++++++++++------------------------- 1 file changed, 48 insertions(+), 116 deletions(-) diff --git a/test/src/tests-forwarders.ts b/test/src/tests-forwarders.ts index 11156d7cf..6b3b22d19 100644 --- a/test/src/tests-forwarders.ts +++ b/test/src/tests-forwarders.ts @@ -129,7 +129,7 @@ describe('forwarders', function() { delete window.MockForwarder1; }); - it('should add forwarders via dynamic script loading via the addForwarder method', function(done) { + it('should add forwarders via dynamic script loading via the addForwarder method', () => { mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder(); @@ -145,8 +145,6 @@ describe('forwarders', function() { .getInstance() ._getActiveForwarders() .length.should.equal(1); - - done(); }); it('should invoke forwarder setIdentity on initialized forwarders (debug = false)', async () => { @@ -177,7 +175,7 @@ describe('forwarders', function() { ); }); - it('should permit forwarder if no consent configured.', function(done) { + it('should permit forwarder if no consent configured.', () => { mParticle.config.isDevelopmentMode = false; const mockForwarder = new MockForwarder(); mockForwarder.register(window.mParticle.config); @@ -194,10 +192,9 @@ describe('forwarders', function() { null ); expect(enabled).to.be.ok; - done(); }); - it('should not permit forwarder if consent configured but there is no user.', function(done) { + it('should not permit forwarder if consent configured but there is no user.', () => { const enableForwarder = true; const consented = false; mParticle._resetForTests(MPConfig); @@ -224,7 +221,6 @@ describe('forwarders', function() { null ); expect(enabled).to.not.be.ok; - done(); }); const MockUser = function() { @@ -239,7 +235,7 @@ describe('forwarders', function() { } as IMParticleUser; }; - it("should disable forwarder if 'Do Not Forward' when 'Consent Rejected' is selected and user consent has been rejected", function(done) { + it("should disable forwarder if 'Do Not Forward' when 'Consent Rejected' is selected and user consent has been rejected", () => { const enableForwarder = false; // 'Do Not Forward' chosen in UI, 'includeOnMatch' in config const consented = false; const userConsent = false; @@ -282,11 +278,9 @@ describe('forwarders', function() { user ); expect(enabled).to.not.be.ok; - - done(); }); - it("should disable forwarder if 'Do Not Forward' when 'Consent Accepted' is selected and consent has been accepted", function(done) { + it("should disable forwarder if 'Do Not Forward' when 'Consent Accepted' is selected and consent has been accepted", () => { const enableForwarder = false; // 'Do Not Forward' chosen in UI, 'includeOnMatch' in config const consented = true; const userConsent = true; @@ -327,11 +321,9 @@ describe('forwarders', function() { user ); expect(enabled).to.not.be.ok; - - done(); }); - it("should enable forwarder if 'Only Forward' when 'Consent Rejected' is selected and consent has been rejected", function(done) { + it("should enable forwarder if 'Only Forward' when 'Consent Rejected' is selected and consent has been rejected", () => { const enableForwarder = true; // 'Only Forward' chosen in UI, 'includeOnMatch' in config const consented = false; const userConsent = false; @@ -371,11 +363,9 @@ describe('forwarders', function() { user ); expect(enabled).to.be.ok; - - done(); }); - it("should enable forwarder if 'Only Forward' when 'Consent Accepted' is selected and consent has been accepted", function(done) { + it("should enable forwarder if 'Only Forward' when 'Consent Accepted' is selected and consent has been accepted", () => { const enableForwarder = true; // 'Only Forward' chosen in UI, 'includeOnMatch' in config const consented = true; const userConsent = true; @@ -416,11 +406,9 @@ describe('forwarders', function() { user ); expect(enabled).to.be.ok; - - done(); }); - it("should disable forwarder if 'Only Forward' when 'Consent Accepted' is selected and consent has been rejected", function(done) { + it("should disable forwarder if 'Only Forward' when 'Consent Accepted' is selected and consent has been rejected", () => { const enableForwarder = true; // 'Only Forward' chosen in UI, 'includeOnMatch' in config const consented = true; const userConsent = false; @@ -461,11 +449,9 @@ describe('forwarders', function() { user ); expect(enabled).to.not.be.ok; - - done(); }); - it("should enable forwarder if 'Do Not Forward' when 'Consent Rejected' is selected and consent has been accepted", function(done) { + it("should enable forwarder if 'Do Not Forward' when 'Consent Rejected' is selected and consent has been accepted", () => { const enableForwarder = false; // 'Do Not Forward' chosen in UI, 'includeOnMatch' in config const consented = false; const userConsent = true; @@ -506,11 +492,9 @@ describe('forwarders', function() { user ); expect(enabled).to.be.ok; - - done(); }); - it("should enable forwarder if 'Do Not Forward' when 'Consent Accepted' is selected and consent has been rejected", function(done) { + it("should enable forwarder if 'Do Not Forward' when 'Consent Accepted' is selected and consent has been rejected", () => { const enableForwarder = false; // 'Do Not Forward' chosen in UI, 'includeOnMatch' in config const consented = true; const userConsent = false; @@ -551,11 +535,9 @@ describe('forwarders', function() { user ); expect(enabled).to.be.ok; - - done(); }); - it("should enable forwarder if 'Do Not Forward' when 'Consent Rejected' is selected and consent has been accepted", function(done) { + it("should enable forwarder if 'Do Not Forward' when 'Consent Rejected' is selected and consent has been accepted", () => { const enableForwarder = false; // 'Do Not Forward' chosen in UI, 'includeOnMatch' in config const consented = false; const userConsent = true; @@ -596,11 +578,9 @@ describe('forwarders', function() { user ); expect(enabled).to.be.ok; - - done(); }); - it("should disable forwarder if 'Do Not Forward' when CCPA is 'Not Present' is selected and user CCPA is not present", function(done) { + it("should disable forwarder if 'Do Not Forward' when CCPA is 'Not Present' is selected and user CCPA is not present", () => { const enableForwarder = false; // 'Do Not Forward' chosen in UI, 'includeOnMatch' in config const consentPresent = false; const userConsentPresent = false; @@ -644,11 +624,9 @@ describe('forwarders', function() { user ); expect(enabled).to.not.be.ok; - - done(); }); - it("should disable forwarder if 'Do Not Forward' when CCPA is 'Present' is selected and user CCPA is present", function(done) { + it("should disable forwarder if 'Do Not Forward' when CCPA is 'Present' is selected and user CCPA is present", () => { const enableForwarder = false; // 'Do Not Forward' chosen in UI, 'includeOnMatch' in config const consentPresent = true; const userConsentPresent = true; @@ -692,11 +670,9 @@ describe('forwarders', function() { user ); expect(enabled).to.not.be.ok; - - done(); }); - it("should enable forwarder if 'Only Forward' when CCPA is 'Not Present' is selected and user CCPA is not present", function(done) { + it("should enable forwarder if 'Only Forward' when CCPA is 'Not Present' is selected and user CCPA is not present", () => { const enableForwarder = true; // 'Only Forward' chosen in UI, 'includeOnMatch' in config const consentPresent = false; const userConsentPresent = false; @@ -741,11 +717,9 @@ describe('forwarders', function() { ); expect(enabled).to.be.ok; - - done(); }); - it("should enable forwarder if 'Only Forward' when CCPA data sale opt out is present is selected and user CCPA is present.", function(done) { + it("should enable forwarder if 'Only Forward' when CCPA data sale opt out is present is selected and user CCPA is present.", () => { const enableForwarder = true; // 'Only Forward' chosen in UI, 'includeOnMatch' in config const consentPresent = true; const userConsentPresent = true; @@ -789,11 +763,9 @@ describe('forwarders', function() { user ); expect(enabled).to.be.ok; - - done(); }); - it("should disable forwarder if 'Only Forward' when CCPA is 'Present' is selected and user CCPA is not present", function(done) { + it("should disable forwarder if 'Only Forward' when CCPA is 'Present' is selected and user CCPA is not present", () => { const enableForwarder = true; // 'Only Forward' chosen in UI, 'includeOnMatch' in config const consentPresent = true; const userConsentPresent = false; @@ -837,11 +809,9 @@ describe('forwarders', function() { user ); expect(enabled).to.not.be.ok; - - done(); }); - it("should enable forwarder if 'Do Not Forward' when CCPA is 'Not Present' is selected and user CCPA is present", function(done) { + it("should enable forwarder if 'Do Not Forward' when CCPA is 'Not Present' is selected and user CCPA is present", () => { const enableForwarder = false; // 'Do Not Forward' chosen in UI, 'includeOnMatch' in config const consentPresent = false; const userConsentPresent = true; @@ -885,11 +855,9 @@ describe('forwarders', function() { user ); expect(enabled).to.be.ok; - - done(); }); - it("should enable forwarder if 'Do Not Forward' when CCPA is 'Present' is selected and user CCPA is not present", function(done) { + it("should enable forwarder if 'Do Not Forward' when CCPA is 'Present' is selected and user CCPA is not present", () => { const enableForwarder = false; // 'Do Not Forward' chosen in UI, 'includeOnMatch' in config const consentPresent = true; const userConsentPresent = false; @@ -933,11 +901,9 @@ describe('forwarders', function() { user ); expect(enabled).to.be.ok; - - done(); }); - it("does not initialize a forwarder when forwarder's isDebug != mParticle.isDevelopmentMode", function(done) { + it("does not initialize a forwarder when forwarder's isDebug != mParticle.isDevelopmentMode", () => { mParticle._resetForTests(MPConfig); mParticle.config.isDevelopmentMode = false; const mockForwarder = new MockForwarder(); @@ -955,11 +921,9 @@ describe('forwarders', function() { .getInstance() ._getActiveForwarders() .length.should.equal(0); - - done(); }); - it('initializes a forwarder with isDebug = false && mParticle.config.isDevelopmentMode = false', function(done) { + it('initializes a forwarder with isDebug = false && mParticle.config.isDevelopmentMode = false', () => { mParticle._resetForTests(MPConfig); mParticle.config.isDevelopmentMode = false; const mockForwarder = new MockForwarder(); @@ -977,11 +941,9 @@ describe('forwarders', function() { expect( mParticle.getInstance()._Store.configuredForwarders.length ).equal(1); - - done(); }); - it('initializes a forwarder with isDebug = true && mParticle.config.isDevelopmentMode = true', function(done) { + it('initializes a forwarder with isDebug = true && mParticle.config.isDevelopmentMode = true', () => { mParticle._resetForTests(MPConfig); mParticle.config.isDevelopmentMode = true; const mockForwarder = new MockForwarder(); @@ -996,11 +958,9 @@ describe('forwarders', function() { expect( mParticle.getInstance()._Store.configuredForwarders.length ).equal(1); - - done(); }); - it('initializes forwarders when isDebug = mParticle.config.isDevelopmentMode', function(done) { + it('initializes forwarders when isDebug = mParticle.config.isDevelopmentMode', () => { mParticle._resetForTests(MPConfig); mParticle.config.isDevelopmentMode = false; const mockForwarder = new MockForwarder(); @@ -1022,8 +982,6 @@ describe('forwarders', function() { expect( mParticle.getInstance()._Store.configuredForwarders.length ).equal(1); - - done(); }); it("sends events to forwarder when forwarder's isDebug = mParticle.config.isDevelopmentMode ", async () => { @@ -1072,7 +1030,7 @@ describe('forwarders', function() { }); // https://go.mparticle.com/work/SQDSDKS-6850 - it.skip('sends forwarding stats to v2 endpoint when featureFlag setting of batching is true', function(done) { + it.skip('sends forwarding stats to v2 endpoint when featureFlag setting of batching is true', async () => { mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder(); mockForwarder.register(window.mParticle.config); @@ -1090,8 +1048,7 @@ describe('forwarders', function() { const clock = sinon.useFakeTimers(); mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); fetchMock.resetHistory(); mockServer.requests = []; @@ -1130,12 +1087,9 @@ describe('forwarders', function() { ); event.should.have.property('ct'); event.should.have.property('eec', 0); - - done(); - }); }); - it('should not send forwarding stats to invisible forwarders', function(done) { + it('should not send forwarding stats to invisible forwarders', () => { mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder(); mockForwarder.register(window.mParticle.config); @@ -1158,8 +1112,6 @@ describe('forwarders', function() { ); expect(event).should.not.have.property('n'); - - done(); }); it('should invoke forwarder opt out', async () => { @@ -1180,7 +1132,7 @@ describe('forwarders', function() { ); }); - it('should invoke forwarder setuserattribute', function(done) { + it('should invoke forwarder setuserattribute', async () => { mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder(); @@ -1189,17 +1141,13 @@ describe('forwarders', function() { window.mParticle.config.kitConfigs.push(config1); mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); window.MockForwarder1.instance.should.have.property( 'setUserAttributeCalled', true ); - - done(); - }); }); it('should invoke forwarder setuserattribute when calling setUserAttributeList', async () => { @@ -1595,7 +1543,7 @@ describe('forwarders', function() { ); }); - it('should pass in app version to forwarder on initialize', function(done) { + it('should pass in app version to forwarder on initialize', () => { const mockForwarder = new MockForwarder(); mockForwarder.register(window.mParticle.config); const config1 = forwarderDefaultConfiguration('MockForwarder', 1); @@ -1608,11 +1556,9 @@ describe('forwarders', function() { 'appVersion', '3.0' ); - - done(); }); - it('should pass in user identities to forwarder on initialize', function(done) { + it('should pass in user identities to forwarder on initialize', () => { setLocalStorage(); const mockForwarder = new MockForwarder(); @@ -1625,11 +1571,9 @@ describe('forwarders', function() { Object.keys( window.MockForwarder1.instance.userIdentities ).length.should.equal(1); - - done(); }); - it('should pass in user attributes to forwarder on initialize', function(done) { + it('should pass in user attributes to forwarder on initialize', () => { setLocalStorage(); const mockForwarder = new MockForwarder(); @@ -1643,8 +1587,6 @@ describe('forwarders', function() { 'color', 'blue' ); - - done(); }); it('should pass filteredUser and filteredUserIdentities to onIdentifyComplete methods', async () => { @@ -2220,7 +2162,7 @@ describe('forwarders', function() { ); }); - it('should call forwarder onUserIdentified method when identity is returned', async function() { + it('should call forwarder onUserIdentified method when identity is returned', async () => { mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder(); @@ -2497,7 +2439,7 @@ describe('forwarders', function() { }); }); - it('should add integration delays to the integrationDelays object', function(done) { + it('should add integration delays to the integrationDelays object', () => { mParticle.init(apiKey, window.mParticle.config) mParticle._setIntegrationDelay(128, true); @@ -2509,8 +2451,6 @@ describe('forwarders', function() { integrationDelays.should.have.property('128', true); integrationDelays.should.have.property('24', false); integrationDelays.should.have.property('10', true); - - done(); }); it('integration test - should not log events if there are any integrations delaying, then resume logging events once delays are gone', async () => { @@ -2617,7 +2557,7 @@ describe('forwarders', function() { }); // https://go.mparticle.com/work/SQDSDKS-6844 - it.skip('integration test - should allow the user to configure the integrationDelayTimeout', function(done) { + it.skip('integration test - should allow the user to configure the integrationDelayTimeout', async () => { // testing user-configured integrationDelayTimeout let clock = sinon.useFakeTimers(); mParticle._resetForTests(MPConfig); @@ -2627,13 +2567,12 @@ describe('forwarders', function() { mParticle._setIntegrationDelay(10, true); mParticle.init(apiKey, window.mParticle.config); - waitForCondition(() => { + await waitForCondition(() => { console.log(window.mParticle.getInstance()?._Store?.identityCallInFlight) return ( window.mParticle.getInstance()?._Store?.identityCallInFlight === false ); - }, 200, 10, clock) - .then(() => { + }, 200, 10, clock); fetchMock.resetHistory(); mParticle.logEvent('Test Event3'); fetchMock.calls().length.should.equal(0); @@ -2665,9 +2604,6 @@ describe('forwarders', function() { testEvent3.should.be.ok(); testEvent4.should.be.ok(); clock.restore(); - - done(); - }) }); it('integration test - after an integration delay is set to false, should fire an event after the event timeout', async () => { @@ -2928,7 +2864,7 @@ describe('forwarders', function() { }); describe('kits with suffixes', function() { - it('should add forwarders with suffixes and initialize them accordingly if there is a coresponding kit config with the same suffix', function(done) { + it('should add forwarders with suffixes and initialize them accordingly if there is a coresponding kit config with the same suffix', () => { mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder( @@ -2957,11 +2893,9 @@ describe('forwarders', function() { .getInstance() ._getActiveForwarders() .length.should.equal(2); - - done(); }); - it('should not add a forwarder with suffix if there is not a corresponding kit config with the same suffix', function(done) { + it('should not add a forwarder with suffix if there is not a corresponding kit config with the same suffix', () => { mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder( @@ -2981,8 +2915,6 @@ describe('forwarders', function() { .getInstance() ._getActiveForwarders() .length.should.equal(0); - - done(); }); }); @@ -3263,7 +3195,7 @@ describe('forwarders', function() { ); }); - it('should filter event attributes out properly when set', async function() { + it('should filter event attributes out properly when set', async () => { mpSideloadedKit1.addEventAttributeFilter( mParticle.EventType.Navigation, 'Test Event', @@ -3310,7 +3242,7 @@ describe('forwarders', function() { ); }); - it('should filter screen names out properly when set', async function() { + it('should filter screen names out properly when set', async () => { mpSideloadedKit1.addScreenNameFilter('Test Screen Name 1'); mpSideloadedKit2.addScreenNameFilter('Test Screen Name 2'); @@ -3344,7 +3276,7 @@ describe('forwarders', function() { ); }); - it('should filter screen name attribute out properly when set', async function() { + it('should filter screen name attribute out properly when set', async () => { mpSideloadedKit1.addScreenAttributeFilter( 'Test Screen Name 1', 'testAttr1' @@ -3432,7 +3364,7 @@ describe('forwarders', function() { ); }); - it('should filter user attributes out properly when set', async function() { + it('should filter user attributes out properly when set', async () => { mpSideloadedKit1.addUserAttributeFilter('testAttr1'); mpSideloadedKit2.addUserAttributeFilter('testAttr2'); @@ -3484,7 +3416,7 @@ describe('forwarders', function() { fetchMock.restore(); }); - it('should send event to sideloaded kits', async function() { + it('should send event to sideloaded kits', async () => { const sideloadedKit1 = new MockSideloadedKit( 'SideloadedKit1', 1 @@ -3517,7 +3449,7 @@ describe('forwarders', function() { sideloadedKit2Event.should.have.property('EventName', 'foo'); }); - it('should invoke sideloaded identify call', async function() { + it('should invoke sideloaded identify call', async () => { const sideloadedKit1 = new MockSideloadedKit( 'SideloadedKit1', 1 @@ -3566,7 +3498,7 @@ describe('forwarders', function() { ); }); - it('should invoke sideloaded set/removeUserAttribute call', async function() { + it('should invoke sideloaded set/removeUserAttribute call', async () => { const sideloadedKit1 = new MockSideloadedKit( 'SideloadedKit1', 1 @@ -3617,7 +3549,7 @@ describe('forwarders', function() { ); }); - it('should invoke sideloaded logout call', async function() { + it('should invoke sideloaded logout call', async () => { const sideloadedKit1 = new MockSideloadedKit( 'SideloadedKit1', 1 @@ -3655,7 +3587,7 @@ describe('forwarders', function() { ); }); - it('should invoke sideloaded login call', async function() { + it('should invoke sideloaded login call', async () => { const sideloadedKit1 = new MockSideloadedKit( 'SideloadedKit1', 1 @@ -3694,7 +3626,7 @@ describe('forwarders', function() { ); }); - it('should invoke sideloaded modify call', async function() { + it('should invoke sideloaded modify call', async () => { const sideloadedKit1 = new MockSideloadedKit( 'SideloadedKit1', 1 @@ -3733,7 +3665,7 @@ describe('forwarders', function() { ); }); - it('should invoke sideloaded modify call', async function() { + it('should invoke sideloaded modify call', async () => { const sideloadedKit1 = new MockSideloadedKit( 'SideloadedKit1', 1