Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 34 additions & 51 deletions test/src/tests-mParticleUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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',
Expand All @@ -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');
Expand All @@ -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();

Expand All @@ -89,8 +86,8 @@ describe('mParticleUser', function() {

mParticle.init(apiKey, window.mParticle.config);

waitForCondition(hasIdentifyReturned)
.then(() => {
await waitForCondition(hasIdentifyReturned);

const userIdentityRequest = {
userIdentities: {
google: 'test',
Expand All @@ -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);
Expand All @@ -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();

Expand All @@ -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();

Expand All @@ -154,8 +146,8 @@ describe('mParticleUser', function() {

mParticle.init(apiKey, window.mParticle.config);

waitForCondition(hasIdentifyReturned)
.then(() => {
await waitForCondition(hasIdentifyReturned);

const userIdentityRequest = {
userIdentities: {
google: 'test',
Expand All @@ -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();

Expand All @@ -191,8 +180,8 @@ describe('mParticleUser', function() {

mParticle.init(apiKey, window.mParticle.config);

waitForCondition(hasIdentifyReturned)
.then(() => {
await waitForCondition(hasIdentifyReturned);

const userIdentityRequest = {
userIdentities: {
google: 'test',
Expand All @@ -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();

Expand All @@ -228,8 +214,8 @@ describe('mParticleUser', function() {

mParticle.init(apiKey, window.mParticle.config);

waitForCondition(hasIdentifyReturned)
.then(() => {
await waitForCondition(hasIdentifyReturned);

const userIdentityRequest = {
userIdentities: {
google: 'test',
Expand All @@ -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();
});
})
});
});
Loading