diff --git a/test/integrations/destinations/ga4/dataDelivery/business.ts b/test/integrations/destinations/ga4/dataDelivery/business.ts new file mode 100644 index 0000000000..80271abbdb --- /dev/null +++ b/test/integrations/destinations/ga4/dataDelivery/business.ts @@ -0,0 +1,350 @@ +import { ProxyV1TestData } from '../../../testTypes'; +import { + generateMetadata, + generateProxyV0Payload, + generateProxyV1Payload, +} from '../../../testUtils'; +import { JSON_MIME_TYPE } from '../../../../../src/v0/util/constant'; + +const headers = { + HOST: 'www.google-analytics.com', + 'Content-Type': JSON_MIME_TYPE, +}; + +const params = { + api_secret: 'dymmyApiSecret', +}; + +const validRequest = { + events: [ + { + name: 'sign_up', + params: { + method: 'google', + engagement_time_msec: 1, + }, + }, + ], + user_id: 'dummyUserId', + client_id: 'dummyClientId', + non_personalized_ads: true, +}; + +const invalidEventNameRequest = { + events: [ + { + name: 'campaign@details', + params: { + term: 'summer+travel', + medium: 'cpc', + source: 'google', + content: 'logo link', + campaign: 'Summer_fun', + campaign_id: 'google_1234', + engagement_time_msec: 1, + }, + }, + ], + user_id: 'dummyUserId', + client_id: 'dummyClientId', + non_personalized_ads: true, +}; + +const invalidParameterValueRequest = { + events: [ + { + name: 'add_to_cart', + params: { + currency: 'USD', + value: 7.77, + engagement_time_msec: 1, + items: [ + { + item_id: '507f1f77bcf86cd799439011', + item_name: 'Monopoly: 3rd Edition', + coupon: 'SUMMER_FUN', + item_category: 'Apparel', + item_brand: 'Google', + item_variant: 'green', + price: '$19', + quantity: 2, + affiliation: 'Google Merchandise Store', + currency: 'USD', + item_list_id: 'related_products', + item_list_name: 'Related Products', + location_id: 'L_12345', + }, + ], + }, + }, + ], + user_id: 'dummyUserId', + client_id: 'dummyClientId', + non_personalized_ads: true, +}; + +const invalidParamMessage = + 'Validation of item.price should prevent conversion from unsupported value [string_value: "$19"]'; +const invalidParameterErrorMessage = `Validation Server Response Handler:: Validation Error for ga4 of field path :undefined | INTERNAL_ERROR-${invalidParamMessage}`; +const invalidEventNameErrorMessage = + 'Validation Server Response Handler:: Validation Error for ga4 of field path :events | NAME_INVALID-Event at index: [0] has invalid name [campaign@details]. Only alphanumeric characters and underscores are allowed.'; + +const metadataArray = [generateMetadata(1)]; + +const expectedStatTags = { + destType: 'GA4', + destinationId: 'default-destinationId', + errorCategory: 'network', + errorType: 'aborted', + feature: 'dataDelivery', + implementation: 'native', + module: 'destination', + workspaceId: 'default-workspaceId', +}; + +export const testScenariosForV0API = [ + { + id: 'ga4_v0_scenario_1', + name: 'ga4', + description: + '[Proxy v0 API] :: Test for a valid request - where the destination responds with 200 without any error', + successCriteria: 'Should return 200 with no error with destination response', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v0', + input: { + request: { + body: generateProxyV0Payload({ + headers, + params, + JSON: validRequest, + endpoint: 'https://www.google-analytics.com/debug/mp/collect', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + destinationResponse: { + response: { + validationMessages: [], + }, + status: 200, + }, + message: '[GA4 Response Handler] - Request Processed Successfully', + status: 200, + }, + }, + }, + }, + }, + { + id: 'ga4_v0_scenario_2', + name: 'ga4', + description: + '[Proxy v0 API] :: Test for a invalid event name - where the destination responds with 200 with error for invalid event name', + successCriteria: 'Should return 400 with error and destination response', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v0', + input: { + request: { + body: generateProxyV0Payload({ + headers, + params, + JSON: invalidEventNameRequest, + endpoint: 'https://www.google-analytics.com/debug/mp/collect', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 400, + body: { + output: { + destinationResponse: + 'Event at index: [0] has invalid name [campaign@details]. Only alphanumeric characters and underscores are allowed.', + message: invalidEventNameErrorMessage, + statTags: expectedStatTags, + status: 400, + }, + }, + }, + }, + }, + { + id: 'ga4_v0_scenario_3', + name: 'ga4', + description: + '[Proxy v0 API] :: Test for a invalid parameter value - where the destination responds with 200 with error for invalid parameter value', + successCriteria: 'Should return 400 with error and destination response', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v0', + input: { + request: { + body: generateProxyV0Payload({ + headers, + params, + JSON: invalidParameterValueRequest, + endpoint: 'https://www.google-analytics.com/debug/mp/collect', + }), + method: 'POST', + }, + }, + output: { + response: { + status: 400, + body: { + output: { + destinationResponse: invalidParamMessage, + message: invalidParameterErrorMessage, + statTags: expectedStatTags, + status: 400, + }, + }, + }, + }, + }, +]; + +export const testScenariosForV1API: ProxyV1TestData[] = [ + { + id: 'ga4_v1_scenario_1', + name: 'ga4', + description: + '[Proxy v1 API] :: Test for a valid request - where the destination responds with 200 without any error', + successCriteria: 'Should return 200 with no error with destination response', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + headers, + params, + JSON: validRequest, + endpoint: 'https://www.google-analytics.com/debug/mp/collect', + }, + metadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + message: '[GA4 Response Handler] - Request Processed Successfully', + response: [ + { + error: '{"validationMessages":[]}', + metadata: generateMetadata(1), + statusCode: 200, + }, + ], + status: 200, + }, + }, + }, + }, + }, + { + id: 'ga4_v1_scenario_2', + name: 'ga4', + description: + '[Proxy v1 API] :: Test for a invalid event name - where the destination responds with 200 with error for invalid event name', + successCriteria: 'Should return 400 with error and destination response', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + headers, + params, + JSON: invalidEventNameRequest, + endpoint: 'https://www.google-analytics.com/debug/mp/collect', + }, + metadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + message: invalidEventNameErrorMessage, + response: [ + { + error: invalidEventNameErrorMessage, + metadata: generateMetadata(1), + statusCode: 400, + }, + ], + statTags: expectedStatTags, + status: 400, + }, + }, + }, + }, + }, + { + id: 'ga4_v1_scenario_3', + name: 'ga4', + description: + '[Proxy v1 API] :: Test for a invalid parameter value - where the destination responds with 200 with error for invalid parameter value', + successCriteria: 'Should return 200 with error with destination response', + scenario: 'Business', + feature: 'dataDelivery', + module: 'destination', + version: 'v1', + input: { + request: { + body: generateProxyV1Payload( + { + headers, + params, + JSON: invalidParameterValueRequest, + endpoint: 'https://www.google-analytics.com/debug/mp/collect', + }, + metadataArray, + ), + method: 'POST', + }, + }, + output: { + response: { + status: 200, + body: { + output: { + message: invalidParameterErrorMessage, + response: [ + { + error: invalidParameterErrorMessage, + metadata: generateMetadata(1), + statusCode: 400, + }, + ], + statTags: expectedStatTags, + status: 400, + }, + }, + }, + }, + }, +]; diff --git a/test/integrations/destinations/ga4/dataDelivery/data.ts b/test/integrations/destinations/ga4/dataDelivery/data.ts index 9ccf35e2a1..51827a38e2 100644 --- a/test/integrations/destinations/ga4/dataDelivery/data.ts +++ b/test/integrations/destinations/ga4/dataDelivery/data.ts @@ -1,177 +1,3 @@ -export const data = [ - { - name: 'ga4', - description: 'Successful data delivery', - feature: 'dataDelivery', - module: 'destination', - version: 'v0', - input: { - request: { - body: { - version: '1', - type: 'REST', - method: 'POST', - endpoint: 'https://www.google-analytics.com/mp/collect', - headers: { - HOST: 'www.google-analytics.com', - 'Content-Type': 'application/json', - }, - params: { - api_secret: 'dummyApiSecret', - measurement_id: 'dummyMeasurementId', - }, - body: { - JSON: { - client_id: 'ec5481b6-a926-4d2e-b293-0b3a77c4d3be', - timestamp_micros: 1650950229000000, - non_personalized_ads: true, - events: [ - { - name: 'view_item_list', - params: { - item_list_id: 'related_products', - item_list_name: 'Related_products', - items: [ - { - item_id: '507f1f77bcf86cd799439011', - item_name: 'Monopoly: 3rd Edition', - coupon: 'SUMMER_FUN', - item_category: 'Apparel', - item_brand: 'Google', - item_variant: 'green', - price: 19, - quantity: 2, - index: 1, - affiliation: 'Google Merchandise Store', - currency: 'USD', - discount: 2.22, - item_category2: 'Adult', - item_category3: 'Shirts', - item_category4: 'Crew', - item_category5: 'Short sleeve', - item_list_id: 'related_products', - item_list_name: 'Related Products', - location_id: 'L_12345', - }, - ], - engagement_time_msec: 1, - }, - }, - ], - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - userId: '', - }, - }, - }, - output: { - response: { - status: 200, - body: { - output: { - destinationResponse: { - response: { - validationMessages: [], - }, - status: 200, - }, - message: '[GA4 Response Handler] - Request Processed Successfully', - status: 200, - }, - }, - }, - }, - }, - { - name: 'ga4', - description: 'Data delivery failure', - feature: 'dataDelivery', - module: 'destination', - version: 'v0', - input: { - request: { - body: { - version: '1', - type: 'REST', - method: 'POST', - endpoint: 'https://www.google-analytics.com/debug/mp/collect', - headers: { - HOST: 'www.google-analytics.com', - 'Content-Type': 'application/json', - }, - params: { - api_secret: 'dummyApiSecret', - measurement_id: 'dummyMeasurementId', - }, - body: { - JSON: { - client_id: 'ec5481b6-a926-4d2e-b293-0b3a77c4d3be', - timestamp_micros: 1650950229000000, - non_personalized_ads: true, - events: [ - { - name: 'view_item', - params: { - category: 'Electronics', - productID: 'ABC123', - productName: 'Example Product', - customer_name: 'Sample User', - link_imageURL: 'https://example.com/images/product.jpg', - customer_email: 'testrudder@gmail.com', - link_productURL: 'https://example.com/products/ABC123', - stockAvailability: true, - details_features_0: 'wireless charging', - details_features_1: 'water-resistant', - engagement_time_msec: 1, - transaction_currency: 'USD', - customer_loyaltyPoints: 500, - transaction_totalAmount: 150.99, - transaction_discountApplied: 20.5, - details_specifications_color: 'blue', - details_specifications_specifications_specifications_specifications_color: - 'blue', - details_specifications_specifications_specifications_specifications_weight: - '1.5kg', - }, - }, - ], - }, - JSON_ARRAY: {}, - XML: {}, - FORM: {}, - }, - files: {}, - userId: '', - }, - }, - }, - output: { - response: { - status: 400, - body: { - output: { - destinationResponse: - 'The event param [string_value: "1.5kg"] has a duplicate name [details_specifications_specifications_specifications_specifications_weight].', - message: - 'Validation Server Response Handler:: Validation Error for ga4 of field path :events.params | NAME_DUPLICATED-The event param [string_value: "1.5kg"] has a duplicate name [details_specifications_specifications_specifications_specifications_weight].', - statTags: { - destType: 'GA4', - destinationId: 'Non-determininable', - errorCategory: 'network', - errorType: 'aborted', - feature: 'dataDelivery', - implementation: 'native', - module: 'destination', - workspaceId: 'Non-determininable', - }, - status: 400, - }, - }, - }, - }, - }, -]; +import { testScenariosForV0API, testScenariosForV1API } from './business'; + +export const data = [...testScenariosForV0API, ...testScenariosForV1API]; diff --git a/test/integrations/destinations/ga4/network.ts b/test/integrations/destinations/ga4/network.ts index e8c91ef451..b5c8dc8e8e 100644 --- a/test/integrations/destinations/ga4/network.ts +++ b/test/integrations/destinations/ga4/network.ts @@ -1,119 +1,139 @@ -export const networkCallsData = [ +const headers = { + HOST: 'www.google-analytics.com', + 'Content-Type': 'application/json', +}; + +const params = { + api_secret: 'dymmyApiSecret', +}; + +const dataDeliveryMocksData = [ { + description: 'Mock response from destination depicting a valid request', httpReq: { - url: 'https://www.google-analytics.com/mp/collect', - headers: { - HOST: 'www.google-analytics.com', - 'Content-Type': 'application/json', - 'User-Agent': 'RudderLabs', - }, - params: { - api_secret: 'dummyApiSecret', - measurement_id: 'dummyMeasurementId', - }, + method: 'post', + url: 'https://www.google-analytics.com/debug/mp/collect', data: { - client_id: 'ec5481b6-a926-4d2e-b293-0b3a77c4d3be', - timestamp_micros: 1650950229000000, - non_personalized_ads: true, events: [ { - name: 'view_item_list', + name: 'sign_up', params: { - item_list_id: 'related_products', - item_list_name: 'Related_products', - items: [ - { - item_id: '507f1f77bcf86cd799439011', - item_name: 'Monopoly: 3rd Edition', - coupon: 'SUMMER_FUN', - item_category: 'Apparel', - item_brand: 'Google', - item_variant: 'green', - price: 19, - quantity: 2, - index: 1, - affiliation: 'Google Merchandise Store', - currency: 'USD', - discount: 2.22, - item_category2: 'Adult', - item_category3: 'Shirts', - item_category4: 'Crew', - item_category5: 'Short sleeve', - item_list_id: 'related_products', - item_list_name: 'Related Products', - location_id: 'L_12345', - }, - ], + method: 'google', engagement_time_msec: 1, }, }, ], + user_id: 'dummyUserId', + client_id: 'dummyClientId', + non_personalized_ads: true, }, - method: 'POST', + headers, + params, }, httpRes: { data: { validationMessages: [], }, status: 200, + statusText: 'OK', }, }, { + description: 'Mock response from destination depicting a invalid event name request', httpReq: { + method: 'post', url: 'https://www.google-analytics.com/debug/mp/collect', - headers: { - HOST: 'www.google-analytics.com', - 'Content-Type': 'application/json', - 'User-Agent': 'RudderLabs', + data: { + events: [ + { + name: 'campaign@details', + params: { + term: 'summer+travel', + medium: 'cpc', + source: 'google', + content: 'logo link', + campaign: 'Summer_fun', + campaign_id: 'google_1234', + engagement_time_msec: 1, + }, + }, + ], + user_id: 'dummyUserId', + client_id: 'dummyClientId', + non_personalized_ads: true, }, - params: { - api_secret: 'dummyApiSecret', - measurement_id: 'dummyMeasurementId', + headers, + params, + }, + httpRes: { + data: { + validationMessages: [ + { + fieldPath: 'events', + description: + 'Event at index: [0] has invalid name [campaign@details]. Only alphanumeric characters and underscores are allowed.', + validationCode: 'NAME_INVALID', + }, + ], }, + status: 200, + statusText: 'OK', + }, + }, + { + description: 'Mock response from destination depicting a invalid parameter value request', + httpReq: { + method: 'post', + url: 'https://www.google-analytics.com/debug/mp/collect', data: { - client_id: 'ec5481b6-a926-4d2e-b293-0b3a77c4d3be', - timestamp_micros: 1650950229000000, - non_personalized_ads: true, events: [ { - name: 'view_item', + name: 'add_to_cart', params: { - category: 'Electronics', - productID: 'ABC123', - productName: 'Example Product', - customer_name: 'Sample User', - link_imageURL: 'https://example.com/images/product.jpg', - customer_email: 'testrudder@gmail.com', - link_productURL: 'https://example.com/products/ABC123', - stockAvailability: true, - details_features_0: 'wireless charging', - details_features_1: 'water-resistant', + currency: 'USD', + value: 7.77, engagement_time_msec: 1, - transaction_currency: 'USD', - customer_loyaltyPoints: 500, - transaction_totalAmount: 150.99, - transaction_discountApplied: 20.5, - details_specifications_color: 'blue', - details_specifications_specifications_specifications_specifications_color: 'blue', - details_specifications_specifications_specifications_specifications_weight: '1.5kg', + items: [ + { + item_id: '507f1f77bcf86cd799439011', + item_name: 'Monopoly: 3rd Edition', + coupon: 'SUMMER_FUN', + item_category: 'Apparel', + item_brand: 'Google', + item_variant: 'green', + price: '$19', + quantity: 2, + affiliation: 'Google Merchandise Store', + currency: 'USD', + item_list_id: 'related_products', + item_list_name: 'Related Products', + location_id: 'L_12345', + }, + ], }, }, ], + user_id: 'dummyUserId', + client_id: 'dummyClientId', + non_personalized_ads: true, }, - method: 'POST', + headers, + params, }, httpRes: { data: { validationMessages: [ { - fieldPath: 'events.params', description: - 'The event param [string_value: "1.5kg"] has a duplicate name [details_specifications_specifications_specifications_specifications_weight].', - validationCode: 'NAME_DUPLICATED', + 'Validation of item.price should prevent conversion from unsupported value [string_value: "$19"]', + validationCode: 'INTERNAL_ERROR', }, ], }, status: 200, + statusText: 'OK', }, }, ]; + +export const networkCallsData = [...dataDeliveryMocksData];