Skip to content

Instantly share code, notes, and snippets.

@jordanbeck
Created October 11, 2023 21:43
Show Gist options
  • Save jordanbeck/99fca2d8c6e8a87104f220014c3d4a02 to your computer and use it in GitHub Desktop.
Save jordanbeck/99fca2d8c6e8a87104f220014c3d4a02 to your computer and use it in GitHub Desktop.
@@ -5,6 +5,7 @@ import com.etsy.android.lib.logger.elk.grafana.Grafana
import com.etsy.android.lib.logger.logcat
import com.etsy.android.ui.cart.refactor.CartRefactorRepository
import com.etsy.android.ui.cart.refactor.CartRefactorResult
+import com.etsy.android.ui.cart.refactor.models.network.CartShopCouponResponse
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.withContext
import javax.inject.Inject
@@ -24,7 +25,11 @@ class ComboEndpointHandler @Inject constructor(
try {
val result = cartRefactorRepository.fetchCart(apiPath)
when (result) {
- is CartRefactorResult.Success -> incrementMetric(METRIC_LOAD_SUCCESS)
+ is CartRefactorResult.Success -> {
+ incrementMetric(METRIC_LOAD_SUCCESS)
+// // TODO: TESTING CALL. REMOVE BEFORE MERGING!
+// return@withContext injectTestCoupons(result)
+ }
is CartRefactorResult.Failure -> handleError(result.error)
}
result
@@ -48,6 +53,42 @@ class ComboEndpointHandler @Inject constructor(
}
}
+ // TODO: THIS IS A TEST FUNCTION TO ADD COUPONS. REMOVE BEFORE MERGING!
+ private fun injectTestCoupons(result: CartRefactorResult.Success): CartRefactorResult.Success {
+ val cart = result.response.nonSdlResponse?.cartGroups?.first()?.shopCarts?.first()?.copy(
+ coupons = listOf(
+ CartShopCouponResponse(
+ snudgeType = "coupon_signals_plain",
+ discount = "20% off",
+ text = "with code THANKYOU",
+ body = "Applies to eligible items",
+ couponCode = "THANKYOU",
+ signalName = "cart_eligible_coupon",
+ analyticsId = "",
+ applied = true,
+ links = null
+ )
+ )
+ ) ?: throw IllegalStateException("Cart should not be null")
+
+ val cartGroup = result.response.nonSdlResponse.cartGroups.first().copy(
+ // Set first shop cart
+ shopCarts = result.response.nonSdlResponse.cartGroups.first().shopCarts.toMutableList().apply {
+ set(0, cart)
+ }
+ )
+
+ return result.copy(
+ response = result.response.copy(
+ nonSdlResponse = result.response.nonSdlResponse.copy(
+ cartGroups = result.response.nonSdlResponse.cartGroups.toMutableList().apply {
+ set(0, cartGroup)
+ }
+ )
+ )
+ )
+ }
+
companion object {
/**
* 700k hits from Android per day for the cart endpoint, so 2% will get us ~14k hits.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment