From af41ab21aafbca5529cd37d3a13a210add939938 Mon Sep 17 00:00:00 2001 From: Scott Antonac Date: Fri, 4 Aug 2023 16:29:23 +1000 Subject: [PATCH] EIT-3042 - remove assets for EU --- .../kotlin/com/afterpay/android/Afterpay.kt | 2 +- .../android/internal/AfterpayDrawable.kt | 24 ----- .../android/internal/AfterpayInstalment.kt | 17 ++-- .../android/internal/AfterpayString.kt | 87 ------------------- .../com/afterpay/android/internal/Brand.kt | 5 +- .../com/afterpay/android/internal/Locales.kt | 9 -- .../com/afterpay/android/AfterpayEnabled.kt | 26 ++++++ .../android/AfterpayInstalmentLocaleTest.kt | 46 +++++----- .../com/afterpay/android/AfterpayTest.kt | 26 ++++-- 9 files changed, 74 insertions(+), 168 deletions(-) diff --git a/afterpay/src/main/kotlin/com/afterpay/android/Afterpay.kt b/afterpay/src/main/kotlin/com/afterpay/android/Afterpay.kt index 2fd2763a..9d4ab463 100644 --- a/afterpay/src/main/kotlin/com/afterpay/android/Afterpay.kt +++ b/afterpay/src/main/kotlin/com/afterpay/android/Afterpay.kt @@ -47,7 +47,7 @@ object Afterpay { get() = getRegionLanguage(locale, configuration?.consumerLocale ?: Locale.getDefault()) internal val enabled: Boolean - get() = language != null + get() = language != null && configuration?.locale != null internal val strings: AfterpayString get() = AfterpayString.forLocale() diff --git a/afterpay/src/main/kotlin/com/afterpay/android/internal/AfterpayDrawable.kt b/afterpay/src/main/kotlin/com/afterpay/android/internal/AfterpayDrawable.kt index 0597b40b..61dc903b 100644 --- a/afterpay/src/main/kotlin/com/afterpay/android/internal/AfterpayDrawable.kt +++ b/afterpay/src/main/kotlin/com/afterpay/android/internal/AfterpayDrawable.kt @@ -8,10 +8,7 @@ import com.afterpay.android.internal.Locales.EN_CA import com.afterpay.android.internal.Locales.EN_GB import com.afterpay.android.internal.Locales.EN_NZ import com.afterpay.android.internal.Locales.EN_US -import com.afterpay.android.internal.Locales.ES_ES import com.afterpay.android.internal.Locales.FR_CA -import com.afterpay.android.internal.Locales.FR_FR -import com.afterpay.android.internal.Locales.IT_IT private val localeLanguages = mapOf( EN_AU to AfterpayDrawable.EN_AFTERPAY, @@ -20,9 +17,6 @@ private val localeLanguages = mapOf( EN_US to AfterpayDrawable.EN_AFTERPAY, EN_CA to AfterpayDrawable.EN_AFTERPAY, FR_CA to AfterpayDrawable.FR_CA, - FR_FR to AfterpayDrawable.FR, - IT_IT to AfterpayDrawable.IT, - ES_ES to AfterpayDrawable.ES, ) internal enum class AfterpayDrawable( @@ -49,24 +43,6 @@ internal enum class AfterpayDrawable( buttonPayNowForeground = R.drawable.afterpay_button_pay_now_fg_fr_ca, buttonPlaceOrderForeground = R.drawable.afterpay_button_place_order_fg_fr_ca, ), - FR( - buttonBuyNowForeground = R.drawable.clearpay_button_buy_now_fg_fr, - buttonCheckoutForeground = R.drawable.clearpay_button_checkout_fg_fr, - buttonPayNowForeground = R.drawable.clearpay_button_pay_now_fg_fr, - buttonPlaceOrderForeground = R.drawable.clearpay_button_place_order_fg_fr, - ), - IT( - buttonBuyNowForeground = R.drawable.clearpay_button_buy_now_fg_it, - buttonCheckoutForeground = R.drawable.clearpay_button_checkout_fg_it, - buttonPayNowForeground = R.drawable.clearpay_button_pay_now_fg_it, - buttonPlaceOrderForeground = R.drawable.clearpay_button_place_order_fg_it, - ), - ES( - buttonBuyNowForeground = R.drawable.clearpay_button_buy_now_fg_es, - buttonCheckoutForeground = R.drawable.clearpay_button_checkout_fg_es, - buttonPayNowForeground = R.drawable.clearpay_button_pay_now_fg_es, - buttonPlaceOrderForeground = R.drawable.clearpay_button_place_order_fg_es, - ), ; companion object { diff --git a/afterpay/src/main/kotlin/com/afterpay/android/internal/AfterpayInstalment.kt b/afterpay/src/main/kotlin/com/afterpay/android/internal/AfterpayInstalment.kt index ad8162ee..6ac2f723 100644 --- a/afterpay/src/main/kotlin/com/afterpay/android/internal/AfterpayInstalment.kt +++ b/afterpay/src/main/kotlin/com/afterpay/android/internal/AfterpayInstalment.kt @@ -30,6 +30,12 @@ internal sealed class AfterpayInstalment { } val currencyLocale: Locale = when { + currencyLocales.isEmpty() -> { + return NotAvailable( + minimumAmount = null, + maximumAmount = "0" + ) + } currencyLocales.count() == 1 -> currencyLocales.first() currencyLocales.contains(configuration.locale) -> configuration.locale else -> Locales.validSet.first { Currency.getInstance(it) == configuration.currency } @@ -40,7 +46,6 @@ internal sealed class AfterpayInstalment { val usCurrencySymbol = Currency.getInstance(Locales.EN_US).getSymbol(Locales.EN_US) val gbCurrencySymbol = Currency.getInstance(Locales.EN_GB).getSymbol(Locales.EN_GB) - val euCurrencySymbol = Currency.getInstance(Locales.FR_FR).getSymbol(Locales.FR_FR) val currencyFormatter = (NumberFormat.getCurrencyInstance(clientLocale) as DecimalFormat).apply { this.currency = configuration.currency @@ -48,10 +53,6 @@ internal sealed class AfterpayInstalment { if (clientLocale == Locales.EN_US) { currencyFormatter.apply { - when (currencySymbol) { - euCurrencySymbol -> this.applyPattern("#,##0.00¤") - } - decimalFormatSymbols = decimalFormatSymbols.apply { this.currencySymbol = when (configuration.currency) { Currency.getInstance(Locales.EN_AU) -> "A$" @@ -71,7 +72,6 @@ internal sealed class AfterpayInstalment { when (currencySymbol) { usCurrencySymbol -> this.applyPattern("¤#,##0.00 ¤¤") gbCurrencySymbol -> this.applyPattern("¤#,##0.00") - euCurrencySymbol -> this.applyPattern("#,##0.00¤") } } } @@ -93,10 +93,7 @@ internal sealed class AfterpayInstalment { } fun numberOfInstalments(currency: Currency): Int { - return when (currency.currencyCode) { - "EUR" -> 3 - else -> 4 - } + return 4 } } } diff --git a/afterpay/src/main/kotlin/com/afterpay/android/internal/AfterpayString.kt b/afterpay/src/main/kotlin/com/afterpay/android/internal/AfterpayString.kt index cb0f0da4..0cce2e1f 100644 --- a/afterpay/src/main/kotlin/com/afterpay/android/internal/AfterpayString.kt +++ b/afterpay/src/main/kotlin/com/afterpay/android/internal/AfterpayString.kt @@ -6,10 +6,7 @@ import com.afterpay.android.internal.Locales.EN_CA import com.afterpay.android.internal.Locales.EN_GB import com.afterpay.android.internal.Locales.EN_NZ import com.afterpay.android.internal.Locales.EN_US -import com.afterpay.android.internal.Locales.ES_ES import com.afterpay.android.internal.Locales.FR_CA -import com.afterpay.android.internal.Locales.FR_FR -import com.afterpay.android.internal.Locales.IT_IT private val localeLanguages = mapOf( EN_AU to AfterpayString.EN, @@ -18,9 +15,6 @@ private val localeLanguages = mapOf( EN_US to AfterpayString.EN, EN_CA to AfterpayString.EN, FR_CA to AfterpayString.FR_CA, - FR_FR to AfterpayString.FR, - IT_IT to AfterpayString.IT, - ES_ES to AfterpayString.ES, ) internal enum class AfterpayString( @@ -109,87 +103,6 @@ internal enum class AfterpayString( priceBreakdownLinkLearnMore = "En savoir plus", priceBreakdownLinkMoreInfo = "Plus d'infos", ), - FR( - breakdownLimit = "disponible pour les montants entre %1\$s – %2\$s", - breakdownLimitDescription = "%1\$s disponible pour les montants entre %2\$s – %3\$s", - introOrTitle = "Ou", - introOr = "ou", - introInTitle = "En", - introIn = "en", - introPayTitle = "Payez", - introPay = "payez", - introPayInTitle = "Payez en", - introPayIn = "payez en", - introMakeTitle = "Effectuez", - introMake = "effectuez", - noConfigurationDescription = "Ou payer avec %1\$s", - noConfiguration = "ou payer avec", - loadErrorTitle = "Erreur", - loadErrorRetry = "Réessayer", - loadErrorCancel = "Annuler", - loadErrorMessage = "Échec du chargement de la page de paiement 1%\$s", - paymentButtonContentDescription = "Payez maintenant avec %1\$s", - priceBreakdownAvailable = "%1\$s %2\$s paiements %3\$sde %4\$s %5\$s", - priceBreakdownAvailableDescription = "%1\$s %2\$s paiements %3\$sde %4\$s %5\$s%6\$s", - priceBreakdownWith = "avec ", - priceBreakdownInterestFree = "sans frais ", - priceBreakdownLinkLearnMore = "En savoir plus", - priceBreakdownLinkMoreInfo = "Plus d'infos", - ), - IT( - breakdownLimit = "disponibile per importi fra %1\$s – %2\$s", - breakdownLimitDescription = "%1\$s disponibile per importi fra %2\$s – %3\$s", - introOrTitle = "O", - introOr = "o", - introInTitle = "In", - introIn = "in", - introPayTitle = "Paga", - introPay = "paga", - introPayInTitle = "Paga in", - introPayIn = "paga in", - introMakeTitle = "Scegli", - introMake = "scegli", - noConfigurationDescription = "O paga con %1\$s", - noConfiguration = "o paga con", - loadErrorTitle = "Errore", - loadErrorRetry = "Riprovare", - loadErrorCancel = "Annulla", - loadErrorMessage = "Impossibile caricare il cassa di %1\$s", - paymentButtonContentDescription = "Paga ora con %1\$s", - priceBreakdownAvailable = "%1\$s %2\$s rate %3\$sda %4\$s %5\$s", - priceBreakdownAvailableDescription = "%1\$s %2\$s rate %3\$sda %4\$s %5\$s%6\$s", - priceBreakdownWith = "con ", - priceBreakdownInterestFree = "senza interessi ", - priceBreakdownLinkLearnMore = "Scopri di piú", - priceBreakdownLinkMoreInfo = "Maggiori info", - ), - ES( - breakdownLimit = "disponible para importes entre %1\$s – %2\$s", - breakdownLimitDescription = "%1\$s disponible para importes entre %2\$s – %3\$s", - introOrTitle = "O", - introOr = "o", - introInTitle = "En", - introIn = "en", - introPayTitle = "Paga", - introPay = "paga", - introPayInTitle = "Paga en", - introPayIn = "paga en", - introMakeTitle = "Haga", - introMake = "haga", - noConfigurationDescription = "O pagar con %1\$s", - noConfiguration = "o pagar con", - loadErrorTitle = "Error", - loadErrorRetry = "Volver a intentar", - loadErrorCancel = "Cancelar", - loadErrorMessage = "Imposible cargar la página de pago de %1\$s", - paymentButtonContentDescription = "Pagar ahora con %1\$s", - priceBreakdownAvailable = "%1\$s %2\$s pagos %3\$sde %4\$s %5\$s", - priceBreakdownAvailableDescription = "%1\$s %2\$s pagos %3\$sde %4\$s %5\$s%6\$s", - priceBreakdownWith = "con ", - priceBreakdownInterestFree = "sin coste ", - priceBreakdownLinkLearnMore = "Saber más", - priceBreakdownLinkMoreInfo = "Más infos", - ), ; companion object { diff --git a/afterpay/src/main/kotlin/com/afterpay/android/internal/Brand.kt b/afterpay/src/main/kotlin/com/afterpay/android/internal/Brand.kt index a9a5eb2a..745a491d 100644 --- a/afterpay/src/main/kotlin/com/afterpay/android/internal/Brand.kt +++ b/afterpay/src/main/kotlin/com/afterpay/android/internal/Brand.kt @@ -8,15 +8,12 @@ import com.afterpay.android.internal.Locales.EN_CA import com.afterpay.android.internal.Locales.EN_GB import com.afterpay.android.internal.Locales.EN_NZ import com.afterpay.android.internal.Locales.EN_US -import com.afterpay.android.internal.Locales.ES_ES import com.afterpay.android.internal.Locales.FR_CA -import com.afterpay.android.internal.Locales.FR_FR -import com.afterpay.android.internal.Locales.IT_IT import java.util.Locale private val brandLocales = mapOf( setOf(EN_AU, EN_CA, FR_CA, EN_NZ, EN_US) to Brand.AFTERPAY, - setOf(EN_GB, IT_IT, FR_FR, ES_ES) to Brand.CLEARPAY, + setOf(EN_GB) to Brand.CLEARPAY, ) internal enum class Brand( diff --git a/afterpay/src/main/kotlin/com/afterpay/android/internal/Locales.kt b/afterpay/src/main/kotlin/com/afterpay/android/internal/Locales.kt index 11a43c31..910f56dd 100644 --- a/afterpay/src/main/kotlin/com/afterpay/android/internal/Locales.kt +++ b/afterpay/src/main/kotlin/com/afterpay/android/internal/Locales.kt @@ -8,9 +8,6 @@ private val validRegionLanguages = mapOf( Locales.EN_NZ.country to setOf(Locales.EN_NZ), Locales.EN_US.country to setOf(Locales.EN_US), Locales.EN_CA.country to setOf(Locales.EN_CA, Locales.FR_CA), - Locales.FR_FR.country to setOf(Locales.FR_FR, Locales.EN_GB), - Locales.IT_IT.country to setOf(Locales.IT_IT, Locales.EN_GB), - Locales.ES_ES.country to setOf(Locales.ES_ES, Locales.EN_GB), ) internal object Locales { @@ -20,9 +17,6 @@ internal object Locales { val EN_NZ: Locale = Locale("en", "NZ") val EN_GB: Locale = Locale.UK val EN_US: Locale = Locale.US - val IT_IT: Locale = Locale.ITALY - val FR_FR: Locale = Locale.FRANCE - val ES_ES: Locale = Locale("es", "ES") val validSet = setOf( EN_AU, @@ -31,9 +25,6 @@ internal object Locales { EN_GB, EN_NZ, EN_US, - IT_IT, - FR_FR, - ES_ES, ) } diff --git a/afterpay/src/test/kotlin/com/afterpay/android/AfterpayEnabled.kt b/afterpay/src/test/kotlin/com/afterpay/android/AfterpayEnabled.kt index 2f6db53e..bf0f0cfe 100644 --- a/afterpay/src/test/kotlin/com/afterpay/android/AfterpayEnabled.kt +++ b/afterpay/src/test/kotlin/com/afterpay/android/AfterpayEnabled.kt @@ -1,5 +1,6 @@ package com.afterpay.android +import com.afterpay.android.internal.Locales import org.junit.Assert import org.junit.Test import java.util.Locale @@ -7,6 +8,15 @@ import java.util.Locale class AfterpayEnabled { private val environment = AfterpayEnvironment.SANDBOX + private val validMerchantLocales: Array = arrayOf( + Locales.EN_AU, + Locales.EN_CA, + Locales.EN_GB, + Locales.EN_US, + Locales.EN_NZ, + Locales.FR_CA, + ) + @Test fun `Afterpay is enabled for basic config and locale is English`() { Afterpay.setConfiguration( @@ -34,4 +44,20 @@ class AfterpayEnabled { Assert.assertEquals(false, Afterpay.enabled) } + + @Test + fun `Afterpay is enabled for merchant locales`() { + for(locale in validMerchantLocales) { + Afterpay.setConfiguration( + minimumAmount = "10.00", + maximumAmount = "1000.00", + currencyCode = "USD", + locale = locale, + environment = environment, + consumerLocale = Locale.US, + ) + + Assert.assertEquals(true, Afterpay.enabled) + } + } } diff --git a/afterpay/src/test/kotlin/com/afterpay/android/AfterpayInstalmentLocaleTest.kt b/afterpay/src/test/kotlin/com/afterpay/android/AfterpayInstalmentLocaleTest.kt index 7fe0008b..bdc3eb3d 100644 --- a/afterpay/src/test/kotlin/com/afterpay/android/AfterpayInstalmentLocaleTest.kt +++ b/afterpay/src/test/kotlin/com/afterpay/android/AfterpayInstalmentLocaleTest.kt @@ -19,6 +19,10 @@ class AfterpayInstalmentLocaleTest { private val oneHundredAndTwenty = 120.toBigDecimal() + private val itLocale = Locale.ITALY + private val frLocale = Locale.FRANCE + private val esLocale = Locale("es", "ES") + @Test fun `available instalment in en-AU locale`() { val instalments = createAllAvailableInstalments(oneHundredAndTwenty, Locales.EN_AU) @@ -28,7 +32,6 @@ class AfterpayInstalmentLocaleTest { assertEquals("£30.00", instalments.gbp.instalmentAmount) assertEquals("$30.00 NZD", instalments.nzd.instalmentAmount) assertEquals("$30.00 USD", instalments.usd.instalmentAmount) - assertEquals("40.00€", instalments.eur.instalmentAmount) } @Test @@ -40,7 +43,7 @@ class AfterpayInstalmentLocaleTest { assertEquals("£10", instalments.gbp.minimumAmount) assertEquals("$10 NZD", instalments.nzd.minimumAmount) assertEquals("$10 USD", instalments.usd.minimumAmount) - assertEquals("10€", instalments.eur.minimumAmount) + assertEquals(null, instalments.eur.minimumAmount) } @Test @@ -52,7 +55,6 @@ class AfterpayInstalmentLocaleTest { assertEquals("£30.00", instalments.gbp.instalmentAmount) assertEquals("$30.00 NZD", instalments.nzd.instalmentAmount) assertEquals("$30.00 USD", instalments.usd.instalmentAmount) - assertEquals("40.00€", instalments.eur.instalmentAmount) } @Test @@ -64,7 +66,7 @@ class AfterpayInstalmentLocaleTest { assertEquals("£10", instalments.gbp.minimumAmount) assertEquals("$10 NZD", instalments.nzd.minimumAmount) assertEquals("$10 USD", instalments.usd.minimumAmount) - assertEquals("10€", instalments.eur.minimumAmount) + assertEquals(null, instalments.eur.minimumAmount) } @Test @@ -76,19 +78,19 @@ class AfterpayInstalmentLocaleTest { assertEquals("£30,00", instalments.gbp.instalmentAmount) assertEquals("$30,00 NZD", instalments.nzd.instalmentAmount) assertEquals("$30,00 USD", instalments.usd.instalmentAmount) - assertEquals("40,00€", instalments.eur.instalmentAmount) } @Test fun `unavailable instalment in fr-CA locale`() { val instalments = createAllUnavailableInstalments(oneHundredAndTwenty, Locales.FR_CA) + assertEquals("$10 AUD", instalments.aud.minimumAmount) assertEquals("10 $", instalments.cad.minimumAmount) assertEquals("£10", instalments.gbp.minimumAmount) assertEquals("$10 NZD", instalments.nzd.minimumAmount) assertEquals("$10 USD", instalments.usd.minimumAmount) - assertEquals("10€", instalments.eur.minimumAmount) + assertEquals(null, instalments.eur.minimumAmount) } @Test @@ -100,7 +102,6 @@ class AfterpayInstalmentLocaleTest { assertEquals("£30.00", instalments.gbp.instalmentAmount) assertEquals("$30.00 NZD", instalments.nzd.instalmentAmount) assertEquals("$30.00 USD", instalments.usd.instalmentAmount) - assertEquals("40.00€", instalments.eur.instalmentAmount) } @Test @@ -112,7 +113,7 @@ class AfterpayInstalmentLocaleTest { assertEquals("£10", instalments.gbp.minimumAmount) assertEquals("$10 NZD", instalments.nzd.minimumAmount) assertEquals("$10 USD", instalments.usd.minimumAmount) - assertEquals("10€", instalments.eur.minimumAmount) + assertEquals(null, instalments.eur.minimumAmount) } @Test @@ -124,7 +125,6 @@ class AfterpayInstalmentLocaleTest { assertEquals("£30.00", instalments.gbp.instalmentAmount) assertEquals("$30.00", instalments.nzd.instalmentAmount) assertEquals("$30.00 USD", instalments.usd.instalmentAmount) - assertEquals("40.00€", instalments.eur.instalmentAmount) } @Test @@ -136,7 +136,7 @@ class AfterpayInstalmentLocaleTest { assertEquals("£10", instalments.gbp.minimumAmount) assertEquals("$10", instalments.nzd.minimumAmount) assertEquals("$10 USD", instalments.usd.minimumAmount) - assertEquals("10€", instalments.eur.minimumAmount) + assertEquals(null, instalments.eur.minimumAmount) } @Test @@ -148,7 +148,6 @@ class AfterpayInstalmentLocaleTest { assertEquals("£30.00", instalments.gbp.instalmentAmount) assertEquals("NZ$30.00", instalments.nzd.instalmentAmount) assertEquals("$30.00", instalments.usd.instalmentAmount) - assertEquals("40.00€", instalments.eur.instalmentAmount) } @Test @@ -160,79 +159,76 @@ class AfterpayInstalmentLocaleTest { assertEquals("£10", instalments.gbp.minimumAmount) assertEquals("NZ$10", instalments.nzd.minimumAmount) assertEquals("$10", instalments.usd.minimumAmount) - assertEquals("10€", instalments.eur.minimumAmount) + assertEquals(null, instalments.eur.minimumAmount) } @Test fun `available instalment in it-IT locale`() { - val instalments = createAllAvailableInstalments(oneHundredAndTwenty, Locales.IT_IT) + val instalments = createAllAvailableInstalments(oneHundredAndTwenty, itLocale) assertEquals("$30,00 AUD", instalments.aud.instalmentAmount) assertEquals("$30,00 CAD", instalments.cad.instalmentAmount) assertEquals("£30,00", instalments.gbp.instalmentAmount) assertEquals("$30,00 NZD", instalments.nzd.instalmentAmount) assertEquals("$30,00 USD", instalments.usd.instalmentAmount) - assertEquals("40,00 €", instalments.eur.instalmentAmount) } @Test fun `unavailable instalment in it-IT locale`() { - val instalments = createAllUnavailableInstalments(oneHundredAndTwenty, Locales.IT_IT) + val instalments = createAllUnavailableInstalments(oneHundredAndTwenty, itLocale) assertEquals("$10 AUD", instalments.aud.minimumAmount) assertEquals("$10 CAD", instalments.cad.minimumAmount) assertEquals("£10", instalments.gbp.minimumAmount) assertEquals("$10 NZD", instalments.nzd.minimumAmount) assertEquals("$10 USD", instalments.usd.minimumAmount) - assertEquals("10 €", instalments.eur.minimumAmount) + assertEquals(null, instalments.eur.minimumAmount) } @Test fun `available instalment in fr-FR locale`() { - val instalments = createAllAvailableInstalments(oneHundredAndTwenty, Locales.FR_FR) + val instalments = createAllAvailableInstalments(oneHundredAndTwenty, frLocale) assertEquals("$30,00 AUD", instalments.aud.instalmentAmount) assertEquals("$30,00 CAD", instalments.cad.instalmentAmount) assertEquals("£30,00", instalments.gbp.instalmentAmount) assertEquals("$30,00 NZD", instalments.nzd.instalmentAmount) assertEquals("$30,00 USD", instalments.usd.instalmentAmount) - assertEquals("40,00 €", instalments.eur.instalmentAmount) } @Test fun `unavailable instalment in fr-FR locale`() { - val instalments = createAllUnavailableInstalments(oneHundredAndTwenty, Locales.FR_FR) + val instalments = createAllUnavailableInstalments(oneHundredAndTwenty, frLocale) assertEquals("$10 AUD", instalments.aud.minimumAmount) assertEquals("$10 CAD", instalments.cad.minimumAmount) assertEquals("£10", instalments.gbp.minimumAmount) assertEquals("$10 NZD", instalments.nzd.minimumAmount) assertEquals("$10 USD", instalments.usd.minimumAmount) - assertEquals("10 €", instalments.eur.minimumAmount) + assertEquals(null, instalments.eur.minimumAmount) } @Test fun `available instalment in es-ES locale`() { - val instalments = createAllAvailableInstalments(oneHundredAndTwenty, Locales.ES_ES) + val instalments = createAllAvailableInstalments(oneHundredAndTwenty, esLocale) assertEquals("$30,00 AUD", instalments.aud.instalmentAmount) assertEquals("$30,00 CAD", instalments.cad.instalmentAmount) assertEquals("£30,00", instalments.gbp.instalmentAmount) assertEquals("$30,00 NZD", instalments.nzd.instalmentAmount) assertEquals("$30,00 USD", instalments.usd.instalmentAmount) - assertEquals("40,00 €", instalments.eur.instalmentAmount) } @Test fun `unavailable instalment in es-ES locale`() { - val instalments = createAllUnavailableInstalments(oneHundredAndTwenty, Locales.ES_ES) + val instalments = createAllUnavailableInstalments(oneHundredAndTwenty, esLocale) assertEquals("$10 AUD", instalments.aud.minimumAmount) assertEquals("$10 CAD", instalments.cad.minimumAmount) assertEquals("£10", instalments.gbp.minimumAmount) assertEquals("$10 NZD", instalments.nzd.minimumAmount) assertEquals("$10 USD", instalments.usd.minimumAmount) - assertEquals("10 €", instalments.eur.minimumAmount) + assertEquals(null, instalments.eur.minimumAmount) } private data class AllAvailableInstallments( @@ -241,7 +237,6 @@ class AfterpayInstalmentLocaleTest { val gbp: AfterpayInstalment.Available, val nzd: AfterpayInstalment.Available, val usd: AfterpayInstalment.Available, - val eur: AfterpayInstalment.Available, ) private data class AllUnavailableInstallments( @@ -260,7 +255,6 @@ class AfterpayInstalmentLocaleTest { gbp = availableInstalment(amount, poundSterling, locale), nzd = availableInstalment(amount, newZealandDollar, locale), usd = availableInstalment(amount, unitedStatesDollar, locale), - eur = availableInstalment(amount, euro, locale), ) } diff --git a/afterpay/src/test/kotlin/com/afterpay/android/AfterpayTest.kt b/afterpay/src/test/kotlin/com/afterpay/android/AfterpayTest.kt index 40ab0ed3..c1f88064 100644 --- a/afterpay/src/test/kotlin/com/afterpay/android/AfterpayTest.kt +++ b/afterpay/src/test/kotlin/com/afterpay/android/AfterpayTest.kt @@ -1,5 +1,6 @@ package com.afterpay.android +import org.junit.Assert import org.junit.Assert.assertThrows import org.junit.Test import java.util.Locale @@ -8,6 +9,13 @@ class AfterpayTest { private val environment = AfterpayEnvironment.SANDBOX + private val invalidMerchantLocales: Array = arrayOf( + Locale.ITALY, + Locale.FRANCE, + Locale("es", "ES"), + Locale.JAPAN + ) + @Test fun `setConfiguration does not throw for valid configuration`() { Afterpay.setConfiguration( @@ -111,13 +119,17 @@ class AfterpayTest { @Test fun `setConfiguration throws for a locale not in the valid set`() { assertThrows(IllegalArgumentException::class.java) { - Afterpay.setConfiguration( - minimumAmount = "10.00", - maximumAmount = "100.00", - currencyCode = "AUD", - locale = Locale.JAPAN, - environment = environment, - ) + for(locale in invalidMerchantLocales) { + Afterpay.setConfiguration( + minimumAmount = "10.00", + maximumAmount = "1000.00", + currencyCode = "USD", + locale = locale, + environment = environment, + ) + + Assert.assertEquals(false, Afterpay.enabled) + } } } }