-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: criteo add support for multiple hash methods (#1812)
* feat: criteo add support for multiple hash methods * chore: add util test cases * chore: add util test cases+1
- Loading branch information
1 parent
1a8fee8
commit 23a0e37
Showing
2 changed files
with
79 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import md5 from 'md5'; | ||
import { handleCommonFields, handleProductAdded } from '../../../src/integrations/Criteo/utils'; | ||
import sha256 from 'crypto-js/sha256'; | ||
import { | ||
handleCommonFields, | ||
handleProductAdded, | ||
getEmailHashes, | ||
getEmail, | ||
} from '../../../src/integrations/Criteo/utils'; | ||
|
||
describe('handleCommonFields', () => { | ||
const inputEvent = { | ||
|
@@ -175,3 +181,40 @@ describe('handleProductAdded', () => { | |
expect(finalPayload[0].item[0].quantity).toBe(5); | ||
}); | ||
}); | ||
|
||
describe('getEmailHashes', () => { | ||
const email = '[email protected]'; | ||
// Returns correct hashes when hashMethod is 'both' | ||
it('should return correct hashes when hashMethod is "both"', () => { | ||
const hashMethod = 'both'; | ||
const result = getEmailHashes(email, hashMethod); | ||
expect(result).toEqual([ | ||
{ event: 'setEmail', hash_method: 'sha256', email: getEmail(email, 'sha256') }, | ||
{ event: 'setEmail', hash_method: 'md5', email: getEmail(email, 'md5') }, | ||
]); | ||
}); | ||
|
||
// Handles empty email input | ||
it('should handle empty email input', () => { | ||
const email = ''; | ||
const hashMethod = 'both'; | ||
const result = getEmailHashes(email, hashMethod); | ||
expect(result).toEqual([ | ||
{ event: 'setEmail', hash_method: 'sha256', email: getEmail(email, 'sha256') }, | ||
{ event: 'setEmail', hash_method: 'md5', email: getEmail(email, 'md5') }, | ||
]); | ||
}); | ||
|
||
it('should return correct hash when hashMethod is sha256', () => { | ||
const hashMethod = 'sha256'; | ||
const expectedHash = sha256(email).toString(); | ||
const result = getEmailHashes(email, hashMethod); | ||
expect(result).toEqual([{ event: 'setEmail', hash_method: 'sha256', email: expectedHash }]); | ||
}); | ||
|
||
it('should return correct hash when hashMethod is none', () => { | ||
const hashMethod = 'none'; | ||
const result = getEmailHashes(email, hashMethod); | ||
expect(result).toEqual([{ event: 'setEmail', email }]); | ||
}); | ||
}); |
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