Skip to content

feat(moengage): add endpoint paths to transformer responses - #4661

Merged
koladilip merged 1 commit into
developfrom
chore.add-endpoint-paths-moengage
Sep 22, 2025
Merged

koladilip merged 1 commit into
developfrom
chore.add-endpoint-paths-moengage

Conversation

@koladilip

Copy link
Copy Markdown
Contributor

Summary

This PR adds endpoint path details to MoEngage transformer responses for better observability and debugging.

Changes

  • Refactored endpoint configuration to use endpointPaths object for better maintainability
  • Added endpoint path details to transformer responses
  • Updated tests to include endpoint path assertions
  • Maintained backward compatibility with existing endpoint structure

Files Modified

  • src/v0/destinations/moengage/config.js - Refactored endpoint configuration
  • src/v0/destinations/moengage/transform.js - Added endpoint path to responses
  • src/v0/destinations/moengage/transform.test.js - Updated tests
  • test/integrations/destinations/moengage/processor/data.ts - Added test data
  • test/integrations/destinations/moengage/router/data.ts - Added test data

Testing

  • All existing tests pass
  • New tests added for endpoint path functionality
  • Integration tests updated with new endpoint path assertions

- Refactor endpoint configuration to use endpointPaths object
- Add endpoint path details to transformer responses for better observability
- Update tests to include endpoint path assertions
- Maintain backward compatibility with existing endpoint structure
@koladilip
koladilip requested a review from a team as a code owner September 22, 2025 08:20
@coderabbitai

coderabbitai Bot commented Sep 22, 2025 •

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Refactor

    • Unified MoEngage endpoint configuration across regions for more consistent behavior.
    • Standardized endpoint handling for identify, track, device, and alias flows.
    • Improved validation with clearer errors for invalid region settings.
  • Tests

    • Expanded and parameterized tests to cover all regions and endpoint types.
    • Consolidated error handling tests for robustness.

Walkthrough

Refactors MoEngage endpoint configuration to centralize path segments and region URLs, replacing per-region constants with consolidated maps. Updates transform logic to return and propagate structured endpoint details { endpoint, path }. Adjusts tests to use parameterized cases for regions and categories, and expands invalid-region error checks.

Changes

Cohort / File(s) Summary of changes
Config consolidation
src/v0/destinations/moengage/config.js
Introduced endpointPaths and endpoints maps; removed endpointUS/endpointEU/endpointIND exports; now export endpointPaths and endpoints composing full URLs per region and path.
Transform logic update
src/v0/destinations/moengage/transform.js
Switched imports to endpoints/endpointPaths; getCommonDestinationEndpoint now returns { endpoint, path }; response now includes endpoint and endpointPath; added invalid-region ConfigurationError handling aligned with new structure.
Tests parameterization
src/v0/destinations/moengage/transform.test.js
Replaced hard-coded endpoint tests with parameterized cases across regions and categories; consolidated invalid-region tests; updated imports to endpoints/endpointPaths.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client as Caller
  participant Transform as transform.js
  participant Config as config.js

  Client->>Transform: getCommonDestinationEndpoint(region, category)
  Transform->>Config: lookup endpoints[region], endpointPaths[category]
  alt Region valid
    Config-->>Transform: { endpoint, path }
    Transform-->>Client: { endpoint, path }
    Client->>Transform: build response(payload, {endpoint, path})
    Transform-->>Client: response { endpoint, endpointPath=path, ... }
  else Region invalid
    Transform-->>Client: throw ConfigurationError("Invalid region")
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • sivashanmukh
  • vinayteki95
  • chandumlg

Suggestions

  • Add a type/interface for the { endpoint, path } return to enforce usage across callers.
  • Validate category against endpointPaths with explicit errors to prevent silent undefined paths.
  • Update any downstream consumers expecting string endpoints to ensure compatibility with the new response shape.

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The PR description clearly summarizes the changes, lists modified files, and notes testing, but it does not conform to the repository's required template: the mandatory "What is the related Linear task?" line (e.g., "Resolves INT-XXX") is missing and the "Please explain the objectives..." section does not explicitly state dependencies or broader impact as required; additionally the developer checklist is left unchecked and several template subsections (new dependencies, behavior changes) are not addressed. Because the repository template specifies those fields as required, the description is incomplete and cannot be marked as passing. Update the PR description to exactly follow the repo template: add the "What is the related Linear task?" line with the Linear ID (Resolves INT-XXX), expand the objectives to list any dependent changes and confirm backward-compatibility or breaking changes, populate or explain each developer checklist item, and clarify any "N/A" entries; once those required fields are completed the description should pass the check.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (1 passed)
Check name Status Explanation
Title Check ✅ Passed The title succinctly and accurately summarizes the primary change: adding endpoint paths to MoEngage transformer responses. It uses an appropriate conventional-commit prefix "feat(moengage):", is concise, and clearly communicates the main intent for reviewers scanning history. It avoids extraneous details or vague wording.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch chore.add-endpoint-paths-moengage

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@devops-github-rudderstack

