diff --git a/platforms/android/samples/CheckoutKitAndroidDemo/app/src/main/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepository.kt b/platforms/android/samples/CheckoutKitAndroidDemo/app/src/main/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepository.kt index c14dcb810..d6472a7d9 100644 --- a/platforms/android/samples/CheckoutKitAndroidDemo/app/src/main/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepository.kt +++ b/platforms/android/samples/CheckoutKitAndroidDemo/app/src/main/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepository.kt @@ -8,7 +8,6 @@ import com.shopify.checkoutkit.androiddemo.graphql.type.CartDeliveryInput import com.shopify.checkoutkit.androiddemo.graphql.type.CartInput import com.shopify.checkoutkit.androiddemo.graphql.type.CartLineInput import com.shopify.checkoutkit.androiddemo.graphql.type.CartLineUpdateInput -import com.shopify.checkoutkit.androiddemo.graphql.type.CountryCode import timber.log.Timber class CartRepository( @@ -82,25 +81,31 @@ class CartRepository( ) ) ), - buyerIdentity = Optional.present(buyerIdentity(demoBuyerIdentityEnabled, customerAccessToken)), + buyerIdentity = buyerIdentity(demoBuyerIdentityEnabled, customerAccessToken), delivery = delivery(demoBuyerIdentityEnabled, customerAccessToken), ) + // A guest carries nothing, so the cart takes the market of the shop. A country here + // would pick the market instead, and the market decides the currency, the address + // form and its labels. The Swift and React Native samples send nothing either. private fun buyerIdentity( demoBuyerIdentityEnabled: Boolean, customerAccessToken: String?, - ): CartBuyerIdentityInput { + ): Optional { if (customerAccessToken != null) { Timber.i("Setting a customer access token in buyer identity") - return CartBuyerIdentityInput(customerAccessToken = Optional.present(customerAccessToken)) + return Optional.present( + CartBuyerIdentityInput(customerAccessToken = Optional.present(customerAccessToken)) + ) } - return if (demoBuyerIdentityEnabled) { - Timber.i("Using demo buyer identity data to prefill checkout") - DemoBuyerIdentity.value - } else { - CartBuyerIdentityInput(countryCode = Optional.present(CountryCode.CA)) + if (!demoBuyerIdentityEnabled) { + return Optional.Absent } + + Timber.i("Using demo buyer identity data to prefill checkout") + + return Optional.present(DemoBuyerIdentity.value) } // A signed in customer picks from the addresses the account already holds, so only the diff --git a/platforms/android/samples/CheckoutKitAndroidDemo/app/src/test/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepositoryTest.kt b/platforms/android/samples/CheckoutKitAndroidDemo/app/src/test/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepositoryTest.kt index 4b0645047..ee0eeb82b 100644 --- a/platforms/android/samples/CheckoutKitAndroidDemo/app/src/test/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepositoryTest.kt +++ b/platforms/android/samples/CheckoutKitAndroidDemo/app/src/test/java/com/shopify/checkoutkit/androiddemo/cart/data/CartRepositoryTest.kt @@ -21,6 +21,16 @@ class CartRepositoryTest { assertThat(input.delivery.getOrNull()).isNull() } + // A country on the buyer identity picks the market, and the market decides the currency, + // the address form and the labels the E2E fixture types. The Swift and React Native + // samples send no buyer identity for a guest, so this one must not either. + @Test + fun `a guest supplies no buyer identity`() { + val input = cartInput(demoBuyerIdentityEnabled = false, customerAccessToken = null) + + assertThat(input.buyerIdentity.getOrNull()).isNull() + } + @Test fun `a signed in customer supplies no delivery address`() { val input = cartInput(demoBuyerIdentityEnabled = true, customerAccessToken = "token")