mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-05-02 14:43:09 +01:00
Implement refactor to utilize new donation configuration endpoint.
This commit is contained in:
committed by
Cody Henthorne
parent
40cf87307a
commit
424a0233c2
@@ -0,0 +1,178 @@
|
||||
package org.thoughtcrime.securesms.components.settings.app.subscription
|
||||
|
||||
import android.app.Application
|
||||
import androidx.test.core.app.ApplicationProvider
|
||||
import io.mockk.every
|
||||
import io.mockk.mockkStatic
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
import org.robolectric.annotation.Config
|
||||
import org.thoughtcrime.securesms.dependencies.ApplicationDependencies
|
||||
import org.whispersystems.signalservice.internal.push.DonationsConfiguration
|
||||
import org.whispersystems.signalservice.internal.util.JsonUtil
|
||||
import java.util.Currency
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
@Config(application = Application::class)
|
||||
class DonationsConfigurationExtensionsKtTest {
|
||||
|
||||
private val testData: String = javaClass.classLoader!!.getResourceAsStream("donations_configuration_test_data.json").bufferedReader().readText()
|
||||
private val testSubject = JsonUtil.fromJson(testData, DonationsConfiguration::class.java)
|
||||
|
||||
@Test
|
||||
fun `Given all methods are available, when I getSubscriptionAmounts, then I expect BIF`() {
|
||||
val subscriptionPrices = testSubject.getSubscriptionAmounts(DonationsConfiguration.SUBSCRIPTION_LEVELS.first(), AllPaymentMethodsAvailability)
|
||||
|
||||
assertEquals(1, subscriptionPrices.size)
|
||||
assertEquals("BIF", subscriptionPrices.first().currency.currencyCode)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given only PayPal available, when I getSubscriptionAmounts, then I expect BIF and JPY`() {
|
||||
val subscriptionPrices = testSubject.getSubscriptionAmounts(DonationsConfiguration.SUBSCRIPTION_LEVELS.first(), PayPalOnly)
|
||||
|
||||
assertEquals(2, subscriptionPrices.size)
|
||||
assertTrue(subscriptionPrices.map { it.currency.currencyCode }.containsAll(setOf("JPY", "BIF")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given only Card available, when I getSubscriptionAmounts, then I expect BIF and USD`() {
|
||||
val subscriptionPrices = testSubject.getSubscriptionAmounts(DonationsConfiguration.SUBSCRIPTION_LEVELS.first(), CardOnly)
|
||||
|
||||
assertEquals(2, subscriptionPrices.size)
|
||||
assertTrue(subscriptionPrices.map { it.currency.currencyCode }.containsAll(setOf("USD", "BIF")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `When I getGiftBadges, then I expect exactly 1 badge with the id GIFT`() {
|
||||
mockkStatic(ApplicationDependencies::class) {
|
||||
every { ApplicationDependencies.getApplication() } returns ApplicationProvider.getApplicationContext()
|
||||
|
||||
val giftBadges = testSubject.getGiftBadges()
|
||||
|
||||
assertEquals(1, giftBadges.size)
|
||||
assertTrue(giftBadges.first().isGift())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `When I getBoostBadges, then I expect exactly 1 badge with the id BOOST`() {
|
||||
mockkStatic(ApplicationDependencies::class) {
|
||||
every { ApplicationDependencies.getApplication() } returns ApplicationProvider.getApplicationContext()
|
||||
|
||||
val boostBadges = testSubject.getBoostBadges()
|
||||
|
||||
assertEquals(1, boostBadges.size)
|
||||
assertTrue(boostBadges.first().isBoost())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `When I getSubscriptionLevels, then I expect the exact 3 defined subscription levels`() {
|
||||
val subscriptionLevels = testSubject.getSubscriptionLevels()
|
||||
|
||||
assertEquals(3, subscriptionLevels.size)
|
||||
assertEquals(DonationsConfiguration.SUBSCRIPTION_LEVELS, subscriptionLevels.keys)
|
||||
subscriptionLevels.keys.fold(0) { acc, i ->
|
||||
assertTrue(acc < i)
|
||||
i
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given all methods are available, when I getGiftAmounts, then I expect BIF`() {
|
||||
val giftAmounts = testSubject.getGiftBadgeAmounts(AllPaymentMethodsAvailability)
|
||||
|
||||
assertEquals(1, giftAmounts.size)
|
||||
assertNotNull(giftAmounts[Currency.getInstance("BIF")])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given only PayPal available, when I getGiftAmounts, then I expect BIF and JPY`() {
|
||||
val giftAmounts = testSubject.getGiftBadgeAmounts(PayPalOnly)
|
||||
|
||||
assertEquals(2, giftAmounts.size)
|
||||
assertTrue(giftAmounts.map { it.key.currencyCode }.containsAll(setOf("JPY", "BIF")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given only Card available, when I getGiftAmounts, then I expect BIF and USD`() {
|
||||
val giftAmounts = testSubject.getGiftBadgeAmounts(CardOnly)
|
||||
|
||||
assertEquals(2, giftAmounts.size)
|
||||
assertTrue(giftAmounts.map { it.key.currencyCode }.containsAll(setOf("USD", "BIF")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given all methods are available, when I getBoostAmounts, then I expect BIF`() {
|
||||
val boostAmounts = testSubject.getBoostAmounts(AllPaymentMethodsAvailability)
|
||||
|
||||
assertEquals(1, boostAmounts.size)
|
||||
assertNotNull(boostAmounts[Currency.getInstance("BIF")])
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given only PayPal available, when I getBoostAmounts, then I expect BIF and JPY`() {
|
||||
val boostAmounts = testSubject.getBoostAmounts(PayPalOnly)
|
||||
|
||||
assertEquals(2, boostAmounts.size)
|
||||
assertTrue(boostAmounts.map { it.key.currencyCode }.containsAll(setOf("JPY", "BIF")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given only Card available, when I getBoostAmounts, then I expect BIF and USD`() {
|
||||
val boostAmounts = testSubject.getBoostAmounts(CardOnly)
|
||||
|
||||
assertEquals(2, boostAmounts.size)
|
||||
assertTrue(boostAmounts.map { it.key.currencyCode }.containsAll(setOf("USD", "BIF")))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given GIFT_LEVEL, When I getBadge, then I expect the gift badge`() {
|
||||
mockkStatic(ApplicationDependencies::class) {
|
||||
every { ApplicationDependencies.getApplication() } returns ApplicationProvider.getApplicationContext()
|
||||
val badge = testSubject.getBadge(DonationsConfiguration.GIFT_LEVEL)
|
||||
|
||||
assertTrue(badge.isGift())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given BOOST_LEVEL, When I getBadge, then I expect the boost badge`() {
|
||||
mockkStatic(ApplicationDependencies::class) {
|
||||
every { ApplicationDependencies.getApplication() } returns ApplicationProvider.getApplicationContext()
|
||||
val badge = testSubject.getBadge(DonationsConfiguration.BOOST_LEVEL)
|
||||
|
||||
assertTrue(badge.isBoost())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Given a sub level, When I getBadge, then I expect a sub badge`() {
|
||||
mockkStatic(ApplicationDependencies::class) {
|
||||
every { ApplicationDependencies.getApplication() } returns ApplicationProvider.getApplicationContext()
|
||||
val badge = testSubject.getBadge(DonationsConfiguration.SUBSCRIPTION_LEVELS.first())
|
||||
|
||||
assertTrue(badge.isSubscription())
|
||||
}
|
||||
}
|
||||
|
||||
private object AllPaymentMethodsAvailability : PaymentMethodAvailability {
|
||||
override fun isPayPalAvailable(): Boolean = true
|
||||
override fun isGooglePayOrCreditCardAvailable(): Boolean = true
|
||||
}
|
||||
|
||||
private object PayPalOnly : PaymentMethodAvailability {
|
||||
override fun isPayPalAvailable(): Boolean = true
|
||||
override fun isGooglePayOrCreditCardAvailable(): Boolean = false
|
||||
}
|
||||
|
||||
private object CardOnly : PaymentMethodAvailability {
|
||||
override fun isPayPalAvailable(): Boolean = false
|
||||
override fun isGooglePayOrCreditCardAvailable(): Boolean = true
|
||||
}
|
||||
}
|
||||
245
app/src/test/resources/donations_configuration_test_data.json
Normal file
245
app/src/test/resources/donations_configuration_test_data.json
Normal file
@@ -0,0 +1,245 @@
|
||||
{
|
||||
"currencies": {
|
||||
"JPY": {
|
||||
"minimum": 300,
|
||||
"oneTime": {
|
||||
"1": [
|
||||
500,
|
||||
600,
|
||||
700,
|
||||
800,
|
||||
900,
|
||||
1000
|
||||
],
|
||||
"100": [
|
||||
3000
|
||||
]
|
||||
},
|
||||
"subscription": {
|
||||
"2000": 35000,
|
||||
"1000": 15000,
|
||||
"500": 5000
|
||||
},
|
||||
"supportedPaymentMethods": [
|
||||
"PAYPAL"
|
||||
]
|
||||
},
|
||||
"USD": {
|
||||
"minimum": 2.5,
|
||||
"oneTime": {
|
||||
"1": [
|
||||
5.5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10
|
||||
],
|
||||
"100": [
|
||||
20
|
||||
]
|
||||
},
|
||||
"subscription": {
|
||||
"2000": 35,
|
||||
"1000": 15,
|
||||
"500": 5
|
||||
},
|
||||
"supportedPaymentMethods": [
|
||||
"CARD"
|
||||
]
|
||||
},
|
||||
"BIF": {
|
||||
"minimum": 3000,
|
||||
"oneTime": {
|
||||
"1": [
|
||||
5000,
|
||||
6000,
|
||||
7000,
|
||||
8000,
|
||||
9000,
|
||||
10000
|
||||
],
|
||||
"100": [
|
||||
50000
|
||||
]
|
||||
},
|
||||
"subscription": {
|
||||
"2000": 350000,
|
||||
"1000": 150000,
|
||||
"500": 50000
|
||||
},
|
||||
"supportedPaymentMethods": [
|
||||
"CARD", "PAYPAL"
|
||||
]
|
||||
}
|
||||
},
|
||||
"levels": {
|
||||
"1": {
|
||||
"name": "ZBOOST",
|
||||
"badge": {
|
||||
"id": "BOOST",
|
||||
"category": "boost1",
|
||||
"name": "boost1",
|
||||
"description": "boost1",
|
||||
"sprites6": [
|
||||
"l",
|
||||
"m",
|
||||
"h",
|
||||
"x",
|
||||
"xx",
|
||||
"xxx"
|
||||
],
|
||||
"svg": "SVG",
|
||||
"svgs": [
|
||||
{
|
||||
"light": "sl",
|
||||
"dark": "sd"
|
||||
},
|
||||
{
|
||||
"light": "ml",
|
||||
"dark": "md"
|
||||
},
|
||||
{
|
||||
"light": "ll",
|
||||
"dark": "ld"
|
||||
}
|
||||
],
|
||||
"duration": 2592000,
|
||||
"imageUrl": ""
|
||||
}
|
||||
},
|
||||
"100": {
|
||||
"name": "ZGIFT",
|
||||
"badge": {
|
||||
"id": "GIFT",
|
||||
"category": "gift1",
|
||||
"name": "gift1",
|
||||
"description": "gift1",
|
||||
"sprites6": [
|
||||
"l",
|
||||
"m",
|
||||
"h",
|
||||
"x",
|
||||
"xx",
|
||||
"xxx"
|
||||
],
|
||||
"svg": "SVG",
|
||||
"svgs": [
|
||||
{
|
||||
"light": "sl",
|
||||
"dark": "sd"
|
||||
},
|
||||
{
|
||||
"light": "ml",
|
||||
"dark": "md"
|
||||
},
|
||||
{
|
||||
"light": "ll",
|
||||
"dark": "ld"
|
||||
}
|
||||
],
|
||||
"duration": 5184000,
|
||||
"imageUrl": ""
|
||||
}
|
||||
},
|
||||
"2000": {
|
||||
"name": "Z3",
|
||||
"badge": {
|
||||
"id": "B3",
|
||||
"category": "cat3",
|
||||
"name": "name3",
|
||||
"description": "desc3",
|
||||
"sprites6": [
|
||||
"l",
|
||||
"m",
|
||||
"h",
|
||||
"x",
|
||||
"xx",
|
||||
"xxx"
|
||||
],
|
||||
"svg": "SVG",
|
||||
"svgs": [
|
||||
{
|
||||
"light": "sl",
|
||||
"dark": "sd"
|
||||
},
|
||||
{
|
||||
"light": "ml",
|
||||
"dark": "md"
|
||||
},
|
||||
{
|
||||
"light": "ll",
|
||||
"dark": "ld"
|
||||
}
|
||||
],
|
||||
"imageUrl": ""
|
||||
}
|
||||
},
|
||||
"1000": {
|
||||
"name": "Z2",
|
||||
"badge": {
|
||||
"id": "B2",
|
||||
"category": "cat2",
|
||||
"name": "name2",
|
||||
"description": "desc2",
|
||||
"sprites6": [
|
||||
"l",
|
||||
"m",
|
||||
"h",
|
||||
"x",
|
||||
"xx",
|
||||
"xxx"
|
||||
],
|
||||
"svg": "SVG",
|
||||
"svgs": [
|
||||
{
|
||||
"light": "sl",
|
||||
"dark": "sd"
|
||||
},
|
||||
{
|
||||
"light": "ml",
|
||||
"dark": "md"
|
||||
},
|
||||
{
|
||||
"light": "ll",
|
||||
"dark": "ld"
|
||||
}
|
||||
],
|
||||
"imageUrl": ""
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"name": "Z1",
|
||||
"badge": {
|
||||
"id": "B1",
|
||||
"category": "cat1",
|
||||
"name": "name1",
|
||||
"description": "desc1",
|
||||
"sprites6": [
|
||||
"l",
|
||||
"m",
|
||||
"h",
|
||||
"x",
|
||||
"xx",
|
||||
"xxx"
|
||||
],
|
||||
"svg": "SVG",
|
||||
"svgs": [
|
||||
{
|
||||
"light": "sl",
|
||||
"dark": "sd"
|
||||
},
|
||||
{
|
||||
"light": "ml",
|
||||
"dark": "md"
|
||||
},
|
||||
{
|
||||
"light": "ll",
|
||||
"dark": "ld"
|
||||
}
|
||||
],
|
||||
"imageUrl": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user