Repository navigation
fix: remove channel from eventSource evaluation for tiktok_ads - #4583
Conversation
Summary by CodeRabbit
WalkthroughgetEventSource for TikTok Ads was simplified: it now accepts only { properties }, removes channel-based and legacy mappings, restricts recognized values to ['web','app','offline','crm'], and falls back to properties.eventSource/event_source or 'web'. Tests were updated to match the new behavior. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Caller
participant Util as getEventSource
Caller->>Util: getEventSource({ properties })
Note over Util: read properties.eventSource or event_source
alt value in [web, app, offline, crm]
Util-->>Caller: return recognized value
else missing or unrecognized
Util-->>Caller: return "web"
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested reviewers
Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ 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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
src/v0/destinations/tiktok_ads/util.js (1)
72-77: Update JSDoc to remove "channel" and reflect the new API.The docstring still mentions "channel" and an old param shape. Please align it with the current behavior and return contract.
/** - * Get event source from message properties or channel. We have considered the following doc + * Resolve TikTok Ads event_source from message.properties only (channel is intentionally ignored). + * Reference: * https://business-api.tiktok.com/portal/docs?id=1771100779668482 - * @param {*} message - * @returns (string): The resolved, valid event source — one of 'web', 'app', 'offline', or 'crm'. Defaults to 'web' if none are valid. + * @param {{ properties?: { eventSource?: string, event_source?: string } }} message + * @returns {string} One of 'web' | 'app' | 'offline' | 'crm'. Defaults to 'web' if not provided or invalid. */src/v0/destinations/tiktok_ads/util.test.js (1)
209-221: Clarify test names to reflect that channel is ignored now.The assertions are correct, but the test titles still talk about "channel". Reword to avoid confusion and reflect the new contract.
- it('returns "web" if both eventSource and channel are missing', () => { + it('returns "web" if eventSource is missing (channel is ignored)', () => { const message = { properties: {} }; expect(getEventSource(message)).toBe('web'); }); - it('returns "web" if both eventSource and channel are invalid', () => { + it('returns "web" if eventSource is invalid (channel is ignored)', () => { const message = { properties: { eventSource: 'foo' }, channel: 'bar' }; expect(getEventSource(message)).toBe('web'); }); - it('returns eventSource if both eventSource and channel are valid', () => { + it('returns eventSource when valid (channel is ignored)', () => { const message = { properties: { eventSource: 'crm' }, channel: 'app' }; expect(getEventSource(message)).toBe('crm'); });If you adopt the normalization in util.js, consider adding these tests to lock the behavior:
it('normalizes case and whitespace for eventSource', () => { expect(getEventSource({ properties: { eventSource: ' Web ' } })).toBe('web'); expect(getEventSource({ properties: { eventSource: 'CRM' } })).toBe('crm'); });
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
⛔ Files ignored due to path filters (1)
test/integrations/destinations/tiktok_ads/router/data.tsis excluded by!**/test/**
📒 Files selected for processing (2)
src/v0/destinations/tiktok_ads/util.js(2 hunks)src/v0/destinations/tiktok_ads/util.test.js(1 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/tiktok_ads/util.test.jssrc/v0/destinations/tiktok_ads/util.js
🧠 Learnings (2)
📓 Common learnings
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
📚 Learning: 2025-07-15T06:27:07.528Z
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
Applied to files:
src/v0/destinations/tiktok_ads/util.test.jssrc/v0/destinations/tiktok_ads/util.js
⏰ 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). (3)
- GitHub Check: UT Tests
- GitHub Check: Analyze (javascript-typescript)
- GitHub Check: Analyze (go)
🔇 Additional comments (1)
src/v0/destinations/tiktok_ads/util.js (1)
78-96: Normalize eventSource with trimming/lowercasing & switch to Set – refactor confirmed safeI’ve scanned all usages of
getEventSource, checked for any upstream reliance on channel fallback, and found no code paths outside of tests and the V2 transformer that would break under the proposed change. Switching to aSetand normalizing input only widens accepted values (e.g.'CRM',' Web '→'crm','web') without altering existing behavior for lowercase, exact matches.• Call-site summary
–src/v0/destinations/tiktok_ads/util.test.js– only covers exact lowercase inputs and default fallback
–src/v0/destinations/tiktok_ads/transformV2.js– usesgetEventSource(message)to setevent_source
– No production code inspects thechannelfield for event source determination• Optional improvement
– Add unit tests inutil.test.jsfor uppercase and whitespace-padded inputs to verify normalization• Proposed diff (no changes since last suggestion):
-const getEventSource = ({ properties }) => { - const supportedSources = ['web', 'app', 'offline', 'crm']; +const getEventSource = ({ properties }) => { + // Use a Set for explicit, O(1) membership checks + const supportedSources = new Set(['web', 'app', 'offline', 'crm']); const { eventSource, event_source: eventSourceV2 } = properties || {}; // Helper function to resolve source const resolveSource = (source) => { - if (!source) return null; + if (!source || typeof source !== 'string') return null; + const normalized = source.trim().toLowerCase(); + if (supportedSources.has(normalized)) return normalized; return null; }; return resolveSource(eventSource) || resolveSource(eventSourceV2) || 'web'; };This refactor is non-breaking and can be safely merged.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## hotfix/21.AUG.2025 #4583 +/- ##
======================================================
- Coverage 91.81% 91.81% -0.01%
======================================================
Files 642 642
Lines 33930 33926 -4
Branches 8041 8031 -10
======================================================
- Hits 31152 31148 -4
- Misses 2526 2548 +22
+ Partials 252 230 -22 ☔ 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 (4)
src/v0/destinations/tiktok_ads/util.test.js (4)
208-211: Rename test to reflect channel is ignored now.Test name still says it uses channel, but the assertion expects ‘web’ (correct). Rename for clarity.
-it('returns channel if eventSource is missing and channel is valid', () => { +it('returns "web" when eventSource is missing (channel ignored)', () => {
212-215: Rename test: remove “channel” semantics from the title.Channel no longer participates in resolution; the expectation to ‘web’ is right. Adjust the title accordingly.
-it('returns channel if eventSource is invalid and channel is valid', () => { +it('returns "web" when eventSource is invalid (channel ignored)', () => {
240-243: Fix misleading test title (“mobile” no longer maps to app).The implementation treats “mobile” as unrecognized and falls back to event_source=web. Update the title to match the new behavior.
-it('if mobile is present, it should return app', () => { - const message = { properties: { eventSource: 'mobile', event_source: 'web' } }; - expect(getEventSource(message)).toBe('web'); +it('falls back to event_source when eventSource is "mobile" (unrecognized)', () => { + const message = { properties: { eventSource: 'mobile', event_source: 'web' } }; + expect(getEventSource(message)).toBe('web');
216-227: Optional: Normalize other titles to remove references to channel.These tests are valid, but titles still mention channel, which can confuse future readers now that channel is ignored.
-it('returns "web" if both eventSource and channel are missing', () => { +it('returns "web" if eventSource is missing', () => { const message = { properties: {} }; expect(getEventSource(message)).toBe('web'); }); -it('returns "web" if both eventSource and channel are invalid', () => { +it('returns "web" if eventSource is invalid', () => { const message = { properties: { eventSource: 'foo' }, channel: 'bar' }; expect(getEventSource(message)).toBe('web'); }); -it('returns eventSource if both eventSource and channel are valid', () => { +it('returns eventSource when it is valid (channel ignored)', () => { const message = { properties: { eventSource: 'crm' }, channel: 'app' }; expect(getEventSource(message)).toBe('crm'); });
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
src/v0/destinations/tiktok_ads/util.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/tiktok_ads/util.test.js
🧠 Learnings (2)
📓 Common learnings
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
📚 Learning: 2025-07-15T06:27:07.528Z
Learnt from: ItsSudip
PR: rudderlabs/rudder-transformer#4497
File: src/v0/destinations/tiktok_ads/transformV2.js:686-691
Timestamp: 2025-07-15T06:27:07.528Z
Learning: For TikTok Ads destination in src/v0/destinations/tiktok_ads/transformV2.js, there are plans for a future enhancement to group events by eventSource when batching to ensure all events in a batch have the same event_source value, as acknowledged by ItsSudip in PR #4497.
Applied to files:
src/v0/destinations/tiktok_ads/util.test.js
🧬 Code graph analysis (1)
src/v0/destinations/tiktok_ads/util.test.js (1)
src/v0/destinations/tiktok_ads/util.js (2)
getEventSource(78-96)message(11-11)
⏰ 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). (1)
- GitHub Check: Analyze (go)
🔇 Additional comments (1)
src/v0/destinations/tiktok_ads/util.test.js (1)
199-244: AllgetEventSourcecall sites now use the single-argument signatureI ran the AST-grep and ripgrep searches as suggested and confirmed there are no two- or three-argument invocations of
getEventSourceanywhere in the repository. All existing call sites correctly use the updated single-argument form, for example:
src/v0/destinations/tiktok_ads/util.test.js: all tests callgetEventSource(message)onlysrc/v0/destinations/tiktok_ads/transformV2.js(line 166):event_source: getEventSource(message)No further action is needed here—this completes the sanity check.
|
Allure Test reports for this run are available at:
|
|



What are the changes introduced in this PR?
Remove channel from evaluation of event_source for tiktok_ads
What is the related Linear task?
Resolves INT-XXX
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.