-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat.slack-source' of https://github.com/rudderlabs/rud…
…der-transformer into feat.slack-source
- Loading branch information
Showing
36 changed files
with
2,572 additions
and
711 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
const { getHashFromArray } = require('../../util'); | ||
|
||
/** | ||
* Retrieves the mapped event name from the given config. | ||
* | ||
* @param {object} message - The message object containing the event. | ||
* @param {object} destination - The destination object containing the events mapping configuration. | ||
* @returns {string} - The mapped event name, or undefined if not found. | ||
*/ | ||
const getMappedEventNameFromConfig = (message, destination) => { | ||
let eventName; | ||
const { event } = message; | ||
const { eventsMapping } = destination.Config; | ||
|
||
// if event is mapped on dashboard, use the mapped event name | ||
if (Array.isArray(eventsMapping) && eventsMapping.length > 0) { | ||
const keyMap = getHashFromArray(eventsMapping, 'from', 'to', false); | ||
eventName = keyMap[event]; | ||
} | ||
|
||
return eventName; | ||
}; | ||
|
||
module.exports = { getMappedEventNameFromConfig }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
const { getMappedEventNameFromConfig } = require('./utils'); | ||
describe('getMappedEventNameFromConfig', () => { | ||
it('should return the mapped event name when it exists in the events mapping configuration', () => { | ||
const message = { event: 'Order Completed' }; | ||
const destination = { | ||
Config: { eventsMapping: [{ from: 'Order Completed', to: 'PURCHASE' }] }, | ||
}; | ||
const result = getMappedEventNameFromConfig(message, destination); | ||
expect(result).toBe('PURCHASE'); | ||
}); | ||
|
||
it('should return undefined when the event mapping is not created', () => { | ||
const message = { event: 'Order Completed' }; | ||
const destination = { Config: {} }; | ||
const result = getMappedEventNameFromConfig(message, destination); | ||
expect(result).toBeUndefined(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.