Copy link
Copy Markdown
Contributor

Allure Test reports for this run are available at:

@codecov

codecov Bot commented Sep 22, 2025 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 91.78%. Comparing base (bde0785) to head (27453d7).
⚠️ Report is 8 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #4661   +/-   ##
========================================
  Coverage    91.78%   91.78%           
========================================
  Files          642      642           
  Lines        33974    33974           
  Branches      8037     8034    -3     
========================================
  Hits         31184    31184           
  Misses        2560     2560           
  Partials       230      230           

☔ 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 (3)
src/v0/destinations/moengage/transform.test.js (1)

117-141: Prefer asserting error class/message directly for resilience.

Constructing an error instance in test data is a bit brittle. Assert by class or message to reduce coupling.

Apply this diff:

-  test.each([
-    {
-      description: 'should throw ConfigurationError for invalid region',
-      input: { apiId: 'testApiId', region: 'INVALID', category: { type: 'identify' } },
-      expectedError: new ConfigurationError('The region is not valid'),
-    },
-    {
-      description: 'should throw ConfigurationError for null region',
-      input: { apiId: 'testApiId', region: null, category: { type: 'identify' } },
-      expectedError: new ConfigurationError('The region is not valid'),
-    },
-    {
-      description: 'should throw ConfigurationError for undefined region',
-      input: { apiId: 'testApiId', region: undefined, category: { type: 'identify' } },
-      expectedError: new ConfigurationError('The region is not valid'),
-    },
-    {
-      description: 'should throw ConfigurationError for empty string region',
-      input: { apiId: 'testApiId', region: '', category: { type: 'identify' } },
-      expectedError: new ConfigurationError('The region is not valid'),
-    },
-  ])('$description', ({ input, expectedError }) => {
-    expect(() => {
-      getCommonDestinationEndpoint(input);
-    }).toThrow(expectedError);
-  });
+  test.each([
+    { description: 'invalid region', input: { apiId: 'testApiId', region: 'INVALID', category: { type: 'identify' } } },
+    { description: 'null region',    input: { apiId: 'testApiId', region: null,       category: { type: 'identify' } } },
+    { description: 'undefined region', input:{ apiId: 'testApiId', region: undefined,  category: { type: 'identify' } } },
+    { description: 'empty region',   input: { apiId: 'testApiId', region: '',         category: { type: 'identify' } } },
+  ])('should throw ConfigurationError for $description', ({ input }) => {
+    expect(() => getCommonDestinationEndpoint(input)).toThrow(ConfigurationError);
+    expect(() => getCommonDestinationEndpoint(input)).toThrow('The region is not valid');
+  });
src/v0/destinations/moengage/transform.js (1)

34-41: Guard unknown categories and URL-encode app_id for alias.

Two small hardening tweaks:

  • Validate category.type exists in both maps.
  • Encode apiId when used as a query param (alias) to avoid malformed URLs.

Apply this diff:

-  if (endpoints[region]) {
-    return {
-      endpoint: `${endpoints[region][category.type]}${apiId}`,
-      path: endpointPaths[category.type],
-    };
-  }
+  if (endpoints[region]) {
+    const base = endpoints[region][category.type];
+    const path = endpointPaths[category.type];
+    if (!base || !path) {
+      throw new ConfigurationError(`The category type "${category.type}" is not supported for region "${region}"`);
+    }
+    const id = category.type === 'alias' ? encodeURIComponent(apiId) : apiId;
+    return {
+      endpoint: `${base}${id}`,
+      path,
+    };
+  }
src/v0/destinations/moengage/config.js (1)

9-31: Freeze config objects to prevent accidental mutation at runtime.

These structures are effectively constants; freezing guards against side effects from shared references.

Apply this diff:

