-
Notifications
You must be signed in to change notification settings - Fork 84
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
fix: userId in braze hyrbrid #1833
Conversation
WalkthroughWalkthroughThe changes involve modifications to the Changes
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/analytics-js-integrations/src/integrations/Braze/browser.js (1 hunks)
Additional comments not posted (1)
packages/analytics-js-integrations/src/integrations/Braze/browser.js (1)
113-117
: LGTM! But verify the impact of changes on the codebase.The addition of the conditional check for
isHybridModeEnabled
and early return is a logical improvement. The removal of redundant variable declarations enhances code clarity.However, ensure that this change does not affect other parts of the codebase that rely on the
identify
method's behavior.Run the following script to verify the usage of the
identify
method:
size-limit report 📦
|
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/analytics-js-integrations/tests/integrations/Braze/browser.test.js (2 hunks)
Additional comments not posted (1)
packages/analytics-js-integrations/__tests__/integrations/Braze/browser.test.js (1)
Line range hint
1086-1121
: Verify the correctness of thechangeUser
method call expectation.The test case now expects the
changeUser
method to be called once during the identify call in hybrid mode. Ensure that this change aligns with the intended functionality and does not introduce regressions.Run the following script to verify the implementation of the
identify
method in the Braze class:Verification successful
Verification Successful:
changeUser
Method Call in Hybrid ModeThe
identify
method in theBraze
class correctly callswindow.braze.changeUser(userId)
whenisHybridModeEnabled
is true, matching the test case expectation of a single call during the identify process in hybrid mode. This confirms that the test case is aligned with the intended functionality.
- The
identify
method implementation correctly handles thechangeUser
call in hybrid mode.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the implementation of the `identify` method in the Braze class. # Test: Search for the `identify` method implementation. Expect: Correct handling of `changeUser` call. ast-grep --lang javascript --pattern $'class Braze { $$$ identify($_) { $$$ } $$$ }'Length of output: 31882
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #1833 +/- ##
========================================
Coverage 57.11% 57.11%
========================================
Files 476 476
Lines 16228 16229 +1
Branches 3250 3245 -5
========================================
+ Hits 9269 9270 +1
- Misses 5715 5731 +16
+ Partials 1244 1228 -16 ☔ View full report in Codecov by Sentry. |
2037e66
to
65b177f
Compare
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- packages/analytics-js-integrations/tests/integrations/Braze/browser.test.js (2 hunks)
Additional comments not posted (1)
packages/analytics-js-integrations/__tests__/integrations/Braze/browser.test.js (1)
Line range hint
1086-1121
: LGTM!The test case correctly verifies that
changeUser
is called exactly once during an identify call in hybrid mode.The code changes are approved.
95868ca
to
df1968d
Compare
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.
Actionable comments posted: 1
Outside diff range and nitpick comments (1)
packages/analytics-js-integrations/__tests__/integrations/Braze/browser.test.js (1)
Line range hint
1086-1121
: Test case uses incorrect message type foridentify
method.In the test for the
identify
method in hybrid mode, therudderElement
message includestype: 'page'
and properties for a page event, which are not appropriate for testing theidentify
method. This may lead to misleading test results. Please update therudderElement
to reflect anidentify
call.Apply this diff to correct the test data:
// Create a mock rudderElement with necessary properties const rudderElement = { message: { userId: 'user123', - type: 'page', - name: 'Home', - properties: { - title: 'Home | RudderStack', - url: 'http://www.rudderstack.com', - }, + type: 'identify', + context: { + traits: { + email: '[email protected]', + firstName: 'John', + lastName: 'Doe', + }, + }, }, };
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (2)
- packages/analytics-js-integrations/tests/integrations/Braze/browser.test.js (2 hunks)
- packages/analytics-js-integrations/src/integrations/Braze/browser.js (1 hunks)
const { message } = rudderElement; | ||
const { userId } = message; | ||
|
||
if (this.isHybridModeEnabled) { | ||
window.braze.changeUser(userId); |
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.
Ensure userId
is defined before calling window.braze.changeUser
.
In hybrid mode, the code calls window.braze.changeUser(userId)
without checking if userId
is defined. If userId
is undefined
or empty, this could cause an error or unexpected behavior. Consider adding a check to ensure userId
is a non-empty string before calling changeUser
.
Apply this diff to add the check:
const { message } = rudderElement;
const { userId } = message;
if (this.isHybridModeEnabled) {
+ if (userId) {
window.braze.changeUser(userId);
+ } else {
+ logger.error('User ID is undefined or empty in hybrid mode');
+ }
return;
}
Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
const { message } = rudderElement; | |
const { userId } = message; | |
if (this.isHybridModeEnabled) { | |
window.braze.changeUser(userId); | |
const { message } = rudderElement; | |
const { userId } = message; | |
if (this.isHybridModeEnabled) { | |
if (userId) { | |
window.braze.changeUser(userId); | |
} else { | |
logger.error('User ID is undefined or empty in hybrid mode'); | |
} | |
return; | |
} |
Quality Gate passedIssues Measures |
PR Description
Please include a summary of the change along with the relevant motivation and context.
Linear task (optional)
Linear task link
Cross Browser Tests
Please confirm you have tested for the following browsers:
Sanity Suite
Security
Summary by CodeRabbit
changeUser
method is called during identification.