Skip to content

chore: add string check for phone in gaoc - #4311

Merged
yashasvibajpai merged 3 commits into
developfrom
fix.istrim.bugsnag.gaoc
May 15, 2025
Merged

yashasvibajpai merged 3 commits into
developfrom
fix.istrim.bugsnag.gaoc

Conversation

@yashasvibajpai

Copy link
Copy Markdown
Contributor

What are the changes introduced in this PR?

This pull request includes a minor improvement to the getAddConversionPayload function in the src/v0/destinations/google_adwords_offline_conversions/utils.js file. The change enhances the validation logic for the phone field before applying the sha256 hash.

Validation improvement:

  • Updated the condition for hashing the phone field to include a check for whether it is a string (isString(phone)), ensuring that non-string values are not processed incorrectly.

What is the related Linear task?

Resolves INT-3641

Please explain the objectives of your changes below

Put down any required details on the broader aspect of your changes. If there are any dependent changes, mandatorily mention them here

Any changes to existing capabilities/behaviour, mention the reason & what are the changes ?

N/A

Any new dependencies introduced with this change?

N/A

Any new generic utility introduced or modified. Please explain the changes.

N/A

Any technical or performance related pointers to consider with the change?

N/A

@coderabbitai review


Developer checklist

  • My code follows the style guidelines of this project

  • No breaking changes are being introduced.

  • All related docs linked with the PR?

  • All changes manually tested?

  • Any documentation changes needed with this change?

  • Is the PR limited to 10 file changes?

  • Is the PR limited to one linear task?

  • Are relevant unit and component test-cases added in new readability format?

Reviewer checklist

  • Is the type of change in the PR title appropriate as per the changes?

  • Verified that there are no credentials or confidential data exposed with the changes.

@yashasvibajpai yashasvibajpai self-assigned this May 10, 2025
@yashasvibajpai
yashasvibajpai requested a review from a team as a code owner May 10, 2025 06:27
@coderabbitai

coderabbitai Bot commented May 10, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of phone numbers to ensure only string values are hashed, preventing potential errors with non-string inputs.
  • Tests

    • Added comprehensive unit tests for the conversion payload utility, covering various user identifier and consent scenarios.
    • Updated tests to expect errors when required user identifiers are missing.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling of phone numbers to ensure only string values are hashed, preventing errors with non-string inputs.
  • Tests
    • Expanded unit tests for getAddConversionPayload covering multiple scenarios including hashing logic, fallback identifiers, and consent data handling.
    • Removed a test expecting a payload when both email and phone are missing; replaced with an error-throwing expectation.

Walkthrough

The update refines the logic in the getAddConversionPayload function within the Google AdWords Offline Conversions utility. It introduces an additional type check to ensure that the phone number is a string before applying hashing, thereby preventing non-string values from being hashed. The function is now explicitly exported. The test suite was expanded with comprehensive unit tests for this function, covering various input scenarios and expected behaviors, including error handling.

Changes

File(s) Change Summary
src/v0/destinations/google_adwords_offline_conversions/utils.js Added a type check to confirm the phone number is a string before hashing in getAddConversionPayload. Explicitly exported the function.
src/v0/destinations/google_adwords_offline_conversions/utils.test.js Added extensive unit tests for getAddConversionPayload covering hashing conditions, fallback identifiers, amount conversions, and consent data. Removed an obsolete test and added error expectation for missing identifiers.

Suggestions for Improvement

  • Consider adding unit tests specifically verifying that non-string phone values are skipped for hashing, to ensure this edge case is fully covered.
  • Review other user identifier fields in the payload for similar type safety checks to maintain consistency and avoid potential runtime errors.
  • Document the expected types for user identifiers clearly in the function's comments or typings to aid future maintainers.

Note

⚡️ AI Code Reviews for VS Code, Cursor, Windsurf

CodeRabbit now has a plugin for VS Code, Cursor and Windsurf. This brings AI code reviews directly in the code editor. Each commit is reviewed immediately, finding bugs before the PR is raised. Seamless context handoff to your AI code agent ensures that you can easily incorporate review feedback.
Learn more here.


