Skip to content

Commit

Permalink
fix: Allow any userIdentificationType to be used when initializing kit (
Browse files Browse the repository at this point in the history
  • Loading branch information
rmi22186 authored May 3, 2024
1 parent cf2ff3a commit 5cc5362
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/BrazeKit-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,9 +632,11 @@ var constructor = function () {
];
}

kitLogger('braze.changeUser', brazeUserIDType);
if (brazeUserIDType) {
kitLogger('braze.changeUser', brazeUserIDType);

braze.changeUser(brazeUserIDType);
braze.changeUser(brazeUserIDType);
}

if (userIdentities.email) {
kitLogger('braze.getUser().setEmail', userIdentities.email);
Expand Down Expand Up @@ -792,10 +794,16 @@ var constructor = function () {
braze.addSdkMetadata(['mp']);
primeBrazeWebPush();

if (forwarderSettings.userIdentificationType === 'MPID' && mParticle.Identity != null && mParticle.Identity.getCurrentUser().getMPID() != null) {
onUserIdentified(mParticle.Identity.getCurrentUser())
const currentUser =
mParticle.Identity !== null
? mParticle.Identity.getCurrentUser()
: null;
const mpid = currentUser ? currentUser.getMPID() : null;

if (currentUser && mpid) {
onUserIdentified(currentUser);
}

openSession(forwarderSettings);
}

Expand Down
20 changes: 20 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ describe('Braze Forwarder', function() {
return {
userIdentities: {
customerid: 'abc',
email: 'email@gmail.com'
},
};
},
Expand Down Expand Up @@ -970,6 +971,25 @@ describe('Braze Forwarder', function() {
delete mParticle.getVersion;
});

it('should set an identity on the user upon kit initialization when userIdentificationType is email', function() {
mParticle.forwarder.init({
apiKey: '123456',
userIdentificationType: 'Email',
});

window.braze.userId.should.equal('email@gmail.com');
window.braze.getUser().emailSet.should.equal('email@gmail.com');
});

it('should not attempt to set an identity on braze if the userIdentificationType does not exist on the customer', function() {
mParticle.forwarder.init({
apiKey: '123456',
userIdentificationType: 'other2',
});

Should(window.braze.userId).equal(null);
});

it('should set main braze user identity from userIdentificationType ', function() {
mParticle.forwarder.init({
apiKey: '123456',
Expand Down

0 comments on commit 5cc5362

Please sign in to comment.