-
Notifications
You must be signed in to change notification settings - Fork 7
feat: Add support to forward subscriptionGroupIds #57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
rmi22186
merged 3 commits into
mparticle-integrations:master-v5
from
mmustafa-tse:feat/subscriptionGroups
Jun 25, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,7 @@ describe('Braze Forwarder', function() { | |
| this.monthOfBirth = null; | ||
| this.dayOfBirth = null; | ||
| this.customAttributes = {}; | ||
| this.subscriptionGroup = {}; | ||
|
|
||
| this.customAttributeSet = false; | ||
|
|
||
|
|
@@ -137,6 +138,14 @@ describe('Braze Forwarder', function() { | |
| self.customAttributeSet = true; | ||
| self.customAttributes[key] = value; | ||
| }; | ||
|
|
||
| this.addToSubscriptionGroup = function(key) { | ||
| self.subscriptionGroup[key] = true; | ||
| } | ||
|
|
||
| this.removeFromSubscriptionGroup = function(key) { | ||
| self.subscriptionGroup[key] = false; | ||
| } | ||
| }, | ||
| MockBraze = function() { | ||
| var self = this; | ||
|
|
@@ -175,6 +184,7 @@ describe('Braze Forwarder', function() { | |
| self.apiKey = apiKey; | ||
| self.baseUrl = options.baseUrl || null; | ||
| self.doNotLoadFontAwesome = options.doNotLoadFontAwesome; | ||
| self.parsedSubscriptionGroupMapping = {}; | ||
| return true; | ||
| }; | ||
|
|
||
|
|
@@ -1107,6 +1117,95 @@ describe('Braze Forwarder', function() { | |
| (window.braze.getUser().yearOfBirth === null).should.equal(true); | ||
| }); | ||
|
|
||
| it('decodeSubscriptionGroupMappings should return parsed subscriptionGroupIds map when proper setting is given', function () { | ||
| // sample subscriptionGroupMapping from config | ||
| var subscriptionGroupMapping = '[{"jsmap":null,"map":"subscriptionGroupTest1","maptype":"UserAttributeClass.Name","value":"00000000-0000-0000-0000-000000000000"},{"jsmap":null,"map":"subscriptionGroupTest2","maptype":"UserAttributeClass.Name","value":"00000000-0000-0000-0000-000000000001"}]'; | ||
|
|
||
| // get the decoded mapped subscriptionGroup | ||
| var parsedSubscriptionGroupMapping = mParticle.forwarder.decodeSubscriptionGroupMappings(subscriptionGroupMapping); | ||
| var expectedResult = { | ||
| 'subscriptionGroupTest1': '00000000-0000-0000-0000-000000000000', | ||
| 'subscriptionGroupTest2': '00000000-0000-0000-0000-000000000001', | ||
| }; | ||
|
|
||
| parsedSubscriptionGroupMapping.should.deepEqual(expectedResult); | ||
| }); | ||
|
|
||
| it('should set subscription group for mapped attributes when value is true with type boolean', function() { | ||
| // sample subscriptionGroupMapping from config | ||
| var subscriptionGroupMapping = '[{"jsmap":null,"map":"subscriptionGroupTest1","maptype":"UserAttributeClass.Name","value":"00000000-0000-0000-0000-000000000000"},{"jsmap":null,"map":"subscriptionGroupTest2","maptype":"UserAttributeClass.Name","value":"00000000-0000-0000-0000-000000000001"}]'; | ||
|
|
||
| // initialize Braze kit with subscriptionGroupMappings | ||
| mParticle.forwarder.init( | ||
| { | ||
| apiKey: '123456', | ||
| subscriptionGroupMapping: subscriptionGroupMapping, | ||
| }, | ||
| reportService.cb, | ||
| true, | ||
| null | ||
| ); | ||
|
|
||
| // get the decoded mapped subscriptionGroup | ||
| var parsedSubscriptionGroupMapping = mParticle.forwarder.decodeSubscriptionGroupMappings(subscriptionGroupMapping); | ||
|
|
||
| // set attribute subscriptionGroupTest1 with boolean value true should call Braze's addToSubscriptionGroup since it's mapped | ||
| mParticle.forwarder.setUserAttribute('subscriptionGroupTest1', true); | ||
| var mappedSubscriptionGroupId = parsedSubscriptionGroupMapping['subscriptionGroupTest1']; | ||
| window.braze.getUser().subscriptionGroup[mappedSubscriptionGroupId].should.equal(true); | ||
| }); | ||
|
|
||
| it('should set subscription group for mapped attributes when value is false with type boolean', function() { | ||
| // sample subscriptionGroupMapping from config | ||
| var subscriptionGroupMapping = '[{"jsmap":null,"map":"subscriptionGroupTest1","maptype":"UserAttributeClass.Name","value":"00000000-0000-0000-0000-000000000000"},{"jsmap":null,"map":"subscriptionGroupTest2","maptype":"UserAttributeClass.Name","value":"00000000-0000-0000-0000-000000000001"}]'; | ||
|
|
||
| // initialize Braze kit with subscriptionGroupMappings | ||
| mParticle.forwarder.init( | ||
| { | ||
| apiKey: '123456', | ||
| subscriptionGroupMapping: subscriptionGroupMapping, | ||
| }, | ||
| reportService.cb, | ||
| true, | ||
| null | ||
| ); | ||
|
|
||
| // get the decoded mapped subscriptionGroup | ||
| var parsedSubscriptionGroupMapping = mParticle.forwarder.decodeSubscriptionGroupMappings(subscriptionGroupMapping); | ||
|
|
||
| // set attribute subscriptionGroupTest2 with boolean value false should call Braze's removeFromSubscriptionGroup since it's mapped | ||
| mParticle.forwarder.setUserAttribute('subscriptionGroupTest2', false); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should be a separate test. You should have one test for the "positive" case, a separate one for the "negative" case, and then additional tests for specific edge cases. |
||
| var mappedSubscriptionGroupId = parsedSubscriptionGroupMapping['subscriptionGroupTest2']; | ||
| window.braze.getUser().subscriptionGroup[mappedSubscriptionGroupId].should.equal(false); | ||
| }); | ||
|
|
||
| it('should not set subscription group for mapped attributes when value type is not boolean', function() { | ||
| // sample subscriptionGroupMapping from config | ||
| var subscriptionGroupMapping = '[{"jsmap":null,"map":"subscriptionGroupTest1","maptype":"UserAttributeClass.Name","value":"00000000-0000-0000-0000-000000000000"},{"jsmap":null,"map":"subscriptionGroupTest2","maptype":"UserAttributeClass.Name","value":"00000000-0000-0000-0000-000000000001"}]'; | ||
|
|
||
| // initialize Braze kit with subscriptionGroupMappings | ||
| mParticle.forwarder.init( | ||
| { | ||
| apiKey: '123456', | ||
| subscriptionGroupMapping: subscriptionGroupMapping, | ||
| }, | ||
| reportService.cb, | ||
| true, | ||
| null | ||
| ); | ||
|
|
||
| // should log error if mapped attribute value is not type boolean | ||
| mParticle.forwarder.logger = { | ||
| verbose: function(msg) { | ||
| mParticle.forwarder.msg = msg; | ||
| }, | ||
| }; | ||
|
|
||
| mParticle.forwarder.setUserAttribute('subscriptionGroupTest1', 'testStringValue'); | ||
| var expectedMessage = `mParticle - Braze Web Kit log:\nCan\'t call setSubscriptionGroups on forwarder Appboy, setSubscriptionGroups must set this value to a boolean:\n`; | ||
| mParticle.forwarder.msg.should.equal(expectedMessage) | ||
| }); | ||
|
|
||
| it('should not set default values if a string is not passed as the attribute', function() { | ||
| mParticle.forwarder.setUserAttribute('first_name', 'John'); | ||
| mParticle.forwarder.setUserAttribute('last_name', 'Doe'); | ||
|
|
@@ -1119,7 +1218,7 @@ describe('Braze Forwarder', function() { | |
| it('should set a custom user attribute', function() { | ||
| mParticle.forwarder.setUserAttribute('test', 'result'); | ||
| window.braze.getUser().should.have.property('customAttributeSet', true); | ||
| window.braze.getUser().customAttributes['test'].should.equal('result');; | ||
| window.braze.getUser().customAttributes['test'].should.equal('result'); | ||
| }); | ||
|
|
||
| it('should set a custom user attribute of diffferent types', function() { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mmustafa-tse I realize, we should actually put a try/catch block here just to be extra safe.