Created
October 19, 2023 16:43
-
-
Save jordanbeck/8bf43fe7b0b2935415b0fd91ae5248ca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- a/Etsy/src/main/java/com/etsy/android/ui/cart/refactor/handlers/fetch/comboendpoint/ComboEndpointHandler.kt | |
| +++ b/Etsy/src/main/java/com/etsy/android/ui/cart/refactor/handlers/fetch/comboendpoint/ComboEndpointHandler.kt | |
| @@ -5,6 +5,9 @@ import com.etsy.android.lib.logger.elk.grafana.Grafana | |
| import com.etsy.android.lib.logger.logcat | |
| 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.CartLinkResponse | |
| +import com.etsy.android.ui.cart.refactor.models.network.CartShopCouponLinksResponse | |
| +import com.etsy.android.ui.cart.refactor.models.network.CartLinkResponse | |
| +import com.etsy.android.ui.cart.refactor.models.network.CartShopCouponLinksResponse | |
| +import com.etsy.android.ui.cart.refactor.models.network.CartShopCouponResponse | |
| import kotlinx.coroutines.CoroutineDispatcher | |
| import kotlinx.coroutines.withContext | |
| import javax.inject.Inject | |
| @@ -24,7 +27,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 +55,66 @@ 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 = false, | |
| + links = CartShopCouponLinksResponse( | |
| + applyCoupon = CartLinkResponse( | |
| + method = "PUT", | |
| + href = "/etsyapps/v3/bespoke/member/non-sdl/carts/{cart_id}/apply-shop-promotion?release_name=p1\"", | |
| + auth = false, | |
| + ) | |
| + ) | |
| + ), | |
| + CartShopCouponResponse( | |
| + snudgeType = "coupon_signals_plain", | |
| + discount = "10% off", | |
| + text = "with code TENOFF", | |
| + body = "Applies to eligible items", | |
| + signalName = "cart_eligible_coupon", | |
| + analyticsId = "", | |
| + applied = true, | |
| + amount = "-$3.99", | |
| + links = CartShopCouponLinksResponse( | |
| + delete = CartLinkResponse( | |
| + method = "POST", | |
| + href = "/etsyapps/v3/bespoke/member/carts/8576620927,8483501078,8532386225,8488225634,8488215722,8526919693,8459816928,8503845039,8499518439,8499125973,8437912996,8467563935,8329860630/delete-coupon/8488225634/0", | |
| + auth = false, | |
| + isNonSdlResponse = false, | |
| + ) | |
| + ) | |
| + ) | |
| + ) | |
| + ) ?: 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) | |
| + } | |
| + ) | |
| + ) | |
| + ) | |
| + } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment