summaryrefslogtreecommitdiffhomepage
path: root/android/app/src/test
diff options
context:
space:
mode:
authorKalle Lindström <karl.lindstrom@mullvad.net>2025-10-22 10:19:32 +0200
committerKalle Lindström <karl.lindstrom@mullvad.net>2025-10-22 10:19:32 +0200
commit907b64d55b82eaf7600ff56e0a380c8ebcdd3235 (patch)
tree7de54fb33b3fa79f8f80b0de798d9fbfc2c7a152 /android/app/src/test
parent771f8a8cf3d429a0a6f5fcb445d8ef302e8f147b (diff)
parent65f4204221cc0285f4c97426503fe99b21610bf5 (diff)
downloadmullvadvpn-907b64d55b82eaf7600ff56e0a380c8ebcdd3235.tar.xz
mullvadvpn-907b64d55b82eaf7600ff56e0a380c8ebcdd3235.zip
Merge branch 'clear-out-of-time-notification-on-login-revoke-screens-droid-2245'
Diffstat (limited to 'android/app/src/test')
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt23
-rw-r--r--android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModelTest.kt21
2 files changed, 42 insertions, 2 deletions
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt
index d0af241314..f3be9af276 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt
@@ -12,13 +12,14 @@ import io.mockk.mockk
import io.mockk.unmockkAll
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.MutableSharedFlow
-import kotlinx.coroutines.test.UnconfinedTestDispatcher
import kotlinx.coroutines.test.runTest
import net.mullvad.mullvadvpn.compose.state.DeviceRevokedUiState
import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule
import net.mullvad.mullvadvpn.lib.model.TunnelState
import net.mullvad.mullvadvpn.lib.shared.AccountRepository
import net.mullvad.mullvadvpn.lib.shared.ConnectionProxy
+import net.mullvad.mullvadvpn.service.notifications.accountexpiry.AccountExpiryNotificationProvider
+import net.mullvad.mullvadvpn.usecase.ScheduleNotificationAlarmUseCase
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
@@ -37,6 +38,12 @@ class DeviceRevokedViewModelTest {
private val tunnelStateFlow = MutableSharedFlow<TunnelState>()
+ private val mockScheduleNotificationAlarmUseCase =
+ mockk<ScheduleNotificationAlarmUseCase>(relaxed = true)
+
+ private val mockAccountExpiryNotificationProvider =
+ mockk<AccountExpiryNotificationProvider>(relaxed = true)
+
@BeforeEach
fun setup() {
MockKAnnotations.init(this)
@@ -45,7 +52,8 @@ class DeviceRevokedViewModelTest {
DeviceRevokedViewModel(
accountRepository = mockedAccountRepository,
connectionProxy = mockConnectionProxy,
- dispatcher = UnconfinedTestDispatcher(),
+ scheduleNotificationAlarmUseCase = mockScheduleNotificationAlarmUseCase,
+ accountExpiryNotificationProvider = mockAccountExpiryNotificationProvider,
)
}
@@ -69,6 +77,17 @@ class DeviceRevokedViewModelTest {
}
@Test
+ fun `when subscription starts the user account expiry notification should be cancelled`() =
+ runTest {
+ // Act, Assert
+ viewModel.uiState.test {
+ assertEquals(DeviceRevokedUiState.UNKNOWN, awaitItem())
+ coVerify { mockScheduleNotificationAlarmUseCase(null, null) }
+ coVerify { mockAccountExpiryNotificationProvider.cancelNotification() }
+ }
+ }
+
+ @Test
fun `onGoToLoginClicked should invoke logout on AccountRepository`() {
// Arrange
coEvery { mockConnectionProxy.disconnect() } returns true.right()
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModelTest.kt
index 81e0afefbe..90ec8f1c8c 100644
--- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModelTest.kt
+++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModelTest.kt
@@ -29,7 +29,9 @@ import net.mullvad.mullvadvpn.lib.model.AccountNumber
import net.mullvad.mullvadvpn.lib.model.CreateAccountError
import net.mullvad.mullvadvpn.lib.model.LoginAccountError
import net.mullvad.mullvadvpn.lib.shared.AccountRepository
+import net.mullvad.mullvadvpn.service.notifications.accountexpiry.AccountExpiryNotificationProvider
import net.mullvad.mullvadvpn.usecase.InternetAvailableUseCase
+import net.mullvad.mullvadvpn.usecase.ScheduleNotificationAlarmUseCase
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@@ -45,6 +47,12 @@ class LoginViewModelTest {
private lateinit var loginViewModel: LoginViewModel
private lateinit var accountHistoryFlow: MutableStateFlow<AccountNumber?>
+ private val mockScheduleNotificationAlarmUseCase =
+ mockk<ScheduleNotificationAlarmUseCase>(relaxed = true)
+
+ private val mockAccountExpiryNotificationProvider =
+ mockk<AccountExpiryNotificationProvider>(relaxed = true)
+
@BeforeEach
fun setup() {
MockKAnnotations.init(this, relaxUnitFun = true)
@@ -58,6 +66,8 @@ class LoginViewModelTest {
accountRepository = mockedAccountRepository,
newDeviceRepository = mockk(relaxUnitFun = true),
internetAvailableUseCase = connectivityUseCase,
+ scheduleNotificationAlarmUseCase = mockScheduleNotificationAlarmUseCase,
+ accountExpiryNotificationProvider = mockAccountExpiryNotificationProvider,
UnconfinedTestDispatcher(),
)
}
@@ -94,6 +104,17 @@ class LoginViewModelTest {
}
@Test
+ fun `when subscription starts the user account expiry notification should be cancelled`() =
+ runTest {
+ // Act, Assert
+ loginViewModel.uiState.test {
+ assertEquals(LoginUiState.INITIAL, awaitItem())
+ coVerify { mockScheduleNotificationAlarmUseCase(null, null) }
+ coVerify { mockAccountExpiryNotificationProvider.cancelNotification() }
+ }
+ }
+
+ @Test
fun `createAccount call should result in NavigateToWelcome side effect`() = runTest {
turbineScope {
// Arrange