Skip to content
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: adroll bugsnag issue #1929

Merged
merged 3 commits into from
Nov 19, 2024
Merged

fix: adroll bugsnag issue #1929

merged 3 commits into from
Nov 19, 2024

Conversation

shrouti1507
Copy link
Contributor

@shrouti1507 shrouti1507 commented Nov 18, 2024

PR Description

Please include a summary of the change along with the relevant motivation and context.

Linear task (optional)

Screenshot 2024-11-18 at 10 02 22 PM

https://linear.app/rudderstack/issue/INT-2873/bugsnag-alerts

Cross Browser Tests

Please confirm you have tested for the following browsers:

  • Chrome
  • Firefox
  • IE11

Sanity Suite

  • All sanity suite test cases pass locally

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Summary by CodeRabbit

  • New Features

    • Introduced comprehensive unit tests for the Adroll integration, covering initialization, loading states, user identification, event tracking, and page tracking.
  • Bug Fixes

    • Improved the track method to ensure event variables are processed correctly by converting them to strings before applying transformations.
  • Tests

    • Added various tests to validate the functionality of the Adroll integration, ensuring robust performance and reliability.

Copy link
Contributor

coderabbitai bot commented Nov 18, 2024

📝 Walkthrough
📝 Walkthrough

Walkthrough

This pull request introduces a comprehensive suite of unit tests for the Adroll integration within the analytics-js-integrations package. The tests cover various functionalities of the Adroll class, including initialization, loading states, user identification, event tracking, and page tracking. Additionally, the track method has been modified to ensure the event variable is explicitly converted to a string before applying transformations, enhancing its robustness. Overall, the changes enhance the testing coverage and reliability of the Adroll integration.

Changes

File Path Change Summary
packages/analytics-js-integrations/__tests__/integrations/Adroll/browser.test.js Added unit tests for the Adroll integration, covering initialization, loading states, identification, event tracking, and page tracking.
packages/analytics-js-integrations/src/integrations/Adroll/browser.js Modified the track method to replace event.toLowerCase() with event.toString().toLowerCase() for better string handling.

Possibly related PRs

Suggested reviewers

  • Gauravudia
  • sanpj2292

Warning

Rate limit exceeded

@shrouti1507 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 1 minutes and 14 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between ed70d75 and a1c91ab.


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?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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.

Copy link

codecov bot commented Nov 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 57.83%. Comparing base (9ebbab9) to head (a1c91ab).
Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1929      +/-   ##
===========================================
+ Coverage    57.54%   57.83%   +0.29%     
===========================================
  Files          485      485              
  Lines        16506    16506              
  Branches      3303     3315      +12     
===========================================
+ Hits          9498     9547      +49     
+ Misses        5743     5695      -48     
+ Partials      1265     1264       -1     

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


🚨 Try these New Features:

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🧹 Outside diff range and nitpick comments (3)
packages/analytics-js-integrations/__tests__/integrations/Adroll/browser.test.js (3)

20-29: Enhance initialization test coverage

The initialization tests only cover the happy path. Consider adding tests for:

  • Error cases with missing or invalid advId/pixId
  • Verification of script injection
  • Multiple initialization attempts

Example test cases to add:

test('should throw error when advId is missing', () => {
  expect(() => new Adroll({ pixId: 'TEST_PIX_ID' })).toThrow();
});

test('should inject adroll script', () => {
  adroll.init();
  const script = document.querySelector('script[src*="adroll"]');
  expect(script).toBeTruthy();
});

54-96: Add validation tests for identify method

While the current tests cover the basic functionality, consider adding:

  • Email format validation tests
  • User ID tracking tests
  • Tests for handling special characters in email

Example test cases to add:

test('should handle invalid email format', () => {
  adroll.identify({
    message: {
      traits: { email: 'invalid-email' }
    }
  });
  expect(window.__adroll.record_adroll_email).not.toHaveBeenCalled();
});

test('should track user ID if available', () => {
  adroll.identify({
    message: {
      userId: 'user123',
      traits: { email: '[email protected]' }
    }
  });
  expect(window._adroll_user_id).toBe('user123');
});

166-211: Enhance page tracking test coverage

The current tests only cover basic page view tracking. Consider adding tests for:

  • Different URL formats and components
  • Page properties (title, referrer, search)
  • Error cases in URL handling

Example test cases to add:

test('should handle complex URLs with query parameters', () => {
  Object.defineProperty(window, 'location', {
    value: {
      pathname: '/products',
      href: 'https://test.com/products?id=123',
      search: '?id=123'
    },
    writable: true
  });
  
  adroll.page({
    message: {
      name: 'Products',
      properties: {
        title: 'Product List',
        referrer: 'https://test.com'
      }
    }
  });
  
  expect(window.__adroll.record_user).toHaveBeenCalledWith(
    expect.objectContaining({
      path: '/products',
      search: '?id=123',
      title: 'Product List',
      referrer: 'https://test.com'
    })
  );
});
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 9ebbab9 and ed70d75.

