From 79f81b436c9a41b0d3cc33fb420a2b2f75b1fe3c Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Wed, 15 Mar 2023 17:27:10 +0530 Subject: [PATCH 1/2] fix(integration): Pinterest content_id field dropped when having null value to match with CDKv2 --- src/v0/destinations/pinterest_tag/utils.js | 13 ++- test/__tests__/data/pinterest_tag_input.json | 83 +++++++++++++++++++ test/__tests__/data/pinterest_tag_output.json | 68 ++++++++++++++- 3 files changed, 159 insertions(+), 5 deletions(-) diff --git a/src/v0/destinations/pinterest_tag/utils.js b/src/v0/destinations/pinterest_tag/utils.js index 28ad27183c..7156b71af4 100644 --- a/src/v0/destinations/pinterest_tag/utils.js +++ b/src/v0/destinations/pinterest_tag/utils.js @@ -6,6 +6,7 @@ const { isDefinedAndNotNull, isDefined, getHashFromArrayWithDuplicate, + removeUndefinedAndNullValues } = require('../../util'); const { InstrumentationError } = require('../../util/errorTypes'); const { COMMON_CONFIGS, CUSTOM_CONFIGS } = require('./config'); @@ -286,7 +287,9 @@ const postProcessEcomFields = (message, mandatoryPayload) => { const { products, quantity } = properties; products.forEach((product) => { const prodParams = setIdPriceQuantity(product, message); - contentIds.push(prodParams.contentId); + if(prodParams.contentId) { + contentIds.push(prodParams.contentId); + } contentArray.push(prodParams.content); if (!product.quantity) { quantityInconsistent = true; @@ -307,7 +310,9 @@ const postProcessEcomFields = (message, mandatoryPayload) => { quantity are taken into consideration */ const prodParams = setIdPriceQuantity(properties, message); - contentIds.push(prodParams.contentId); + if(prodParams.contentId) { + contentIds.push(prodParams.contentId); + } contentArray.push(prodParams.content); totalQuantity = properties.quantity ? totalQuantity + properties.quantity : totalQuantity; } @@ -320,13 +325,13 @@ const postProcessEcomFields = (message, mandatoryPayload) => { } customPayload = { ...customPayload, - content_ids: contentIds, + content_ids: contentIds.length > 0 ? contentIds : null, contents: contentArray, }; return { ...mandatoryPayload, - custom_data: { ...customPayload }, + custom_data: { ...removeUndefinedAndNullValues(customPayload)}, }; }; diff --git a/test/__tests__/data/pinterest_tag_input.json b/test/__tests__/data/pinterest_tag_input.json index c6d88306b5..44b5877391 100644 --- a/test/__tests__/data/pinterest_tag_input.json +++ b/test/__tests__/data/pinterest_tag_input.json @@ -1727,6 +1727,89 @@ "Enabled": true, "Transformations": [] } +}, +{ + "message": { + "type": "track", + "event": "custom event", + "channel": "web", + "sentAt": "2020-08-14T05:30:30.118Z", + "context": { + "source": "test", + "userAgent": "chrome", + "traits": { + "anonymousId": "50be5c78-6c3f-4b60-be84-97805a316fb1", + "email": "abc@gmail.com", + "phone": "+1234589947", + "ge": "male", + "db": "19950715", + "lastname": "Ganguly", + "firstName": "Shrouti", + "address": { + "city": "Kolkata", + "state": "WB", + "zip": "700114", + "country": "IN" + } + }, + "device": { + "advertisingId": "abc123" + }, + "library": { + "name": "rudder-sdk-ruby-sync", + "version": "1.0.6" + } + }, + "messageId": "7208bbb6-2c4e-45bb-bf5b-ad426f3593e9", + "timestamp": "2020-08-14T05:30:30.118Z", + "properties": { + "tax": 2, + "total": 27.5, + "coupon": "hasbros", + "revenue": 48, + "currency": "USD", + "discount": 2.5, + "order_id": "50314b8e9bcf000000000000", + "requestIP": "123.0.0.0", + "shipping": 3, + "subtotal": 22.5, + "affiliation": "Google Store", + "checkout_id": "fksdjfsdjfisjf9sdfjsd9f" + }, + "anonymousId": "50be5c78-6c3f-4b60-be84-97805a316fb1", + "integrations": { + "All": true + } + }, + "destination": { + "ID": "1pYpzzvcn7AQ2W9GGIAZSsN6Mfq", + "Name": "PINTEREST_TAG", + "Config": { + "tagId": "123456789", + "advertiserId": "123456", + "appId": "429047995", + "sendingUnHashedData": true, + "enableDeduplication": true, + "deduplicationKey": "messageId", + "enhancedMatch": true, + "customProperties": [ + { + "properties": "presentclass" + }, + { + "properties": "presentgrade" + } + ], + "eventsMapping": [ + { + "from": "ABC Searched", + "to": "Watch Video" + } + ] + }, + "Enabled": true, + "Transformations": [] + } } ] diff --git a/test/__tests__/data/pinterest_tag_output.json b/test/__tests__/data/pinterest_tag_output.json index 5ceaebba96..525625ee53 100644 --- a/test/__tests__/data/pinterest_tag_output.json +++ b/test/__tests__/data/pinterest_tag_output.json @@ -853,5 +853,71 @@ }, "files": {} } - ] + ], + [{ + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://ct.pinterest.com/events/v3", + "headers": { + "Content-Type": "application/json" + }, + "params": {}, + "body": { + "JSON": { + "event_name": "custom event", + "event_time": 1597383030, + "action_source": "web", + "event_id": "7208bbb6-2c4e-45bb-bf5b-ad426f3593e9", + "app_id": "429047995", + "advertiser_id": "123456", + "user_data": { + "em": [ + "48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08" + ], + "ph": [ + "d164bbe036663cb5c96835e9ccc6501e9a521127ea62f6359744928ba932413b" + ], + "ln": [ + "bdfdee6414a89d72bfbf5ee90b1f85924467bae1e3980d83c2cd348dc31d5819" + ], + "fn": [ + "ee5db3fe0253b651aca3676692e0c59b25909304f5c51d223a02a215d104144b" + ], + "ct": [ + "6689106ca7922c30b2fd2c175c85bc7fc2d52cc4941bdd7bb622c6cdc6284a85" + ], + "st": [ + "3b45022ab36728cdae12e709e945bba267c50ee8a91e6e4388539a8e03a3fdcd" + ], + "zp": [ + "1a4292e00780e18d00e76fde9850aee5344e939ba593333cd5e4b4aa2cd33b0c" + ], + "country": [ + "582967534d0f909d196b97f9e6921342777aea87b46fa52df165389db1fb8ccf" + ], + "hashed_maids": [ + "6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090" + ], + "client_user_agent": "chrome" + }, + "custom_data": { + "currency": "USD", + "value": 27.5, + "order_id": "50314b8e9bcf000000000000", + "num_items": 0, + "contents": [ + { + "quantity": 1, + "item_price": "undefined" + } + ] + } + }, + "JSON_ARRAY": {}, + "XML": {}, + "FORM": {} + }, + "files": {} +}] ] From 28ec6f2b0095f43494ac9085a4c05b14ae30192c Mon Sep 17 00:00:00 2001 From: shrouti1507 Date: Wed, 15 Mar 2023 17:31:39 +0530 Subject: [PATCH 2/2] fix(integration): formatting files --- test/__tests__/data/pinterest_tag_input.json | 148 +++++++++--------- test/__tests__/data/pinterest_tag_output.json | 122 ++++++++------- 2 files changed, 136 insertions(+), 134 deletions(-) diff --git a/test/__tests__/data/pinterest_tag_input.json b/test/__tests__/data/pinterest_tag_input.json index 44b5877391..f84391ef55 100644 --- a/test/__tests__/data/pinterest_tag_input.json +++ b/test/__tests__/data/pinterest_tag_input.json @@ -1730,85 +1730,85 @@ }, { "message": { - "type": "track", - "event": "custom event", - "channel": "web", - "sentAt": "2020-08-14T05:30:30.118Z", - "context": { - "source": "test", - "userAgent": "chrome", - "traits": { - "anonymousId": "50be5c78-6c3f-4b60-be84-97805a316fb1", - "email": "abc@gmail.com", - "phone": "+1234589947", - "ge": "male", - "db": "19950715", - "lastname": "Ganguly", - "firstName": "Shrouti", - "address": { - "city": "Kolkata", - "state": "WB", - "zip": "700114", - "country": "IN" - } - }, - "device": { - "advertisingId": "abc123" - }, - "library": { - "name": "rudder-sdk-ruby-sync", - "version": "1.0.6" - } + "type": "track", + "event": "custom event", + "channel": "web", + "sentAt": "2020-08-14T05:30:30.118Z", + "context": { + "source": "test", + "userAgent": "chrome", + "traits": { + "anonymousId": "50be5c78-6c3f-4b60-be84-97805a316fb1", + "email": "abc@gmail.com", + "phone": "+1234589947", + "ge": "male", + "db": "19950715", + "lastname": "Ganguly", + "firstName": "Shrouti", + "address": { + "city": "Kolkata", + "state": "WB", + "zip": "700114", + "country": "IN" + } }, - "messageId": "7208bbb6-2c4e-45bb-bf5b-ad426f3593e9", - "timestamp": "2020-08-14T05:30:30.118Z", - "properties": { - "tax": 2, - "total": 27.5, - "coupon": "hasbros", - "revenue": 48, - "currency": "USD", - "discount": 2.5, - "order_id": "50314b8e9bcf000000000000", - "requestIP": "123.0.0.0", - "shipping": 3, - "subtotal": 22.5, - "affiliation": "Google Store", - "checkout_id": "fksdjfsdjfisjf9sdfjsd9f" + "device": { + "advertisingId": "abc123" }, - "anonymousId": "50be5c78-6c3f-4b60-be84-97805a316fb1", - "integrations": { - "All": true + "library": { + "name": "rudder-sdk-ruby-sync", + "version": "1.0.6" } + }, + "messageId": "7208bbb6-2c4e-45bb-bf5b-ad426f3593e9", + "timestamp": "2020-08-14T05:30:30.118Z", + "properties": { + "tax": 2, + "total": 27.5, + "coupon": "hasbros", + "revenue": 48, + "currency": "USD", + "discount": 2.5, + "order_id": "50314b8e9bcf000000000000", + "requestIP": "123.0.0.0", + "shipping": 3, + "subtotal": 22.5, + "affiliation": "Google Store", + "checkout_id": "fksdjfsdjfisjf9sdfjsd9f" + }, + "anonymousId": "50be5c78-6c3f-4b60-be84-97805a316fb1", + "integrations": { + "All": true + } }, "destination": { - "ID": "1pYpzzvcn7AQ2W9GGIAZSsN6Mfq", - "Name": "PINTEREST_TAG", - "Config": { - "tagId": "123456789", - "advertiserId": "123456", - "appId": "429047995", - "sendingUnHashedData": true, - "enableDeduplication": true, - "deduplicationKey": "messageId", - "enhancedMatch": true, - "customProperties": [ - { - "properties": "presentclass" - }, - { - "properties": "presentgrade" - } - ], - "eventsMapping": [ - { - "from": "ABC Searched", - "to": "Watch Video" - } - ] - }, - "Enabled": true, - "Transformations": [] + "ID": "1pYpzzvcn7AQ2W9GGIAZSsN6Mfq", + "Name": "PINTEREST_TAG", + "Config": { + "tagId": "123456789", + "advertiserId": "123456", + "appId": "429047995", + "sendingUnHashedData": true, + "enableDeduplication": true, + "deduplicationKey": "messageId", + "enhancedMatch": true, + "customProperties": [ + { + "properties": "presentclass" + }, + { + "properties": "presentgrade" + } + ], + "eventsMapping": [ + { + "from": "ABC Searched", + "to": "Watch Video" + } + ] + }, + "Enabled": true, + "Transformations": [] } } ] diff --git a/test/__tests__/data/pinterest_tag_output.json b/test/__tests__/data/pinterest_tag_output.json index 525625ee53..2d8badf24f 100644 --- a/test/__tests__/data/pinterest_tag_output.json +++ b/test/__tests__/data/pinterest_tag_output.json @@ -854,70 +854,72 @@ "files": {} } ], - [{ - "version": "1", - "type": "REST", - "method": "POST", - "endpoint": "https://ct.pinterest.com/events/v3", - "headers": { + [ + { + "version": "1", + "type": "REST", + "method": "POST", + "endpoint": "https://ct.pinterest.com/events/v3", + "headers": { "Content-Type": "application/json" - }, - "params": {}, - "body": { + }, + "params": {}, + "body": { "JSON": { - "event_name": "custom event", - "event_time": 1597383030, - "action_source": "web", - "event_id": "7208bbb6-2c4e-45bb-bf5b-ad426f3593e9", - "app_id": "429047995", - "advertiser_id": "123456", - "user_data": { - "em": [ - "48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08" - ], - "ph": [ - "d164bbe036663cb5c96835e9ccc6501e9a521127ea62f6359744928ba932413b" - ], - "ln": [ - "bdfdee6414a89d72bfbf5ee90b1f85924467bae1e3980d83c2cd348dc31d5819" - ], - "fn": [ - "ee5db3fe0253b651aca3676692e0c59b25909304f5c51d223a02a215d104144b" - ], - "ct": [ - "6689106ca7922c30b2fd2c175c85bc7fc2d52cc4941bdd7bb622c6cdc6284a85" - ], - "st": [ - "3b45022ab36728cdae12e709e945bba267c50ee8a91e6e4388539a8e03a3fdcd" - ], - "zp": [ - "1a4292e00780e18d00e76fde9850aee5344e939ba593333cd5e4b4aa2cd33b0c" - ], - "country": [ - "582967534d0f909d196b97f9e6921342777aea87b46fa52df165389db1fb8ccf" - ], - "hashed_maids": [ - "6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090" - ], - "client_user_agent": "chrome" - }, - "custom_data": { - "currency": "USD", - "value": 27.5, - "order_id": "50314b8e9bcf000000000000", - "num_items": 0, - "contents": [ - { - "quantity": 1, - "item_price": "undefined" - } - ] - } + "event_name": "custom event", + "event_time": 1597383030, + "action_source": "web", + "event_id": "7208bbb6-2c4e-45bb-bf5b-ad426f3593e9", + "app_id": "429047995", + "advertiser_id": "123456", + "user_data": { + "em": [ + "48ddb93f0b30c475423fe177832912c5bcdce3cc72872f8051627967ef278e08" + ], + "ph": [ + "d164bbe036663cb5c96835e9ccc6501e9a521127ea62f6359744928ba932413b" + ], + "ln": [ + "bdfdee6414a89d72bfbf5ee90b1f85924467bae1e3980d83c2cd348dc31d5819" + ], + "fn": [ + "ee5db3fe0253b651aca3676692e0c59b25909304f5c51d223a02a215d104144b" + ], + "ct": [ + "6689106ca7922c30b2fd2c175c85bc7fc2d52cc4941bdd7bb622c6cdc6284a85" + ], + "st": [ + "3b45022ab36728cdae12e709e945bba267c50ee8a91e6e4388539a8e03a3fdcd" + ], + "zp": [ + "1a4292e00780e18d00e76fde9850aee5344e939ba593333cd5e4b4aa2cd33b0c" + ], + "country": [ + "582967534d0f909d196b97f9e6921342777aea87b46fa52df165389db1fb8ccf" + ], + "hashed_maids": [ + "6ca13d52ca70c883e0f0bb101e425a89e8624de51db2d2392593af6a84118090" + ], + "client_user_agent": "chrome" + }, + "custom_data": { + "currency": "USD", + "value": 27.5, + "order_id": "50314b8e9bcf000000000000", + "num_items": 0, + "contents": [ + { + "quantity": 1, + "item_price": "undefined" + } + ] + } }, "JSON_ARRAY": {}, "XML": {}, "FORM": {} - }, - "files": {} -}] + }, + "files": {} + } + ] ]