diff --git a/src/v0/destinations/google_adwords_offline_conversions/transform.js b/src/v0/destinations/google_adwords_offline_conversions/transform.js index 511e21e411..579881cf77 100644 --- a/src/v0/destinations/google_adwords_offline_conversions/transform.js +++ b/src/v0/destinations/google_adwords_offline_conversions/transform.js @@ -10,8 +10,8 @@ const { defaultBatchRequestConfig, getSuccessRespEvents, checkInvalidRtTfEvents, - populateConsentForGoogleDestinations, } = require('../../util'); +const { populateConsentForGoogleDestinations } = require('../../util/googleUtils'); const { CALL_CONVERSION, trackCallConversionsMapping, diff --git a/src/v0/util/googleUtils/index.js b/src/v0/util/googleUtils/index.js new file mode 100644 index 0000000000..0331a10c40 --- /dev/null +++ b/src/v0/util/googleUtils/index.js @@ -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 }; diff --git a/src/v0/util/googleUtils/index.test.js b/src/v0/util/googleUtils/index.test.js new file mode 100644 index 0000000000..27eff2a793 --- /dev/null +++ b/src/v0/util/googleUtils/index.test.js @@ -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({}); + }); +}); diff --git a/src/v0/util/index.js b/src/v0/util/index.js index bca98e2e6e..34182a7685 100644 --- a/src/v0/util/index.js +++ b/src/v0/util/index.js @@ -2108,28 +2108,6 @@ const parseConfigArray = (arr, key) => { return arr.map((item) => item[key]); }; -const GOOGLE_ALLOWED_CONSENT_STATUS = ['UNSPECIFIED', 'UNKNOWN', 'GRANTED', 'DENIED']; - -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; -}; - // ======================================================================== // EXPORTS // ======================================================================== @@ -2240,5 +2218,4 @@ module.exports = { isNewStatusCodesAccepted, IsGzipSupported, parseConfigArray, - populateConsentForGoogleDestinations, };