📒 Files selected for processing (2)
  • packages/analytics-js-integrations/__tests__/integrations/Adroll/browser.test.js (1 hunks)
  • packages/analytics-js-integrations/src/integrations/Adroll/browser.js (1 hunks)
🧰 Additional context used
🪛 Biome
packages/analytics-js-integrations/src/integrations/Adroll/browser.js

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

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

🪛 GitHub Check: codecov/patch
packages/analytics-js-integrations/src/integrations/Adroll/browser.js

[warning] 77-77: packages/analytics-js-integrations/src/integrations/Adroll/browser.js#L77
Added line #L77 was not covered by tests

🔇 Additional comments (4)
packages/analytics-js-integrations/src/integrations/Adroll/browser.js (3)

75-75: LGTM: Delete operator usage is appropriate here

While static analysis flags the delete operator for performance reasons, its usage here is justified as:

  1. It's in a conditional block (not frequently called)
  2. It's modifying a temporary object
  3. Using undefined assignment would leave an enumerable property, which might affect AdRoll's processing
🧰 Tools
🪛 Biome

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

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


64-64: LGTM: Robust fix for Bugsnag alerts

The addition of .toString() before .toLowerCase() calls is a solid fix that will prevent Bugsnag alerts by ensuring type safety when handling events. The implementation is consistent across all event checks and maintains the existing functionality while making it more robust.

Also applies to: 68-68, 70-70, 77-77


77-79: Verify test coverage for custom event mapping

This code path handles custom event mapping to AdRoll segments, but line 77 is reported as not covered by tests. Please ensure there are test cases that:

  1. Map a custom event to a segmentId
  2. Verify the correct assignment of adroll_segments
✅ Verification successful

Let me gather more context about the test coverage by checking the actual test implementations.


Test coverage for custom event mapping is properly implemented

The test file includes comprehensive coverage for custom event mapping:

  • The Track tests suite includes setup of custom event mapping: { from: 'custom event', to: 'ghi789' }
  • Tests verify correct adroll_segments assignment for different event types:
    • Product events (abc123)
    • Order events (def456)
    • Page events (page123)
  • The implementation includes test cases for both mapped and unmapped events
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check test coverage for custom event mapping

# Look for test cases in the test file
rg -A 5 "custom.*event" "packages/analytics-js-integrations/__tests__/integrations/Adroll/browser.test.js"

# Check if there are tests verifying segmentId assignment
rg -A 5 "adroll_segments" "packages/analytics-js-integrations/__tests__/integrations/Adroll/browser.test.js"

Length of output: 634


Script:

#!/bin/bash
# Check the full test file content to understand the test coverage
cat "packages/analytics-js-integrations/__tests__/integrations/Adroll/browser.test.js"

Length of output: 5397

🧰 Tools
🪛 GitHub Check: codecov/patch

[warning] 77-77: packages/analytics-js-integrations/src/integrations/Adroll/browser.js#L77
Added line #L77 was not covered by tests

packages/analytics-js-integrations/__tests__/integrations/Adroll/browser.test.js (1)

31-52: LGTM! Comprehensive loading state tests

The tests thoroughly cover both positive and negative cases for loading states, including the relationship between isLoaded and isReady.

Copy link

github-actions bot commented Nov 18, 2024

size-limit report 📦

