From 27e4785749898b166637f4dcd7e6b457a8f51628 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Tue, 12 Nov 2024 16:24:41 -0500 Subject: [PATCH 1/3] feat: Send ProductName to Braze --- .../kotlin/com/mparticle/kits/AppboyKit.kt | 13 +++- .../com/mparticle/kits/AppboyKitTest.kt | 77 ++++++++++++++++++- 2 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt index 5816b7b..d199afe 100644 --- a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt @@ -613,8 +613,18 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, } } + var sanitizedProductName: String = product.sku + try { + if (settings[FORWARD_SKU_AS_PRODUCT_NAME] == "True") { + sanitizedProductName = product.name + } + } catch (e: Exception) { + Logger.error(e, "The Braze kit threw an exception while searching for forward sku as product name flag.") + + } + Braze.Companion.getInstance(context).logPurchase( - product.sku, + sanitizedProductName, currencyValue, BigDecimal(product.unitPrice), product.quantity.toInt(), @@ -1076,6 +1086,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, const val HOST = "host" const val PUSH_ENABLED = "push_enabled" const val NAME = "Appboy" + const val FORWARD_SKU_AS_PRODUCT_NAME = "forwardSkuAsProductName" private const val PREF_KEY_HAS_SYNCED_ATTRIBUTES = "appboy::has_synced_attributes" private const val PREF_KEY_CURRENT_EMAIL = "appboy::current_email" private const val FLUSH_DELAY = 5000 diff --git a/src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt b/src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt index 75a7cd9..769d0d8 100644 --- a/src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt +++ b/src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt @@ -964,7 +964,7 @@ class AppboyKitTests { eaaObject.put("eaa", mapValue) jsonObject.put("hs", eaaObject) - Mockito.`when`(mTypeFilters!!.size()).thenReturn(0) + Mockito.`when`(mTypeFilters!!.size()).thenReturn(0) var kitConfiguration = MockKitConfiguration.createKitConfiguration(jsonObject) kit.configuration = kitConfiguration @@ -1002,7 +1002,7 @@ class AppboyKitTests { eaaObject.put("ear", mapValue) jsonObject.put("hs", eaaObject) - Mockito.`when`(mTypeFilters!!.size()).thenReturn(0) + Mockito.`when`(mTypeFilters!!.size()).thenReturn(0) var kitConfiguration = MockKitConfiguration.createKitConfiguration(jsonObject) kit.configuration = kitConfiguration @@ -1033,7 +1033,7 @@ class AppboyKitTests { eaaObject.put("eas", mapValue) jsonObject.put("hs", eaaObject) - Mockito.`when`(mTypeFilters!!.size()).thenReturn(0) + Mockito.`when`(mTypeFilters!!.size()).thenReturn(0) var kitConfiguration = MockKitConfiguration.createKitConfiguration(jsonObject) kit.configuration = kitConfiguration @@ -1290,4 +1290,75 @@ class AppboyKitTests { TestCase.assertEquals(0, currentUser.getCustomUserAttribute().size) } + + @Test + fun testPurchase_Forward_product_name() { + var settings = HashMap() + settings[AppboyKit.APPBOY_KEY] = "key" + settings[AppboyKit.FORWARD_SKU_AS_PRODUCT_NAME] = "True" + val kit = MockAppboyKit() + + kit.configuration = + KitConfiguration.createKitConfiguration(JSONObject().put("as", settings)) + kit.onKitCreate(settings, MockContextApplication()) + val product = Product.Builder("product name", "sku1", 4.5) + .build() + val commerceEvent = CommerceEvent.Builder(Product.CHECKOUT, product) + .currency("Moon Dollars") + .build() + kit.logTransaction(commerceEvent, product) + val braze = Braze + val purchases = braze.purchases + Assert.assertEquals(1, purchases.size.toLong()) + val purchase = purchases[0] + Assert.assertEquals("product name", purchase.sku) + Assert.assertNull(purchase.purchaseProperties.properties[CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE]) + } + + @Test + fun testPurchase_Forward_product_name_When_flag_IS_FALSE() { + var settings = HashMap() + settings[AppboyKit.APPBOY_KEY] = "key" + settings[AppboyKit.FORWARD_SKU_AS_PRODUCT_NAME] = "False" + val kit = MockAppboyKit() + + kit.configuration = + KitConfiguration.createKitConfiguration(JSONObject().put("as", settings)) + kit.onKitCreate(settings, MockContextApplication()) + val product = Product.Builder("product name", "sku1", 4.5) + .build() + val commerceEvent = CommerceEvent.Builder(Product.CHECKOUT, product) + .currency("Moon Dollars") + .build() + kit.logTransaction(commerceEvent, product) + val braze = Braze + val purchases = braze.purchases + Assert.assertEquals(1, purchases.size.toLong()) + val purchase = purchases[0] + Assert.assertEquals("sku1", purchase.sku) + Assert.assertNull(purchase.purchaseProperties.properties[CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE]) + } + + @Test + fun testPurchase_Forward_product_name_When_flag_IS_Null() { + var settings = HashMap() + settings[AppboyKit.APPBOY_KEY] = "key" + val kit = MockAppboyKit() + + kit.configuration = + KitConfiguration.createKitConfiguration(JSONObject().put("as", settings)) + kit.onKitCreate(settings, MockContextApplication()) + val product = Product.Builder("product name", "sku1", 4.5) + .build() + val commerceEvent = CommerceEvent.Builder(Product.CHECKOUT, product) + .currency("Moon Dollars") + .build() + kit.logTransaction(commerceEvent, product) + val braze = Braze + val purchases = braze.purchases + Assert.assertEquals(1, purchases.size.toLong()) + val purchase = purchases[0] + Assert.assertEquals("sku1", purchase.sku) + Assert.assertNull(purchase.purchaseProperties.properties[CommerceEventUtils.Constants.ATT_ACTION_CURRENCY_CODE]) + } } From fa5e99337cc055568f25ed6ed77b764f76724ef0 Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Wed, 13 Nov 2024 13:38:50 -0500 Subject: [PATCH 2/3] Address review comments --- src/main/kotlin/com/mparticle/kits/AppboyKit.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt index d199afe..793c6f4 100644 --- a/src/main/kotlin/com/mparticle/kits/AppboyKit.kt +++ b/src/main/kotlin/com/mparticle/kits/AppboyKit.kt @@ -615,7 +615,7 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, var sanitizedProductName: String = product.sku try { - if (settings[FORWARD_SKU_AS_PRODUCT_NAME] == "True") { + if (settings[REPLACE_SKU_AS_PRODUCT_NAME] == "True") { sanitizedProductName = product.name } } catch (e: Exception) { @@ -1086,7 +1086,8 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener, const val HOST = "host" const val PUSH_ENABLED = "push_enabled" const val NAME = "Appboy" - const val FORWARD_SKU_AS_PRODUCT_NAME = "forwardSkuAsProductName" + // if this flag is true, kit will send Product name as sku + const val REPLACE_SKU_AS_PRODUCT_NAME = "forwardSkuAsProductName" private const val PREF_KEY_HAS_SYNCED_ATTRIBUTES = "appboy::has_synced_attributes" private const val PREF_KEY_CURRENT_EMAIL = "appboy::current_email" private const val FLUSH_DELAY = 5000 From 3a7347b3a8977304dcfd823a8c2ccecf7951aa1c Mon Sep 17 00:00:00 2001 From: Mansi Pandya Date: Wed, 13 Nov 2024 13:45:05 -0500 Subject: [PATCH 3/3] Update the test case --- src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt b/src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt index 769d0d8..e409aad 100644 --- a/src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt +++ b/src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt @@ -1295,7 +1295,7 @@ class AppboyKitTests { fun testPurchase_Forward_product_name() { var settings = HashMap() settings[AppboyKit.APPBOY_KEY] = "key" - settings[AppboyKit.FORWARD_SKU_AS_PRODUCT_NAME] = "True" + settings[AppboyKit.REPLACE_SKU_AS_PRODUCT_NAME] = "True" val kit = MockAppboyKit() kit.configuration = @@ -1319,7 +1319,7 @@ class AppboyKitTests { fun testPurchase_Forward_product_name_When_flag_IS_FALSE() { var settings = HashMap() settings[AppboyKit.APPBOY_KEY] = "key" - settings[AppboyKit.FORWARD_SKU_AS_PRODUCT_NAME] = "False" + settings[AppboyKit.REPLACE_SKU_AS_PRODUCT_NAME] = "False" val kit = MockAppboyKit() kit.configuration =