From 2d403c9e4a08a3af478da3d2840efdf80dc39b23 Mon Sep 17 00:00:00 2001 From: Utsab Chowdhury Date: Wed, 29 Nov 2023 18:02:42 +0530 Subject: [PATCH] fix: add support for custom properties for braze purchase events --- src/v0/destinations/braze/braze.util.test.js | 71 ++++++++++++++++++++ src/v0/destinations/braze/util.js | 4 ++ test/__tests__/data/braze_output.json | 26 +++++++ 3 files changed, 101 insertions(+) diff --git a/src/v0/destinations/braze/braze.util.test.js b/src/v0/destinations/braze/braze.util.test.js index eb5a46fe34..30eeef78df 100644 --- a/src/v0/destinations/braze/braze.util.test.js +++ b/src/v0/destinations/braze/braze.util.test.js @@ -1219,4 +1219,75 @@ describe('getPurchaseObjs', () => { ); } }); + + test('products having extra properties', () => { + const output = getPurchaseObjs({ + properties: { + products: [ + { product_id: '123', price: 10.99, quantity: 2, random_extra_property_a: 'abc' }, + { product_id: '456', price: 5.49, quantity: 1, random_extra_property_b: 'efg' }, + { + product_id: '789', + price: 15.49, + quantity: 1, + random_extra_property_a: 'abc', + random_extra_property_b: 'efg', + random_extra_property_c: 'hij', + }, + ], + currency: 'USD', + }, + timestamp: '2023-08-04T12:34:56Z', + anonymousId: 'abc', + }); + expect(output).toEqual([ + { + product_id: '123', + price: 10.99, + currency: 'USD', + quantity: 2, + time: '2023-08-04T12:34:56Z', + properties: { + random_extra_property_a: 'abc', + }, + _update_existing_only: false, + user_alias: { + alias_name: 'abc', + alias_label: 'rudder_id', + }, + }, + { + product_id: '456', + price: 5.49, + currency: 'USD', + quantity: 1, + time: '2023-08-04T12:34:56Z', + properties: { + random_extra_property_b: 'efg', + }, + _update_existing_only: false, + user_alias: { + alias_name: 'abc', + alias_label: 'rudder_id', + }, + }, + { + product_id: '789', + price: 15.49, + currency: 'USD', + quantity: 1, + time: '2023-08-04T12:34:56Z', + properties: { + random_extra_property_a: 'abc', + random_extra_property_b: 'efg', + random_extra_property_c: 'hij', + }, + _update_existing_only: false, + user_alias: { + alias_name: 'abc', + alias_label: 'rudder_id', + }, + }, + ]); + }); }); diff --git a/src/v0/destinations/braze/util.js b/src/v0/destinations/braze/util.js index 9b5d57d6bc..8c20360bb1 100644 --- a/src/v0/destinations/braze/util.js +++ b/src/v0/destinations/braze/util.js @@ -634,6 +634,10 @@ function getPurchaseObjs(message) { parseInt(quantity, 10), timestamp, ); + const extraProperties = _.omit(product, ['product_id', 'sku', 'price', 'quantity', 'currency']); + if (Object.keys(extraProperties).length > 0) { + purchaseObj = { ...purchaseObj, properties: extraProperties }; + } purchaseObj = setExternalIdOrAliasObject(purchaseObj, message); purchaseObjs.push(purchaseObj); }); diff --git a/test/__tests__/data/braze_output.json b/test/__tests__/data/braze_output.json index 10c42b1064..7c7959f78f 100644 --- a/test/__tests__/data/braze_output.json +++ b/test/__tests__/data/braze_output.json @@ -396,6 +396,12 @@ "currency": "USD", "price": 0, "product_id": "507f1f77bcf86cd799439011", + "properties": { + "category": "Games", + "image_url": "https:///www.example.com/product/path.jpg", + "name": "Monopoly: 3rd Edition", + "url": "https://www.example.com/product/path" + }, "quantity": 1, "time": "2020-01-24T11:59:02.402+05:30", "user_alias": { @@ -408,6 +414,10 @@ "currency": "USD", "price": 0, "product_id": "505bd76785ebb509fc183733", + "properties": { + "category": "Games", + "name": "Uno Card Game" + }, "quantity": 2, "time": "2020-01-24T11:59:02.402+05:30", "user_alias": { @@ -457,6 +467,12 @@ "currency": "USD", "price": 0, "product_id": "507f1f77bcf86cd799439011", + "properties": { + "category": "Games", + "image_url": "https:///www.example.com/product/path.jpg", + "name": "Monopoly: 3rd Edition", + "url": "https://www.example.com/product/path" + }, "quantity": 1, "time": "2020-01-24T11:59:02.402+05:30", "user_alias": { @@ -469,6 +485,10 @@ "currency": "USD", "price": 10, "product_id": "505bd76785ebb509fc183733", + "properties": { + "category": "Games", + "name": "Uno Card Game" + }, "quantity": 2, "time": "2020-01-24T11:59:02.402+05:30", "user_alias": { @@ -855,6 +875,12 @@ "purchases": [ { "product_id": "507f1f77bcf86cd799439011", + "properties": { + "category": "Games", + "image_url": "https:///www.example.com/product/path.jpg", + "name": "Monopoly: 3rd Edition", + "url": "https://www.example.com/product/path" + }, "price": 0, "currency": "USD", "quantity": 1,