From 68367f5227c96f2700a773018b991b1e87a0774d Mon Sep 17 00:00:00 2001 From: Sudip Paul <67197965+ItsSudip@users.noreply.github.com> Date: Wed, 24 Jul 2024 11:50:25 +0530 Subject: [PATCH] fix: update getConversionActionId function for gaoc (#3594) --- .../utils.js | 5 +- .../dataDelivery/oauth.ts | 72 +++++++++++++++++++ .../network.ts | 69 +++++++++++------- 3 files changed, 119 insertions(+), 27 deletions(-) diff --git a/src/v0/destinations/google_adwords_offline_conversions/utils.js b/src/v0/destinations/google_adwords_offline_conversions/utils.js index 7c21371ccf5..7228bb8da41 100644 --- a/src/v0/destinations/google_adwords_offline_conversions/utils.js +++ b/src/v0/destinations/google_adwords_offline_conversions/utils.js @@ -16,7 +16,6 @@ const { getFieldValueFromMessage, isDefinedAndNotNullAndNotEmpty, isDefinedAndNotNull, - getAuthErrCategoryFromStCode, getAccessToken, getIntegrationsObj, } = require('../../util'); @@ -34,7 +33,7 @@ const { const { processAxiosResponse } = require('../../../adapters/utils/networkUtils'); const Cache = require('../../util/cache'); const helper = require('./helper'); -const { finaliseConsent } = require('../../util/googleUtils'); +const { finaliseConsent, getAuthErrCategory } = require('../../util/googleUtils'); const conversionActionIdCache = new Cache(CONVERSION_ACTION_ID_CACHE_TTL); @@ -86,7 +85,7 @@ const getConversionActionId = async ({ headers, params, metadata }) => { )} during google_ads_offline_conversions response transformation`, status, response, - getAuthErrCategoryFromStCode(get(searchStreamResponse, 'status')), + getAuthErrCategory(searchStreamResponse), ); } const conversionAction = get( diff --git a/test/integrations/destinations/google_adwords_offline_conversions/dataDelivery/oauth.ts b/test/integrations/destinations/google_adwords_offline_conversions/dataDelivery/oauth.ts index 73fd7c961d2..b8e4c78e1d0 100644 --- a/test/integrations/destinations/google_adwords_offline_conversions/dataDelivery/oauth.ts +++ b/test/integrations/destinations/google_adwords_offline_conversions/dataDelivery/oauth.ts @@ -332,4 +332,76 @@ export const v1oauthScenarios = [ }, }, }, + { + id: 'gaoc_v1_oauth_scenario_4', + name: 'google_adwords_offline_conversions', + description: + "[Proxy v1 API] :: Oauth when the user doesn't enabled 2 factor authentication but the google ads account has it enabled for not store sales conversion", + successCriteria: 'The proxy should return 401 with authErrorCategory as AUTH_STATUS_INACTIVE', + scenario: 'Oauth', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + ...{ ...commonRequestParameters, JSON: { isStoreConversion: false } }, + headers: { + Authorization: 'Bearer invalidabcd1234', + 'Content-Type': 'application/json', + 'developer-token': 'ijkl91011', + 'login-customer-id': 'logincustomerid', + }, + endpoint: + 'https://googleads.googleapis.com/v16/customers/customerid/offlineUserDataJobs', + }, + metadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 401, + body: { + output: { + authErrorCategory: 'AUTH_STATUS_INACTIVE', + message: + '[Google Ads Offline Conversions]:: {"error":{"code":401,"details":[{"@type":"type.googleapis.com/google.ads.googleads.v16.errors.GoogleAdsFailure","errors":[{"errorCode":{"authenticationError":"TWO_STEP_VERIFICATION_NOT_ENROLLED"},"message":"An account administrator changed this account\'s authentication settings. To access this Google Ads account, enable 2-Step Verification in your Google account at https://www.google.com/landing/2step."}],"requestId":"wy4ZYbsjWcgh6uC2Ruc_Zg"}],"message":"Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":"UNAUTHENTICATED"}} during google_ads_offline_conversions response transformation', + response: [ + { + error: + '[Google Ads Offline Conversions]:: {"error":{"code":401,"details":[{"@type":"type.googleapis.com/google.ads.googleads.v16.errors.GoogleAdsFailure","errors":[{"errorCode":{"authenticationError":"TWO_STEP_VERIFICATION_NOT_ENROLLED"},"message":"An account administrator changed this account\'s authentication settings. To access this Google Ads account, enable 2-Step Verification in your Google account at https://www.google.com/landing/2step."}],"requestId":"wy4ZYbsjWcgh6uC2Ruc_Zg"}],"message":"Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.","status":"UNAUTHENTICATED"}} during google_ads_offline_conversions response transformation', + metadata: { + attemptNum: 1, + destinationId: 'default-destinationId', + dontBatch: false, + jobId: 1, + secret: { + accessToken: 'default-accessToken', + }, + sourceId: 'default-sourceId', + userId: 'default-userId', + workspaceId: 'default-workspaceId', + }, + statusCode: 401, + }, + ], + statTags: { + destType: 'GOOGLE_ADWORDS_OFFLINE_CONVERSIONS', + destinationId: 'default-destinationId', + errorCategory: 'network', + errorType: 'aborted', + feature: 'dataDelivery', + implementation: 'native', + module: 'destination', + workspaceId: 'default-workspaceId', + }, + status: 401, + }, + }, + }, + }, + }, ]; diff --git a/test/integrations/destinations/google_adwords_offline_conversions/network.ts b/test/integrations/destinations/google_adwords_offline_conversions/network.ts index 49f89cec28a..f1147162d2a 100644 --- a/test/integrations/destinations/google_adwords_offline_conversions/network.ts +++ b/test/integrations/destinations/google_adwords_offline_conversions/network.ts @@ -1,3 +1,30 @@ +const commonResponse = { + status: 401, + data: { + error: { + code: 401, + details: [ + { + '@type': 'type.googleapis.com/google.ads.googleads.v16.errors.GoogleAdsFailure', + errors: [ + { + errorCode: { + authenticationError: 'TWO_STEP_VERIFICATION_NOT_ENROLLED', + }, + message: + "An account administrator changed this account's authentication settings. To access this Google Ads account, enable 2-Step Verification in your Google account at https://www.google.com/landing/2step.", + }, + ], + requestId: 'wy4ZYbsjWcgh6uC2Ruc_Zg', + }, + ], + message: + 'Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.', + status: 'UNAUTHENTICATED', + }, + }, +}; + export const networkCallsData = [ { httpReq: { @@ -647,7 +674,7 @@ export const networkCallsData = [ }, { description: - 'Mock response from destination depicting a request with invalid authentication credentials', + 'Mock response from destination depicting a request from user who has not enabled 2 factor authentication', httpReq: { url: 'https://googleads.googleapis.com/v16/customers/customerid/offlineUserDataJobs:create', data: { @@ -669,31 +696,25 @@ export const networkCallsData = [ }, method: 'POST', }, - httpRes: { - status: 401, + httpRes: commonResponse, + }, + { + description: + 'Mock response from destination depicting a request from user who has not enabled 2 factor authentication', + httpReq: { + url: 'https://googleads.googleapis.com/v16/customers/1112223333/googleAds:searchStream', data: { - error: { - code: 401, - details: [ - { - '@type': 'type.googleapis.com/google.ads.googleads.v16.errors.GoogleAdsFailure', - errors: [ - { - errorCode: { - authenticationError: 'TWO_STEP_VERIFICATION_NOT_ENROLLED', - }, - message: - "An account administrator changed this account's authentication settings. To access this Google Ads account, enable 2-Step Verification in your Google account at https://www.google.com/landing/2step.", - }, - ], - requestId: 'wy4ZYbsjWcgh6uC2Ruc_Zg', - }, - ], - message: - 'Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.', - status: 'UNAUTHENTICATED', - }, + query: + "SELECT conversion_action.id FROM conversion_action WHERE conversion_action.name = 'Sign-up - click'", + }, + headers: { + Authorization: 'Bearer invalidabcd1234', + 'Content-Type': 'application/json', + 'developer-token': 'ijkl91011', + 'login-customer-id': 'logincustomerid', }, + method: 'POST', }, + httpRes: commonResponse, }, ];