Skip to content

Commit

Permalink
fix: review comments address
Browse files Browse the repository at this point in the history
  • Loading branch information
shrouti1507 committed Mar 11, 2024
1 parent a027389 commit af7a820
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 15 deletions.
23 changes: 10 additions & 13 deletions src/v0/destinations/google_adwords_offline_conversions/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const {
defaultBatchRequestConfig,
getSuccessRespEvents,
combineBatchRequestsWithSameJobIds,
getIntegrationsObj,
} = require('../../util');
const {
CALL_CONVERSION,
Expand All @@ -23,18 +22,11 @@ const {
getStoreConversionPayload,
requestBuilder,
getClickConversionPayloadAndEndpoint,
getConsentsDataFromIntegrationObj,
} = require('./utils');
const { finaliseConsent } = require('../../util/googleUtils');
const helper = require('./helper');

const getConsentsDataFromIntegrationObj = (message, conversionType) => {
const integrationObj =
conversionType === 'store'
? {}
: getIntegrationsObj(message, 'GOOGLE_ADWORDS_OFFLINE_CONVERSIONS') || {};
return integrationObj?.consents || {};
};

/**
* get conversions depending on the type set from dashboard
* i.e click conversions or call conversions
Expand All @@ -52,24 +44,29 @@ const getConversions = (message, metadata, { Config }, event, conversionType) =>
const { properties, timestamp, originalTimestamp } = message;

const filteredCustomerId = removeHyphens(customerId);
const eventLevelConsentsData = getConsentFromIntegrationObj(message, conversionType);
const eventLevelConsentsData = getConsentsDataFromIntegrationObj(message, conversionType);

if (conversionType === 'click') {
// click conversion
const convertedPayload = getClickConversionPayloadAndEndpoint(
message,
Config,
filteredCustomerId,
userSentConsentValues,
eventLevelConsentsData,
);
payload = convertedPayload.payload;
endpoint = convertedPayload.endpoint;
} else if (conversionType === 'store') {
payload = getStoreConversionPayload(message, Config, filteredCustomerId, userSentConsentValues);
payload = getStoreConversionPayload(
message,
Config,
filteredCustomerId,
eventLevelConsentsData,
);
endpoint = STORE_CONVERSION_CONFIG.replace(':customerId', filteredCustomerId);
} else {
// call conversions
const consentObject = finaliseConsent(userSentConsentValues, Config, consentFields);
const consentObject = finaliseConsent(eventLevelConsentsData, Config, consentFields);
payload = constructPayload(message, trackCallConversionsMapping);
endpoint = CALL_CONVERSION.replace(':customerId', filteredCustomerId);
payload.conversions[0].consent = consentObject;
Expand Down
10 changes: 10 additions & 0 deletions src/v0/destinations/google_adwords_offline_conversions/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const {
isDefinedAndNotNull,
getAuthErrCategoryFromStCode,
getAccessToken,
getIntegrationsObj,
} = require('../../util');
const {
SEARCH_STREAM,
Expand Down Expand Up @@ -376,6 +377,14 @@ const getClickConversionPayloadAndEndpoint = (
return { payload, endpoint };
};

const getConsentsDataFromIntegrationObj = (message, conversionType) => {
const integrationObj =
conversionType === 'store'
? {}
: getIntegrationsObj(message, 'GOOGLE_ADWORDS_OFFLINE_CONVERSIONS') || {};
return integrationObj?.consents || {};
};

module.exports = {
validateDestinationConfig,
generateItemListFromProducts,
Expand All @@ -386,4 +395,5 @@ module.exports = {
buildAndGetAddress,
getClickConversionPayloadAndEndpoint,
getExisitingUserIdentifier,
getConsentsDataFromIntegrationObj,
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const {
getClickConversionPayloadAndEndpoint,
buildAndGetAddress,
getExisitingUserIdentifier,
getConsentsDataFromIntegrationObj,
} = require('./utils');

const getTestMessage = () => {
Expand Down Expand Up @@ -285,3 +286,46 @@ describe('getClickConversionPayloadAndEndpoint util tests', () => {
);
});
});

describe('getConsentsDataFromIntegrationObj', () => {
it('should return an empty object when conversionType is "store"', () => {
const message = {};
const conversionType = 'store';
const result = getConsentsDataFromIntegrationObj(message, conversionType);
expect(result).toEqual({});
});

it('should return an empty object when conversionType is not "store" and getIntegrationsObj returns undefined', () => {
const message = {};
const conversionType = 'click';
const result = getConsentsDataFromIntegrationObj(message, conversionType);
expect(result).toEqual({});
});

it('should return an empty object when conversionType is not "store" and getIntegrationsObj returns null', () => {
const message = {};
const conversionType = 'call';
const getIntegrationsObj = jest.fn(() => null);
const result = getConsentsDataFromIntegrationObj(message, conversionType);
expect(result).toEqual({});
});

it('should return the consent object when conversion type is call', () => {
const message = {
integrations: {
GOOGLE_ADWORDS_OFFLINE_CONVERSIONS: {
consents: {
adUserData: 'GRANTED',
adPersonalization: 'DENIED',
},
},
},
};
const conversionType = 'call';
const result = getConsentsDataFromIntegrationObj(message, conversionType);
expect(result).toEqual({
adPersonalization: 'DENIED',
adUserData: 'GRANTED',
});
});
});
2 changes: 0 additions & 2 deletions src/v0/util/googleUtils/index.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const { populateConsentFromConfig, finaliseConsent } = require('./index');

const destinationAllowedConsentKeys = ['adUserData', 'adPersonalization'];

describe('unit test for populateConsentFromConfig', () => {
it('should return an UNSPECIFIED object when no properties are provided', () => {
const result = populateConsentFromConfig({});
Expand Down

0 comments on commit af7a820

Please sign in to comment.