Name Size (Base) Size (Current) Size Limit Status
Plugins Module Federation Mapping - Legacy - CDN 332 B 332 B (0%) 512 B
Plugins - Legacy - CDN 15.71 KB 15.71 KB (0%) 16 KB
Plugins Module Federation Mapping - Modern - CDN 331 B 331 B (0%) 512 B
Plugins - Modern - CDN 7.2 KB 7.2 KB (0%) 7.5 KB
Common - No bundling 16.27 KB 16.27 KB (0%) 16.5 KB
Cookies Utils - Legacy - NPM (ESM) 1.54 KB 1.54 KB (0%) 2 KB
Cookies Utils - Legacy - NPM (CJS) 1.75 KB 1.75 KB (0%) 2 KB
Cookies Utils - Legacy - NPM (UMD) 1.53 KB 1.53 KB (0%) 2 KB
Cookies Utils - Modern - NPM (ESM) 1.17 KB 1.17 KB (0%) 1.5 KB
Cookies Utils - Modern - NPM (CJS) 1.4 KB 1.4 KB (0%) 1.5 KB
Cookies Utils - Modern - NPM (UMD) 1.16 KB 1.16 KB (0%) 1.5 KB
Load Snippet 778 B 778 B (0%) 1 KB
Core (v1.1) - NPM (ESM) 30.32 KB 30.32 KB (0%) 32 KB
Core (v1.1) - NPM (CJS) 30.52 KB 30.52 KB (0%) 32 KB
Core (v1.1) - NPM (UMD) 30.34 KB 30.34 KB (0%) 32 KB
Core (Content Script - v1.1) - NPM (ESM) 29.89 KB 29.89 KB (0%) 30.5 KB
Core (Content Script - v1.1) - NPM (CJS) 30.04 KB 30.04 KB (0%) 30.5 KB
Core (Content Script - v1.1) - NPM (UMD) 29.98 KB 29.98 KB (0%) 30 KB
Core - Legacy - CDN 48.51 KB 48.51 KB (0%) 49 KB
Core - Modern - CDN 24.75 KB 24.75 KB (0%) 25 KB
Core - Legacy - NPM (ESM) 48.33 KB 48.33 KB (0%) 48.5 KB
Core - Legacy - NPM (CJS) 48.6 KB 48.6 KB (0%) 49 KB
Core - Legacy - NPM (UMD) 48.36 KB 48.36 KB (0%) 48.5 KB
Core - Modern - NPM (ESM) 24.5 KB 24.5 KB (0%) 25 KB
Core - Modern - NPM (CJS) 24.74 KB 24.74 KB (0%) 25 KB
Core - Modern - NPM (UMD) 24.53 KB 24.53 KB (0%) 25 KB
Core (Bundled) - Legacy - NPM (ESM) 48.33 KB 48.33 KB (0%) 48.5 KB
Core (Bundled) - Legacy - NPM (CJS) 48.58 KB 48.58 KB (0%) 49 KB
Core (Bundled) - Legacy - NPM (UMD) 48.36 KB 48.36 KB (0%) 48.5 KB
Core (Bundled) - Modern - NPM (ESM) 39.48 KB 39.48 KB (0%) 40 KB
Core (Bundled) - Modern - NPM (CJS) 39.75 KB 39.75 KB (0%) 40 KB
Core (Bundled) - Modern - NPM (UMD) 39.49 KB 39.49 KB (0%) 40 KB
Core (Content Script) - Legacy - NPM (ESM) 47.83 KB 47.83 KB (0%) 48 KB
Core (Content Script) - Legacy - NPM (CJS) 48.06 KB 48.06 KB (0%) 48.5 KB
Core (Content Script) - Legacy - NPM (UMD) 47.8 KB 47.8 KB (0%) 48 KB
Core (Content Script) - Modern - NPM (ESM) 38.96 KB 38.96 KB (0%) 39.5 KB
Core (Content Script) - Modern - NPM (CJS) 39.2 KB 39.2 KB (0%) 40 KB
Core (Content Script) - Modern - NPM (UMD) 38.93 KB 38.93 KB (0%) 39 KB
Service Worker - Legacy - NPM (ESM) 30.56 KB 30.56 KB (0%) 31 KB
Service Worker - Legacy - NPM (CJS) 30.83 KB 30.83 KB (0%) 31 KB
Service Worker - Legacy - NPM (UMD) 30.65 KB 30.65 KB (0%) 31 KB
Service Worker - Modern - NPM (ESM) 25.74 KB 25.74 KB (0%) 26 KB
Service Worker - Modern - NPM (CJS) 26 KB 26 KB (0%) 26.5 KB
Service Worker - Modern - NPM (UMD) 25.75 KB 25.75 KB (0%) 26 KB
All Integrations - Legacy - CDN 94.73 KB 94.7 KB (-0.03% ▼) 95.3 KB
All Integrations - Modern - CDN 90.01 KB 90.03 KB (+0.03% ▲) 91 KB

shrouti1507 and others added 2 commits November 18, 2024 22:26
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Copy link

sonarcloud bot commented Nov 18, 2024

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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/Adroll/browser.test.js (1)

208-215: Restore window.location after modifying it in tests

In the beforeEach hook of the "Page tests" suite, window.location is being overridden. To prevent potential side effects on other tests, it's advisable to store the original window.location and restore it in the afterEach hook.

Consider applying this change:

+ let originalLocation;

 beforeEach(() => {
+  originalLocation = window.location;
   Object.defineProperty(window, 'location', {
     value: {
       pathname: '/',
       href: 'https://www.test-host.com/',
     },
     writable: true,
   });
 });

+ afterEach(() => {
+   window.location = originalLocation;
+ });
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ed70d75 and a1c91ab.

📒 Files selected for processing (1)
  • packages/analytics-js-integrations/__tests__/integrations/Adroll/browser.test.js (1 hunks)
🧰 Additional context used
🪛 Biome
packages/analytics-js-integrations/__tests__/integrations/Adroll/browser.test.js

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

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)


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

Unsafe fix: Use an undefined assignment instead.

(lint/performance/noDelete)

@shrouti1507 shrouti1507 merged commit 18589f2 into develop Nov 19, 2024
13 checks passed
@shrouti1507 shrouti1507 deleted the fix.adroll branch November 19, 2024 06:04
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.

3 participants