Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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<CartBuyerIdentityInput> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Loading