Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Send ProductName to Braze #174

Merged
merged 3 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/main/kotlin/com/mparticle/kits/AppboyKit.kt
Original file line number Diff line number Diff line change
Expand Up @@ -613,8 +613,18 @@ open class AppboyKit : KitIntegration(), AttributeListener, CommerceListener,
}
}

var sanitizedProductName: String = product.sku
Mansi-mParticle marked this conversation as resolved.
Show resolved Hide resolved
try {
if (settings[FORWARD_SKU_AS_PRODUCT_NAME] == "True") {
sanitizedProductName = product.name
einsteinx2 marked this conversation as resolved.
Show resolved Hide resolved
}
} 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(),
Expand Down Expand Up @@ -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
Expand Down
77 changes: 74 additions & 3 deletions src/test/kotlin/com/mparticle/kits/AppboyKitTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -1290,4 +1290,75 @@ class AppboyKitTests {
TestCase.assertEquals(0, currentUser.getCustomUserAttribute().size)

}

@Test
fun testPurchase_Forward_product_name() {
var settings = HashMap<String, String?>()
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<String, String?>()
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<String, String?>()
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])
}
}
Loading