-
Notifications
You must be signed in to change notification settings - Fork 122
fix: fb pixel test case refactor #3075
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d640005
fix: initial commit
shrouti1507 b52fe41
Merge branch 'develop' into test-refactor.fbPixel
shrouti1507 f97f9ce
Merge branch 'develop' of github.com:rudderlabs/rudder-transformer in…
shrouti1507 caa8d45
fix: identify validation page screen
shrouti1507 308c64c
fix: adding ecomm test cases
shrouti1507 c45f9b6
fix: adding config level features test cases
shrouti1507 4c26c7f
Merge branch 'develop' into test-refactor.fbPixel
shrouti1507 7e80aa0
Merge branch 'develop' into test-refactor.fbPixel
shrouti1507 14164c7
fix: updating the common destination
shrouti1507 89390ef
fix: review comments addressed
shrouti1507 e711ea2
fix: conflict resolved
shrouti1507 eb8de80
Merge branch 'develop' into test-refactor.fbPixel
shrouti1507 1ff8127
fix: review comments address
shrouti1507 7cf683b
fix: enhance code coverage
shrouti1507 46576ca
Merge branch 'develop' into test-refactor.fbPixel
shrouti1507 95ae2c4
fix: review comments addressed
shrouti1507 dfc36a3
Merge branch 'develop' into test-refactor.fbPixel
shrouti1507 792a622
Merge branch 'develop' into test-refactor.fbPixel
shrouti1507 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,170 @@ | ||
const { InstrumentationError } = require('@rudderstack/integrations-lib'); | ||
const { getActionSource, formatRevenue, getCategoryFromEvent } = require('./utils'); | ||
const { CONFIG_CATEGORIES, OTHER_STANDARD_EVENTS } = require('./config'); | ||
|
||
describe('Test Facebook Pixel Utils', () => { | ||
describe('getActionSource', () => { | ||
// Returns 'other' if payload.action_source is not defined and channel is neither 'web' nor 'mobile' | ||
it('should return "other" when payload.action_source is not defined and channel is neither "web" nor "mobile"', () => { | ||
const payload = {}; | ||
const channel = 'email'; | ||
const result = getActionSource(payload, channel); | ||
expect(result).toBe('other'); | ||
}); | ||
|
||
// Returns payload.action_source if it is defined and is a valid value from ACTION_SOURCES_VALUES | ||
it('should return payload.action_source when it is defined and is a valid value from ACTION_SOURCES_VALUES', () => { | ||
const payload = { action_source: 'website' }; | ||
const channel = 'email'; | ||
const result = getActionSource(payload, channel); | ||
expect(result).toBe('website'); | ||
}); | ||
|
||
// Returns 'website' if channel is 'web' and payload.action_source is not defined | ||
it('should return "website" when channel is "web" and payload.action_source is not defined', () => { | ||
const payload = {}; | ||
const channel = 'web'; | ||
const result = getActionSource(payload, channel); | ||
expect(result).toBe('website'); | ||
}); | ||
|
||
// Throws an InstrumentationError if payload.action_source is defined but not a valid value from ACTION_SOURCES_VALUES | ||
it('should throw an InstrumentationError when payload.action_source is defined but not a valid value from ACTION_SOURCES_VALUES', () => { | ||
const payload = { action_source: 'invalid' }; | ||
const channel = 'email'; | ||
expect(() => { | ||
getActionSource(payload, channel); | ||
}).toThrow(InstrumentationError); | ||
}); | ||
|
||
// Returns 'other' if payload is not defined | ||
it('should return "other" when payload is not defined', () => { | ||
const payload = undefined; | ||
const channel = 'email'; | ||
const result = getActionSource(payload, channel); | ||
expect(result).toBe('other'); | ||
}); | ||
|
||
// Returns 'website' if channel is 'web' and payload is not defined | ||
it('should return "website" when channel is "web" and payload is not defined', () => { | ||
const payload = undefined; | ||
const channel = 'web'; | ||
const result = getActionSource(payload, channel); | ||
expect(result).toBe('website'); | ||
}); | ||
}); | ||
|
||
describe('formatRevenue', () => { | ||
// Returns a number with two decimal places when passed a valid revenue value. | ||
it('should return a number with two decimal places when passed a valid revenue value', () => { | ||
const revenue = '100.50'; | ||
const formattedRevenue = formatRevenue(revenue); | ||
expect(formattedRevenue).toBe(100.5); | ||
}); | ||
|
||
// Returns 0 when passed a null revenue value. | ||
it('should return 0 when passed a null revenue value', () => { | ||
const revenue = null; | ||
const formattedRevenue = formatRevenue(revenue); | ||
expect(formattedRevenue).toBe(0); | ||
}); | ||
|
||
// Returns 0 when passed an undefined revenue value. | ||
it('should return 0 when passed an undefined revenue value', () => { | ||
const revenue = undefined; | ||
const formattedRevenue = formatRevenue(revenue); | ||
expect(formattedRevenue).toBe(0); | ||
}); | ||
|
||
// Throws an InstrumentationError when passed a non-numeric string revenue value. | ||
it('should throw an InstrumentationError when passed a non-numeric string revenue value', () => { | ||
const revenue = 'abc'; | ||
expect(() => { | ||
formatRevenue(revenue); | ||
}).toThrow(InstrumentationError); | ||
}); | ||
|
||
// Returns a number with two decimal places when passed a numeric string revenue value with more than two decimal places. | ||
it('should return a number with two decimal places when passed a numeric string revenue value with more than two decimal places', () => { | ||
const revenue = '100.555'; | ||
const formattedRevenue = formatRevenue(revenue); | ||
expect(formattedRevenue).toBe(100.56); | ||
}); | ||
|
||
// Returns a number with two decimal places when passed a numeric value with more than two decimal places. | ||
it('should return a number with two decimal places when passed a numeric value with more than two decimal places', () => { | ||
const revenue = 100.555; | ||
const formattedRevenue = formatRevenue(revenue); | ||
expect(formattedRevenue).toBe(100.56); | ||
}); | ||
}); | ||
|
||
describe('getCategoryFromEvent', () => { | ||
// The function correctly maps the eventName to its corresponding category. | ||
it('should correctly map the eventName to its corresponding category', () => { | ||
const eventName = CONFIG_CATEGORIES.PRODUCT_LIST_VIEWED.type; | ||
const result = getCategoryFromEvent(eventName); | ||
expect(result).toEqual(CONFIG_CATEGORIES.PRODUCT_LIST_VIEWED); | ||
}); | ||
|
||
// The function returns the correct category for a given eventName. | ||
it('should return the correct category for a given eventName', () => { | ||
const eventName = CONFIG_CATEGORIES.PRODUCT_VIEWED.type; | ||
const result = getCategoryFromEvent(eventName); | ||
expect(result).toEqual(CONFIG_CATEGORIES.PRODUCT_VIEWED); | ||
}); | ||
|
||
// The function returns the default category if the eventName is not recognized. | ||
it('should return the default category if the eventName is not recognized', () => { | ||
const eventName = 'unknownEvent'; | ||
const result = getCategoryFromEvent(eventName); | ||
expect(result).toEqual(CONFIG_CATEGORIES.SIMPLE_TRACK); | ||
}); | ||
|
||
// The function handles null or undefined eventName inputs. | ||
it('should handle null or undefined eventName inputs', () => { | ||
const eventName = null; | ||
const result = getCategoryFromEvent(eventName); | ||
expect(result).toEqual(CONFIG_CATEGORIES.SIMPLE_TRACK); | ||
}); | ||
|
||
// The function handles empty string eventName inputs. | ||
it('should handle empty string eventName inputs', () => { | ||
const eventName = ''; | ||
const result = getCategoryFromEvent(eventName); | ||
expect(result).toEqual(CONFIG_CATEGORIES.SIMPLE_TRACK); | ||
}); | ||
|
||
// The function handles eventName inputs that are not strings. | ||
it('should handle eventName inputs that are not strings', () => { | ||
const eventName = 123; | ||
const result = getCategoryFromEvent(eventName); | ||
expect(result).toEqual(CONFIG_CATEGORIES.SIMPLE_TRACK); | ||
}); | ||
|
||
// The function handles multiple eventNames that map to the same category. | ||
it('should correctly map multiple eventNames to the same category', () => { | ||
const eventName1 = CONFIG_CATEGORIES.PRODUCT_LIST_VIEWED.type; | ||
const eventName2 = CONFIG_CATEGORIES.PRODUCT_LIST_VIEWED.eventName; | ||
const result1 = getCategoryFromEvent(eventName1); | ||
const result2 = getCategoryFromEvent(eventName2); | ||
expect(result1).toEqual(CONFIG_CATEGORIES.PRODUCT_LIST_VIEWED); | ||
expect(result2).toEqual(CONFIG_CATEGORIES.PRODUCT_LIST_VIEWED); | ||
}); | ||
|
||
// The function handles eventNames that are included in the OTHER_STANDARD_EVENTS list. | ||
it('should correctly handle eventNames included in the OTHER_STANDARD_EVENTS list', () => { | ||
const eventName = OTHER_STANDARD_EVENTS[0]; | ||
const result = getCategoryFromEvent(eventName); | ||
expect(result).toEqual(CONFIG_CATEGORIES.OTHER_STANDARD); | ||
expect(result.eventName).toEqual(eventName); | ||
}); | ||
|
||
// The function handles eventNames that are not recognized and not in the OTHER_STANDARD_EVENTS list. | ||
it('should correctly handle unrecognized eventNames', () => { | ||
const eventName = 'unrecognizedEvent'; | ||
const result = getCategoryFromEvent(eventName); | ||
expect(result).toEqual(CONFIG_CATEGORIES.SIMPLE_TRACK); | ||
}); | ||
}); | ||
}); |
This file contains hidden or 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 |
---|---|---|
|
@@ -298,4 +298,5 @@ module.exports = { | |
transformedPayloadData, | ||
formingFinalResponse, | ||
fetchUserData, | ||
deduceFbcParam, | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.