-const endpoints = {
+const endpoints = Object.freeze({
   US: {
     // track properties, | Track
     identify: `https://api-01.moengage.com/v1/${endpointPaths.identify}/`,
     // identify a user| Identify
     track: `https://api-01.moengage.com/v1/${endpointPaths.track}/`,
     // identify a user| Device
     device: `https://api-01.moengage.com/v1/${endpointPaths.device}/`,
     alias: `https://api-01.moengage.com/v1/${endpointPaths.alias}?app_id=`,
   },
   EU: {
     identify: `https://api-02.moengage.com/v1/${endpointPaths.identify}/`,
     track: `https://api-02.moengage.com/v1/${endpointPaths.track}/`,
     device: `https://api-02.moengage.com/v1/${endpointPaths.device}/`,
     alias: `https://api-02.moengage.com/v1/${endpointPaths.alias}?app_id=`,
   },
   IND: {
     identify: `https://api-03.moengage.com/v1/${endpointPaths.identify}/`,
     track: `https://api-03.moengage.com/v1/${endpointPaths.track}/`,
     device: `https://api-03.moengage.com/v1/${endpointPaths.device}/`,
     alias: `https://api-03.moengage.com/v1/${endpointPaths.alias}?app_id=`,
   },
-};
+});

And for paths:

-const endpointPaths = {
+const endpointPaths = Object.freeze({
   identify: 'customer',
   track: 'event',
   device: 'device',
   alias: 'customer/merge',
-};
+});
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ff66dbf and 27453d7.

⛔ Files ignored due to path filters (2)
  • test/integrations/destinations/moengage/processor/data.ts is excluded by !**/test/**
  • test/integrations/destinations/moengage/router/data.ts is excluded by !**/test/**
📒 Files selected for processing (3)
  • src/v0/destinations/moengage/config.js (2 hunks)
  • src/v0/destinations/moengage/transform.js (3 hunks)
  • src/v0/destinations/moengage/transform.test.js (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.js

⚙️ CodeRabbit configuration file

Focus on ESLint errors (max 3) and warnings (max 5).

Files:

  • src/v0/destinations/moengage/transform.test.js
  • src/v0/destinations/moengage/config.js
  • src/v0/destinations/moengage/transform.js
🧬 Code graph analysis (2)
src/v0/destinations/moengage/transform.test.js (2)
src/v0/destinations/moengage/config.js (2)
  • endpoints (9-31)
  • endpointPaths (3-8)
src/v0/destinations/moengage/transform.js (2)
  • getCommonDestinationEndpoint (33-41)
  • getCommonDestinationEndpoint (104-104)
src/v0/destinations/moengage/transform.js (2)
src/v0/destinations/moengage/config.js (3)
  • require (1-1)
  • endpoints (9-31)
  • endpointPaths (3-8)
src/v0/destinations/moengage/transform.test.js (3)
  • require (1-1)
  • require (2-2)
  • require (3-3)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image AMD64
  • GitHub Check: Build Transformer Docker Image - PR / Build Transformer Docker Image ARM64
  • 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/moengage/transform.test.js (2)

2-2: LGTM: config-driven assertions are clear.

Importing endpoints and endpointPaths keeps tests aligned with config. No ESLint issues spotted here.


38-111: Nice parameterized coverage across regions and categories.

Good use of test.each to avoid duplication; assertions on both endpoint and path are precise. No ESLint issues found in this block.

src/v0/destinations/moengage/config.js (2)

3-8: Centralized endpointPaths looks good.

Clear, minimal surface for path management. No ESLint issues found.


67-72: Export surface is sensible and backward-compatible.

Named exports (CONFIG_CATEGORIES, MAPPING_CONFIG, endpointPaths, endpoints) are cohesive. No ESLint issues here.

src/v0/destinations/moengage/transform.js (1)

104-107: Approve — endpoint and endpointPath present; no legacy per‑region constants found

Searched repo (under src/) for endpointEU/endpointUS/endpointIND and regex \bendpoint(EU|US|IND)\b — no matches; moengage uses endpoints/endpointPaths from config. Ready to merge.

@sonarqubecloud

Copy link
Copy Markdown

@koladilip
koladilip merged commit f2f8072 into develop Sep 22, 2025
@koladilip
koladilip deleted the chore.add-endpoint-paths-moengage branch September 22, 2025 10:26
maheshkutty pushed a commit that referenced this pull request Sep 24, 2025
- Refactor endpoint configuration to use endpointPaths object
- Add endpoint path details to transformer responses for better observability
- Update tests to include endpoint path assertions
- Maintain backward compatibility with existing endpoint structure
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