From 7ca6707a0a32a0d59268138edcaa86be7ebcacb0 Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Mon, 26 Feb 2024 15:08:49 +0530 Subject: [PATCH] fix: clean up of unnecessary code --- .../google_adwords_remarketing_lists/utils.js | 3 +- src/v0/util/googleUtils/index.js | 56 ------- src/v0/util/googleUtils/index.test.js | 154 ------------------ 3 files changed, 2 insertions(+), 211 deletions(-) delete mode 100644 src/v0/util/googleUtils/index.js delete mode 100644 src/v0/util/googleUtils/index.test.js diff --git a/src/v0/destinations/google_adwords_remarketing_lists/utils.js b/src/v0/destinations/google_adwords_remarketing_lists/utils.js index b02d32db30..3ffbe0c491 100644 --- a/src/v0/destinations/google_adwords_remarketing_lists/utils.js +++ b/src/v0/destinations/google_adwords_remarketing_lists/utils.js @@ -1,5 +1,6 @@ const lodash = require('lodash'); -const { GOOGLE_ALLOWED_CONSENT_STATUS } = require('../../util/googleUtils'); + +const GOOGLE_ALLOWED_CONSENT_STATUS = ['UNSPECIFIED', 'UNKNOWN', 'GRANTED', 'DENIED']; // Helper to validate and transform consent values const validateAndTransformConsent = (consentValue) => { diff --git a/src/v0/util/googleUtils/index.js b/src/v0/util/googleUtils/index.js deleted file mode 100644 index d18a27ad83..0000000000 --- a/src/v0/util/googleUtils/index.js +++ /dev/null @@ -1,56 +0,0 @@ -const get = require('get-value'); -const { getIntegrationsObj } = require('..'); - -const GOOGLE_ALLOWED_CONSENT_STATUS = ['UNSPECIFIED', 'UNKNOWN', 'GRANTED', 'DENIED']; -const { MappedToDestinationKey } = require('../../../constants'); - -/** - * 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 = (message, destName) => { - const mappedToDestination = get(message, MappedToDestinationKey); - if (mappedToDestination) return {}; - // Define mappings for different destination names - const mappings = { - GOOGLE_ADWORDS_OFFLINE_CONVERSIONS: { - ad_user_data: 'ad_user_data', - ad_personalization: 'ad_personalization', - }, - GOOGLE_ADWORDS_REMARKETING_LISTS: { - adUserData: 'adUserData', - adPersonalization: 'adPersonalization', - }, - }; - - const currentMapping = mappings[destName]; - if (!currentMapping) return {}; - - const integrationObj = getIntegrationsObj(message, destName) || {}; - const consents = integrationObj.consents || {}; - - // Define a function to process consent based on type and key - const processConsent = (consentType) => { - if (consents[consentType] && GOOGLE_ALLOWED_CONSENT_STATUS.includes(consents[consentType])) { - return consents[consentType]; - } - return 'UNSPECIFIED'; - }; - - // Construct consentObj based on the current mapping - const consentObj = Object.keys(currentMapping).reduce((obj, consentType) => { - const key = currentMapping[consentType]; - // Process each consent type and assign it to the key specified in the mapping - // eslint-disable-next-line no-param-reassign - obj[key] = processConsent(consentType); - return obj; - }, {}); - - return consentObj; -}; - -module.exports = { populateConsentForGoogleDestinations, GOOGLE_ALLOWED_CONSENT_STATUS }; diff --git a/src/v0/util/googleUtils/index.test.js b/src/v0/util/googleUtils/index.test.js deleted file mode 100644 index b969ab73b0..0000000000 --- a/src/v0/util/googleUtils/index.test.js +++ /dev/null @@ -1,154 +0,0 @@ -const { populateConsentForGoogleDestinations } = require('./index'); - -describe('populateConsentForGoogleDestinations', () => { - - // Returns an object with ad_user_data and ad_personalization properties set to UNSPECIFIED when no consents are provided - it('GOOGLE_ADWORDS_OFFLINE_CONVERSIONS : should return an object with ad_user_data and ad_personalization properties set to UNSPECIFIED when no consents are provided', () => { - const message = {}; - const destName = 'GOOGLE_ADWORDS_OFFLINE_CONVERSIONS'; - - const result = populateConsentForGoogleDestinations(message, destName); - - expect(result).toEqual({ - ad_user_data: 'UNSPECIFIED', - ad_personalization: 'UNSPECIFIED', - }); - }); - - // Returns an empty object when the destination name is not recognized - it('GOOGLE_ADWORDS_OFFLINE_CONVERSIONS: should return an empty object when the destination name is not recognized', () => { - const message = {}; - const destName = 'unknown_destination'; - - const result = populateConsentForGoogleDestinations(message, destName); - - expect(result).toEqual({}); - }); - - // Returns an object with ad_user_data and ad_personalization properties set to the provided consents when they are valid and present in the message properties - it('GOOGLE_ADWORDS_OFFLINE_CONVERSIONS: should return an object with ad_user_data and ad_personalization properties set to the provided consents when they are valid and present in the message properties', () => { - const message = { - integrations: { - google_adwords_offline_conversions: { - consents: { - ad_user_data: 'GRANTED', - ad_personalization: 'DENIED' - } - } - } - }; - const destName = 'GOOGLE_ADWORDS_OFFLINE_CONVERSIONS'; - - const result = populateConsentForGoogleDestinations(message, destName); - - expect(result).toEqual({ - ad_user_data: 'GRANTED', - ad_personalization: 'DENIED', - }); - }); - - // Returns an object with ad_user_data and ad_personalization properties set to UNSPECIFIED when the provided consents are not valid or not present in the message properties - it('GOOGLE_ADWORDS_OFFLINE_CONVERSIONS : should return an object with ad_user_data and ad_personalization properties set to UNSPECIFIED when the provided consents are not valid or not present in the message properties', () => { - const message = { - integrations: { - google_adwords_offline_conversions: { - consents: { - ad_user_data: 'GRANTED', - ad_personalization: 'INVALID' - } - } - } - }; - const destName = 'GOOGLE_ADWORDS_OFFLINE_CONVERSIONS'; - - const result = populateConsentForGoogleDestinations(message, destName); - - expect(result).toEqual({ - ad_user_data: 'GRANTED', - ad_personalization: 'UNSPECIFIED', - }); - }); - - // Returns an empty object when the integration object is not present in the message - it('GOOGLE_ADWORDS_OFFLINE_CONVERSIONS : should return an default object when the integration object is not present in the message', () => { - const message = {}; - const destName = 'GOOGLE_ADWORDS_OFFLINE_CONVERSIONS'; - - const result = populateConsentForGoogleDestinations(message, destName); - - expect(result).toEqual({ - ad_user_data: 'UNSPECIFIED', - ad_personalization: 'UNSPECIFIED', - }); - }); - - // Returns an object with ad_user_data and ad_personalization properties set to UNSPECIFIED when no consents are provided - it('GOOGLE_ADWORDS_REMARKETING_LISTS: should return an object with ad_user_data and ad_personalization properties set to UNSPECIFIED when no consents are provided', () => { - const message = {}; - const destName = 'GOOGLE_ADWORDS_REMARKETING_LISTS'; - - const result = populateConsentForGoogleDestinations(message, destName); - - expect(result).toEqual({ - adUserData: 'UNSPECIFIED', - adPersonalization: 'UNSPECIFIED', - }); - }); - - // Returns an object with ad_user_data and ad_personalization properties set to the provided consents when they are valid and present in the message properties - it('GOOGLE_ADWORDS_REMARKETING_LISTS : should return an object with ad_user_data and ad_personalization properties set to the provided consents when they are valid and present in the message properties', () => { - const message = { - integrations: { - google_adwords_remarketing_lists: { - consents: { - adUserData: 'GRANTED', - adPersonalization: 'DENIED' - } - } - } - }; - const destName = 'GOOGLE_ADWORDS_REMARKETING_LISTS'; - - const result = populateConsentForGoogleDestinations(message, destName); - - expect(result).toEqual({ - adUserData: 'GRANTED', - adPersonalization: 'DENIED', - }); - }); - - // Returns an object with ad_user_data and ad_personalization properties set to UNSPECIFIED when the provided consents are not valid or not present in the message properties - it('GOOGLE_ADWORDS_REMARKETING_LISTS : should return an object with ad_user_data and ad_personalization properties set to UNSPECIFIED when the provided consents are not valid or not present in the message properties', () => { - const message = { - integrations: { - google_adwords_remarketing_lists: { - consents: { - adUserData: 'GRANTED', - adPersonalization: 'INVALID' - } - } - } - }; - const destName = 'GOOGLE_ADWORDS_REMARKETING_LISTS'; - - const result = populateConsentForGoogleDestinations(message, destName); - - expect(result).toEqual({ - adUserData: 'GRANTED', - adPersonalization: 'UNSPECIFIED', - }); - }); - - // Returns an empty object when the integration object is not present in the message - it('GOOGLE_ADWORDS_REMARKETING_LISTS : should return an default object when the integration object is not present in the message', () => { - const message = {}; - const destName = 'GOOGLE_ADWORDS_REMARKETING_LISTS'; - - const result = populateConsentForGoogleDestinations(message, destName); - - expect(result).toEqual({ - adUserData: 'UNSPECIFIED', - adPersonalization: 'UNSPECIFIED', - }); - }); -});