-
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.
fix: adding new googleUtil folder to migrate the util and add test cases
- Loading branch information
1 parent
940c365
commit 9f4ef9a
Showing
4 changed files
with
81 additions
and
24 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
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,30 @@ | ||
const GOOGLE_ALLOWED_CONSENT_STATUS = ['UNSPECIFIED', 'UNKNOWN', 'GRANTED', 'DENIED']; | ||
|
||
/** | ||
* Populates the consent object based on the provided properties. | ||
* | ||
* @param {object} properties - message.properties containing properties related to consent. | ||
* @returns {object} - An object containing consent information. | ||
* ref : https://developers.google.com/google-ads/api/rest/reference/rest/v15/Consent | ||
*/ | ||
const populateConsentForGoogleDestinations = (properties) => { | ||
const consent = {}; | ||
|
||
if ( | ||
properties?.userDataConsent && | ||
GOOGLE_ALLOWED_CONSENT_STATUS.includes(properties.userDataConsent) | ||
) { | ||
consent.adUserData = properties.userDataConsent; | ||
} | ||
|
||
if ( | ||
properties?.personalizationConsent && | ||
GOOGLE_ALLOWED_CONSENT_STATUS.includes(properties.personalizationConsent) | ||
) { | ||
consent.adPersonalization = properties.personalizationConsent; | ||
} | ||
|
||
return consent; | ||
}; | ||
|
||
module.exports = { populateConsentForGoogleDestinations }; |
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,50 @@ | ||
const { populateConsentForGoogleDestinations } = require('./index'); | ||
|
||
describe('unit test for populateConsentForGoogleDestinations', () => { | ||
// Returns an empty object when no properties are provided. | ||
it('should return an empty object when no properties are provided', () => { | ||
const result = populateConsentForGoogleDestinations({}); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
// Sets adUserData property of consent object when userDataConsent property is provided and its value is one of the allowed consent statuses. | ||
it('should set adUserData property of consent object when userDataConsent property is provided and its value is one of the allowed consent statuses', () => { | ||
const properties = { userDataConsent: 'GRANTED' }; | ||
const result = populateConsentForGoogleDestinations(properties); | ||
expect(result).toEqual({ adUserData: 'GRANTED' }); | ||
}); | ||
|
||
// Sets adPersonalization property of consent object when personalizationConsent property is provided and its value is one of the allowed consent statuses. | ||
it('should set adPersonalization property of consent object when personalizationConsent property is provided and its value is one of the allowed consent statuses', () => { | ||
const properties = { personalizationConsent: 'DENIED' }; | ||
const result = populateConsentForGoogleDestinations(properties); | ||
expect(result).toEqual({ adPersonalization: 'DENIED' }); | ||
}); | ||
|
||
// Returns an empty object when properties parameter is not provided. | ||
it('should return an empty object when properties parameter is not provided', () => { | ||
const result = populateConsentForGoogleDestinations(); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
// Returns an empty object when properties parameter is null. | ||
it('should return an empty object when properties parameter is null', () => { | ||
const result = populateConsentForGoogleDestinations(null); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
// Returns an empty object when properties parameter is an empty object. | ||
it('should return an empty object when properties parameter is an empty object', () => { | ||
const result = populateConsentForGoogleDestinations({}); | ||
expect(result).toEqual({}); | ||
}); | ||
|
||
// Returns an empty object when properties parameter is an empty object. | ||
it('should return an empty object when properties parameter contains adUserData and adPersonalization with non-allowed values', () => { | ||
const result = populateConsentForGoogleDestinations({ | ||
adUserData: 'RANDOM', | ||
personalizationConsent: 'RANDOM', | ||
}); | ||
expect(result).toEqual({}); | ||
}); | ||
}); |
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