diff options
Diffstat (limited to 'android/app/src/test')
| -rw-r--r-- | android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/DeviceRevokedViewModelTest.kt | 23 | ||||
| -rw-r--r-- | android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModelTest.kt | 21 |
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 |
