Repository navigation
feat(moengage): add endpoint paths to transformer responses - #4661
Conversation
- 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
Summary by CodeRabbit
WalkthroughRefactors 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Suggestions
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests
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. Comment |
|
Allure Test reports for this run are available at:
|
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
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.typeexists in both maps.- Encode
apiIdwhen 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
⛔ Files ignored due to path filters (2)
test/integrations/destinations/moengage/processor/data.tsis excluded by!**/test/**test/integrations/destinations/moengage/router/data.tsis 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.jssrc/v0/destinations/moengage/config.jssrc/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
endpointsandendpointPathskeeps tests aligned with config. No ESLint issues spotted here.
38-111: Nice parameterized coverage across regions and categories.Good use of
test.eachto avoid duplication; assertions on bothendpointandpathare 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 foundSearched 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.
|
- 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



Summary
This PR adds endpoint path details to MoEngage transformer responses for better observability and debugging.
Changes
endpointPathsobject for better maintainabilityFiles Modified
src/v0/destinations/moengage/config.js- Refactored endpoint configurationsrc/v0/destinations/moengage/transform.js- Added endpoint path to responsessrc/v0/destinations/moengage/transform.test.js- Updated teststest/integrations/destinations/moengage/processor/data.ts- Added test datatest/integrations/destinations/moengage/router/data.ts- Added test dataTesting