Note

⚡️ Faster reviews with caching

CodeRabbit now supports caching for code and dependencies, helping speed up reviews. This means quicker feedback, reduced wait times, and a smoother review experience overall. Cached data is encrypted and stored securely. This feature will be automatically enabled for all accounts on May 16th. To opt out, configure Review - Disable Cache at either the organization or repository level. If you prefer to disable all data retention across your organization, simply turn off the Data Retention setting under your Organization Settings.
Enjoy the performance boost—your workflow just got faster.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge Base: Disabled due to data retention organization setting

📥 Commits

Reviewing files that changed from the base of the PR and between b1ef407 and a01f5d2.

📒 Files selected for processing (1)
  • src/v0/destinations/google_adwords_offline_conversions/utils.js (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/v0/destinations/google_adwords_offline_conversions/utils.js
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Code Coverage
  • GitHub Check: test_and_publish
  • GitHub Check: UT Tests
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented May 10, 2025 •

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.10%. Comparing base (8ae3b99) to head (a01f5d2).
Report is 28 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #4311      +/-   ##
===========================================
- Coverage    91.32%   91.10%   -0.22%     
===========================================
  Files          636      636              
  Lines        33376    33380       +4     
  Branches      7892     7890       -2     
===========================================
- Hits         30481    30412      -69     
- Misses        2680     2729      +49     
- Partials       215      239      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/v0/destinations/google_adwords_offline_conversions/utils.test.js (1)

492-509: Consider testing non-string phone handling.

While you test proper handling of string phone values, I don't see a specific test for the non-string case that this PR aims to fix. Consider adding a test with a non-string phone value to explicitly verify that the fix works as expected.

+  it('should handle non-string phone values correctly', () => {
+    const message = createValidMessage({
+      traits: { email: undefined, phone: 12345 }, // Numeric phone value
+    });
+
+    const config = {
+      validateOnly: false,
+      hashUserIdentifier: true,
+      defaultUserIdentifier: 'phone',
+    };
+
+    const result = getAddConversionPayload(message, config, {});
+
+    // Should handle non-string values appropriately
+    expect(result.operations.create.userIdentifiers[0].hashedPhoneNumber).toBeUndefined();
+    // or expect the appropriate behavior based on your implementation
+  });
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4c6bcc4 and b1ef407.

📒 Files selected for processing (2)
  • src/v0/destinations/google_adwords_offline_conversions/utils.js (2 hunks)
  • src/v0/destinations/google_adwords_offline_conversions/utils.test.js (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/v0/destinations/google_adwords_offline_conversions/utils.js
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.js`: Focus on ESLint errors (max 3) and warnings (max 5).

**/*.js: Focus on ESLint errors (max 3) and warnings (max 5).

  • src/v0/destinations/google_adwords_offline_conversions/utils.test.js
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build User Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • GitHub Check: Code Coverage
  • GitHub Check: test_and_publish
  • GitHub Check: UT Tests
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (5)
src/v0/destinations/google_adwords_offline_conversions/utils.test.js (5)

1-1: Good addition of the sha256 dependency.

Adding the sha256 import is necessary for validating the hashing functionality in your tests. This allows you to compare the expected hash values with what the function generates.


8-8: Properly importing the new exported function.

Good job explicitly importing the getAddConversionPayload function to test it. This follows the pattern established for the other utility functions.


226-237: The expectation of throwing an error is more accurate.

The test now correctly expects an error to be thrown when both email and phone are absent, which aligns with the requirement that at least one identifier is needed for user identification.

🧰 Tools
🪛 Biome (1.9.4)

[error] 228-228: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 229-229: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


[error] 230-230: Avoid the delete operator which can impact performance.

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


383-552: Well-structured and comprehensive test suite.

The test suite for getAddConversionPayload is thorough and covers key scenarios:

  • Default configuration behavior
  • Conditional hashing of identifiers
  • Fallback to alternative identifiers
  • Empty identifier handling
  • Transaction amount conversion
  • Consent data management

The helper function createValidMessage promotes code reuse and readability by centralizing the test message creation.


454-472: Test validates the PR's key improvement.

This test case specifically validates the core change in this PR - ensuring phone numbers are properly handled as strings during hashing. It confirms that when hashUserIdentifier is true and the phone is a string, it's correctly hashed using sha256.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

Co-authored-by: Sudip Paul <[email protected]>
@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@sonarqubecloud

Copy link
Copy Markdown

@yashasvibajpai
yashasvibajpai merged commit 00f44b0 into develop May 15, 2025
@yashasvibajpai
yashasvibajpai deleted the fix.istrim.bugsnag.gaoc branch May 15, 2025 10:20
ItsSudip added a commit that referenced this pull request May 27, 2025
* feat: update destination type with optional account types (#4291)

* feat: update destination type with optional account types

* chore: add authenticationType

* chore: update types with generics

* chore: add optional config to accountDefiition

* chore: update deleteAccount to regulationAccount

* chore: update regulationAccount to deleteAccount

* chore(destination): migrate slack destination tests to new format (#4279)

* chore(destination): migrate slack destination tests to new format

* refactor: tests to use proper types

* chore: fix status in mailchimp, fix cognitive complexity, add unit tests (#4314)

* chore: fix status in mailchimp, fix cognitive complexity, add unit tests

* chore: fix PR comments for mailchimp tests

* test: add tests for error cases to improve code coverage

---------

Co-authored-by: Dilip Kola <[email protected]>

* chore(braze): added docs for braze destination (#4297)

* chore(braze): added docs for braze destination

* chore: update braze docs

* chore: add multiplexing section

---------

Co-authored-by: Utsab Chowdhury <[email protected]>

* chore: add string check for phone in gaoc (#4311)

* chore: add string check for phone in gaoc

* chore: add unit test

* chore: update condition

Co-authored-by: Sudip Paul <[email protected]>

---------

Co-authored-by: Sudip Paul <[email protected]>

* chore: correct dotenv import (#4320)

* chore: payload size middleware performance improvement (#4318)

* fix: add uuid as fallback to missing anonymousId in webhook events (#4276)

* chore: bump codecov/codecov-action from 5.4.2 to 5.4.3 (#4335)

Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 5.4.2 to 5.4.3.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](codecov/codecov-action@v5.4.2...v5.4.3)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-version: 5.4.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: bump slackapi/slack-github-action from 1.27.0 to 2.1.0 (#4312)

Bumps [slackapi/slack-github-action](https://github.com/slackapi/slack-github-action) from 1.27.0 to 2.1.0.
- [Release notes](https://github.com/slackapi/slack-github-action/releases)
- [Commits](slackapi/slack-github-action@v1.27.0...v2.1.0)

---
updated-dependencies:
- dependency-name: slackapi/slack-github-action
  dependency-version: 2.1.0
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

* chore: mp add content type header to all apis (#4344)

* fix: mp add content-type header and follow strict for engage and group apis

* chore: mp add content type header to all apis

* feat: bluecore email subscription event (#4304)

* fix: blucore optin event mapping

* fix: review comments

* chore: add subscription event

* chore: add subscription event

* fix: reviews comments

* fix: review comments

* fix: review comments

* fix: review comments

* chore: test description

* chore(release): 1.101.0

* chore: pass copy of metadata to avoid actual metadata modifications (#4351)

* Revert "feat: update destination type with optional account types (#4291)" (#4348)

This reverts commit f368f00.

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: Sudip Paul <[email protected]>
Co-authored-by: Yashasvi Bajpai <[email protected]>
Co-authored-by: Dilip Kola <[email protected]>
Co-authored-by: Dilip Kola <[email protected]>
Co-authored-by: Vinay Teki <[email protected]>
Co-authored-by: Utsab Chowdhury <[email protected]>
Co-authored-by: Aris Tzoumas <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Mahesh Kutty <[email protected]>
Co-authored-by: GitHub Actions <[email protected]>
Co-authored-by: Jayachand Mopidevi <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants