summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJonatan Rhodin <jonatan.rhodin@mullvad.net>2025-08-08 15:50:45 +0200
committerJonatan Rhodin <jonatan.rhodin@mullvad.net>2025-08-11 16:06:44 +0200
commita78d98311017fd3879c250dd326bc49909dd792c (patch)
treecb153897c80b99c6ceec797c4ceced2b2ae071b8
parent4d4b5d2d18525c6898a0a8f4992626e42f388457 (diff)
downloadmullvadvpn-a78d98311017fd3879c250dd326bc49909dd792c.tar.xz
mullvadvpn-a78d98311017fd3879c250dd326bc49909dd792c.zip
Add tests to ensure expected behavior in the payment flow
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/AddTimeViewModelTest.kt56
1 files changed, 56 insertions, 0 deletions
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/AddTimeViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/AddTimeViewModelTest.kt
index b042f44b9c..7e3f966dbb 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/AddTimeViewModelTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/AddTimeViewModelTest.kt
@@ -198,4 +198,60 @@ class AddTimeViewModelTest {
assertEquals(result, item.value.purchaseState)
}
}
+
+ @Test
+ fun `purchaseResult error billing error should result in purchase state null`() = runTest {
+ // Arrange
+ val productId = ProductId("one_month")
+ val paymentProduct =
+ PaymentProduct(productId = productId, price = ProductPrice("€5.00"), status = null)
+ val purchaseResultLoading = PurchaseResult.FetchingProducts
+ val purchaseResultData = PurchaseResult.Error.BillingError(null)
+
+ // Act, Assert
+ viewModel.uiState.test {
+ awaitItem() // Default state
+ // Payment availability can not be null, otherwise the test will timeout
+ paymentAvailability.emit(PaymentAvailability.ProductsAvailable(listOf(paymentProduct)))
+ awaitItem()
+ purchaseResult.emit(
+ purchaseResultLoading
+ ) // Set up loading state so we get a new state when we emit the error
+ val loadingItem = awaitItem()
+ assertIs<Lc.Content<AddTimeUiState>>(loadingItem)
+ assertEquals(PurchaseState.Connecting, loadingItem.value.purchaseState)
+ purchaseResult.emit(purchaseResultData)
+ val item = awaitItem()
+ assertIs<Lc.Content<AddTimeUiState>>(item)
+ assertEquals(null, item.value.purchaseState)
+ }
+ }
+
+ @Test
+ fun `purchaseResult cancelled should result in purchase state null`() = runTest {
+ // Arrange
+ val productId = ProductId("one_month")
+ val paymentProduct =
+ PaymentProduct(productId = productId, price = ProductPrice("€5.00"), status = null)
+ val purchaseResultLoading = PurchaseResult.FetchingProducts
+ val purchaseResultData = PurchaseResult.Completed.Cancelled
+
+ // Act, Assert
+ viewModel.uiState.test {
+ awaitItem() // Default state
+ // Payment availability can not be null, otherwise the test will timeout
+ paymentAvailability.emit(PaymentAvailability.ProductsAvailable(listOf(paymentProduct)))
+ awaitItem()
+ purchaseResult.emit(
+ purchaseResultLoading
+ ) // Set up loading state so we get a new state when we emit cancelled
+ val loadingItem = awaitItem()
+ assertIs<Lc.Content<AddTimeUiState>>(loadingItem)
+ assertEquals(PurchaseState.Connecting, loadingItem.value.purchaseState)
+ purchaseResult.emit(purchaseResultData)
+ val item = awaitItem()
+ assertIs<Lc.Content<AddTimeUiState>>(item)
+ assertEquals(null, item.value.purchaseState)
+ }
+ }
}