diff --git a/test/src/tests-mParticleUser.js b/test/src/tests-mParticleUser.js index fc65cb242..97b4d81b9 100644 --- a/test/src/tests-mParticleUser.js +++ b/test/src/tests-mParticleUser.js @@ -34,7 +34,7 @@ describe('mParticleUser', function() { fetchMock.restore(); }); - it('should call forwarder onUserIdentified method with a filtered user identity list', function(done) { + it('should call forwarder onUserIdentified method with a filtered user identity list', async () => { mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder(); @@ -45,8 +45,8 @@ describe('mParticleUser', function() { window.mParticle.config.kitConfigs.push(config1); mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + const userIdentityRequest = { userIdentities: { google: 'test', @@ -55,13 +55,13 @@ describe('mParticleUser', function() { }, }; mParticle.Identity.login(userIdentityRequest); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.Identity.getCurrentUser()?.getMPID() === 'loginMPID' ); - }) - .then(() => { + }); + window.MockForwarder1.instance.onUserIdentifiedUser .getUserIdentities() .userIdentities.should.not.have.property('google'); @@ -71,12 +71,9 @@ describe('mParticleUser', function() { window.MockForwarder1.instance.onUserIdentifiedUser .getUserIdentities() .userIdentities.should.have.property('other', 'id2'); - done(); - }) - }) }); - it('should call forwarder onUserIdentified method with a filtered user attributes list', function(done) { + it('should call forwarder onUserIdentified method with a filtered user attributes list', async () => { mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder(); @@ -89,8 +86,8 @@ describe('mParticleUser', function() { mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + const userIdentityRequest = { userIdentities: { google: 'test', @@ -100,13 +97,13 @@ describe('mParticleUser', function() { }; mParticle.Identity.login(userIdentityRequest); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.Identity.getCurrentUser()?.getMPID() === 'loginMPID' ); - }) - .then(() => {}); + }); + mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); mParticle.Identity.getCurrentUser().setUserAttribute('color', 'blue'); mParticle.Identity.login(userIdentityRequest); @@ -116,12 +113,9 @@ describe('mParticleUser', function() { window.MockForwarder1.instance.onUserIdentifiedUser .getAllUserAttributes() .should.have.property('color', 'blue'); - - done(); - }); }); - it('should call forwarder onIdentifyComplete', function(done) { + it('should call forwarder onIdentifyComplete', async () => { mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder(); @@ -134,14 +128,12 @@ describe('mParticleUser', function() { mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + window.MockForwarder1.instance.onIdentifyCompleteCalled.should.equal(true); - done(); - }) }); - it('should call forwarder onLoginComplete', function(done) { + it('should call forwarder onLoginComplete', async () => { mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder(); @@ -154,8 +146,8 @@ describe('mParticleUser', function() { mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + const userIdentityRequest = { userIdentities: { google: 'test', @@ -165,20 +157,17 @@ describe('mParticleUser', function() { }; mParticle.Identity.login(userIdentityRequest); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.Identity.getCurrentUser()?.getMPID() === 'loginMPID' ); - }) - .then(() => { - window.MockForwarder1.instance.onLoginCompleteCalled.should.equal(true); - done(); }); - }) + + window.MockForwarder1.instance.onLoginCompleteCalled.should.equal(true); }); - it('should call forwarder onLogoutComplete', function(done) { + it('should call forwarder onLogoutComplete', async () => { mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder(); @@ -191,8 +180,8 @@ describe('mParticleUser', function() { mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + const userIdentityRequest = { userIdentities: { google: 'test', @@ -202,20 +191,17 @@ describe('mParticleUser', function() { }; mParticle.Identity.logout(userIdentityRequest); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.Identity.getCurrentUser()?.getMPID() === 'logoutMPID' ); - }) - .then(() => { - window.MockForwarder1.instance.onLogoutCompleteCalled.should.equal(true); - done(); - }); - }) + }); + + window.MockForwarder1.instance.onLogoutCompleteCalled.should.equal(true); }); - it('should call forwarder onModifyComplete method with the proper identity method passed through', function(done) { + it('should call forwarder onModifyComplete method with the proper identity method passed through', async () => { mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder(); @@ -228,8 +214,8 @@ describe('mParticleUser', function() { mParticle.init(apiKey, window.mParticle.config); - waitForCondition(hasIdentifyReturned) - .then(() => { + await waitForCondition(hasIdentifyReturned); + const userIdentityRequest = { userIdentities: { google: 'test', @@ -243,16 +229,13 @@ describe('mParticleUser', function() { }); mParticle.Identity.modify(userIdentityRequest); - waitForCondition(() => { + await waitForCondition(() => { return ( mParticle.Identity.getCurrentUser()?.getMPID() === 'modifyMPID' ); - }) - .then(() => { + }); + window.MockForwarder1.instance.onModifyCompleteCalled.should.equal(true); - done(); - }); - }) }); }); \ No newline at end of file