This repository has been archived by the owner on Jan 10, 2025. It is now read-only.
forked from mollyim/mollyim-android
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
177 changed files
with
4,629 additions
and
1,932 deletions.
There are no files selected for viewing
This file contains 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
Binary file added
BIN
+438 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_00.binproto
Binary file not shown.
Binary file added
BIN
+534 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_01.binproto
Binary file not shown.
Binary file added
BIN
+610 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_02.binproto
Binary file not shown.
Binary file added
BIN
+586 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_03.binproto
Binary file not shown.
Binary file added
BIN
+608 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_04.binproto
Binary file not shown.
Binary file added
BIN
+527 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_05.binproto
Binary file not shown.
Binary file added
BIN
+589 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_06.binproto
Binary file not shown.
Binary file added
BIN
+518 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_07.binproto
Binary file not shown.
Binary file added
BIN
+497 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_08.binproto
Binary file not shown.
Binary file added
BIN
+435 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_09.binproto
Binary file not shown.
Binary file added
BIN
+532 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_10.binproto
Binary file not shown.
Binary file added
BIN
+610 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_11.binproto
Binary file not shown.
Binary file added
BIN
+584 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_12.binproto
Binary file not shown.
Binary file added
BIN
+610 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_13.binproto
Binary file not shown.
Binary file added
BIN
+527 Bytes
app/src/androidTest/assets/backupTests/chat_item_view_once_14.binproto
Binary file not shown.
This file contains 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
168 changes: 168 additions & 0 deletions
168
app/src/androidTest/java/org/thoughtcrime/securesms/jobs/BackupSubscriptionCheckJobTest.kt
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
package org.thoughtcrime.securesms.jobs | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import io.mockk.coEvery | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import io.mockk.mockkStatic | ||
import okhttp3.mockwebserver.MockResponse | ||
import org.junit.Before | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.signal.core.util.billing.BillingPurchaseResult | ||
import org.thoughtcrime.securesms.backup.v2.MessageBackupTier | ||
import org.thoughtcrime.securesms.components.settings.app.subscription.InAppPaymentsRepository | ||
import org.thoughtcrime.securesms.database.model.InAppPaymentSubscriberRecord | ||
import org.thoughtcrime.securesms.database.model.databaseprotos.InAppPaymentData | ||
import org.thoughtcrime.securesms.dependencies.AppDependencies | ||
import org.thoughtcrime.securesms.dependencies.InstrumentationApplicationDependencyProvider | ||
import org.thoughtcrime.securesms.keyvalue.SignalStore | ||
import org.thoughtcrime.securesms.testing.Get | ||
import org.thoughtcrime.securesms.testing.SignalActivityRule | ||
import org.thoughtcrime.securesms.testing.assertIs | ||
import org.thoughtcrime.securesms.testing.assertIsNull | ||
import org.thoughtcrime.securesms.testing.success | ||
import org.thoughtcrime.securesms.util.RemoteConfig | ||
import org.whispersystems.signalservice.api.subscriptions.ActiveSubscription | ||
import org.whispersystems.signalservice.api.subscriptions.SubscriberId | ||
import java.math.BigDecimal | ||
import java.util.Currency | ||
import kotlin.time.Duration.Companion.days | ||
import kotlin.time.Duration.Companion.milliseconds | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class BackupSubscriptionCheckJobTest { | ||
@get:Rule | ||
val harness = SignalActivityRule() | ||
|
||
private val testSubject = BackupSubscriptionCheckJob.create() | ||
|
||
@Before | ||
fun setUp() { | ||
mockkStatic(AppDependencies::class) | ||
mockkStatic(RemoteConfig::class) | ||
|
||
every { RemoteConfig.messageBackups } returns true | ||
every { AppDependencies.billingApi } returns mockk() | ||
every { AppDependencies.billingApi.isApiAvailable() } returns true | ||
coEvery { AppDependencies.billingApi.queryPurchases() } returns BillingPurchaseResult.None | ||
|
||
val billingApi = AppDependencies.billingApi | ||
|
||
every { billingApi.isApiAvailable() } returns true | ||
} | ||
|
||
@Test | ||
fun givenMessageBackupsAreDisabled_whenICheck_thenIExpectSuccess() { | ||
every { RemoteConfig.messageBackups } returns false | ||
|
||
val result = testSubject.run() | ||
|
||
result.isSuccess.assertIs(true) | ||
} | ||
|
||
@Test | ||
fun givenBillingApiIsUnavailable_whenICheck_thenIExpectSuccess() { | ||
every { AppDependencies.billingApi.isApiAvailable() } returns false | ||
|
||
val result = testSubject.run() | ||
|
||
result.isSuccess.assertIs(true) | ||
} | ||
|
||
@Test | ||
fun givenAGooglePlaySubscriptionAndNoSubscriberId_whenICheck_thenIExpectToTurnOffBackups() { | ||
coEvery { AppDependencies.billingApi.queryPurchases() } returns BillingPurchaseResult.Success( | ||
purchaseToken = "", | ||
isAcknowledged = true, | ||
purchaseTime = System.currentTimeMillis(), | ||
isAutoRenewing = true | ||
) | ||
|
||
SignalStore.backup.backupTier = MessageBackupTier.PAID | ||
|
||
val result = testSubject.run() | ||
|
||
result.isSuccess.assertIs(true) | ||
SignalStore.backup.backupTier.assertIsNull() | ||
} | ||
|
||
@Test | ||
fun givenNoSubscriberIdButPaidTier_whenICheck_thenIExpectToTurnOffBackups() { | ||
SignalStore.backup.backupTier = MessageBackupTier.PAID | ||
|
||
val result = testSubject.run() | ||
|
||
result.isSuccess.assertIs(true) | ||
SignalStore.backup.backupTier.assertIsNull() | ||
} | ||
|
||
@Test | ||
fun givenActiveSubscription_whenICheck_thenIExpectToTurnOnBackups() { | ||
initialiseActiveSubscription() | ||
SignalStore.backup.backupTier = null | ||
|
||
val result = testSubject.run() | ||
|
||
result.isSuccess.assertIs(true) | ||
SignalStore.backup.backupTier.assertIs(MessageBackupTier.PAID) | ||
} | ||
|
||
fun givenInactiveSubscription_whenICheck_thenIExpectToTurnOffBackups() { | ||
initialiseActiveSubscription("canceled") | ||
SignalStore.backup.backupTier = MessageBackupTier.PAID | ||
|
||
val result = testSubject.run() | ||
|
||
result.isSuccess.assertIs(true) | ||
SignalStore.backup.backupTier.assertIsNull() | ||
} | ||
|
||
fun givenInactiveSubscriptionAndNoLocalState_whenICheck_thenIExpectToTurnOffBackups() { | ||
initialiseActiveSubscription("canceled") | ||
SignalStore.backup.backupTier = null | ||
|
||
val result = testSubject.run() | ||
|
||
result.isSuccess.assertIs(true) | ||
SignalStore.backup.backupTier.assertIsNull() | ||
} | ||
|
||
private fun initialiseActiveSubscription(status: String = "active") { | ||
val currency = Currency.getInstance("USD") | ||
val subscriber = InAppPaymentSubscriberRecord( | ||
subscriberId = SubscriberId.generate(), | ||
currency = currency, | ||
type = InAppPaymentSubscriberRecord.Type.BACKUP, | ||
requiresCancel = false, | ||
paymentMethodType = InAppPaymentData.PaymentMethodType.CARD | ||
) | ||
|
||
InAppPaymentsRepository.setSubscriber(subscriber) | ||
SignalStore.inAppPayments.setSubscriberCurrency(currency, subscriber.type) | ||
|
||
InstrumentationApplicationDependencyProvider.addMockWebRequestHandlers( | ||
Get("/v1/subscription/${subscriber.subscriberId.serialize()}") { | ||
MockResponse().success( | ||
ActiveSubscription( | ||
ActiveSubscription.Subscription( | ||
201, | ||
currency.currencyCode, | ||
BigDecimal.ONE, | ||
System.currentTimeMillis().milliseconds.inWholeSeconds + 30.days.inWholeSeconds, | ||
true, | ||
System.currentTimeMillis().milliseconds.inWholeSeconds + 30.days.inWholeSeconds, | ||
false, | ||
status, | ||
"STRIPE", | ||
"GOOGLE_PLAY_BILLING", | ||
false | ||
), | ||
null | ||
) | ||
) | ||
} | ||
) | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.