From ba23a454c010e1961a19c6abca8eaba46ecf2c70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Fri, 14 Jun 2024 15:00:23 +0200 Subject: [PATCH] Align UseCases --- .../net/mullvad/mullvadvpn/di/UiModule.kt | 12 ++++++----- .../repository/InAppNotificationController.kt | 10 ++++----- .../repository/NewDeviceRepository.kt | 18 ++++++++++++++++ .../AccountExpiryNotificationUseCase.kt | 2 +- .../usecase/AvailableProvidersUseCase.kt | 2 +- .../usecase/FilteredRelayListUseCase.kt | 2 +- ...UseCase.kt => InternetAvailableUseCase.kt} | 4 ++-- .../usecase/NewDeviceNotificationUseCase.kt | 21 +++++++------------ .../mullvadvpn/usecase/PaymentUseCase.kt | 8 +++++++ .../usecase/SelectedLocationTitleUseCase.kt | 2 +- ...t => SystemVpnSettingsAvailableUseCase.kt} | 4 ++-- .../usecase/TunnelStateNotificationUseCase.kt | 2 +- .../usecase/VersionNotificationUseCase.kt | 2 +- .../customlists/CustomListActionUseCase.kt | 18 ++++++++-------- .../CustomListRelayItemsUseCase.kt | 4 +--- .../CustomListsRelayItemUseCase.kt | 2 +- .../mullvadvpn/viewmodel/ConnectViewModel.kt | 8 +++---- .../CreateCustomListDialogViewModel.kt | 3 +-- .../viewmodel/CustomListLocationsViewModel.kt | 9 ++------ .../viewmodel/CustomListsViewModel.kt | 2 +- .../DeleteCustomListConfirmationViewModel.kt | 3 +-- .../EditCustomListNameDialogViewModel.kt | 3 +-- .../mullvadvpn/viewmodel/FilterViewModel.kt | 6 +++--- .../mullvadvpn/viewmodel/LoginViewModel.kt | 12 +++++------ .../viewmodel/SelectLocationViewModel.kt | 14 ++++++------- .../viewmodel/VpnSettingsViewModel.kt | 7 +++---- .../AccountExpiryNotificationUseCaseTest.kt | 8 +++---- .../usecase/CustomListActionUseCaseTest.kt | 12 +++++------ .../NewDeviceUseNotificationCaseTest.kt | 6 +++--- .../TunnelStateNotificationUseCaseTest.kt | 6 +++--- .../usecase/VersionNotificationUseCaseTest.kt | 6 +++--- .../viewmodel/LoginViewModelTest.kt | 10 ++++----- .../viewmodel/VpnSettingsViewModelTest.kt | 5 +++-- 33 files changed, 120 insertions(+), 113 deletions(-) create mode 100644 android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/NewDeviceRepository.kt rename android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/{ConnectivityUseCase.kt => InternetAvailableUseCase.kt} (84%) rename android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/{SystemVpnSettingsUseCase.kt => SystemVpnSettingsAvailableUseCase.kt} (65%) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt index 70153de61969..d752460ddbf2 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/di/UiModule.kt @@ -19,6 +19,7 @@ import net.mullvad.mullvadvpn.repository.ApiAccessRepository import net.mullvad.mullvadvpn.repository.ChangelogRepository import net.mullvad.mullvadvpn.repository.CustomListsRepository import net.mullvad.mullvadvpn.repository.InAppNotificationController +import net.mullvad.mullvadvpn.repository.NewDeviceRepository import net.mullvad.mullvadvpn.repository.PrivacyDisclaimerRepository import net.mullvad.mullvadvpn.repository.ProblemReportRepository import net.mullvad.mullvadvpn.repository.RelayListFilterRepository @@ -30,16 +31,16 @@ import net.mullvad.mullvadvpn.ui.serviceconnection.AppVersionInfoRepository import net.mullvad.mullvadvpn.ui.serviceconnection.ServiceConnectionManager import net.mullvad.mullvadvpn.usecase.AccountExpiryNotificationUseCase import net.mullvad.mullvadvpn.usecase.AvailableProvidersUseCase -import net.mullvad.mullvadvpn.usecase.ConnectivityUseCase import net.mullvad.mullvadvpn.usecase.EmptyPaymentUseCase import net.mullvad.mullvadvpn.usecase.FilteredRelayListUseCase +import net.mullvad.mullvadvpn.usecase.InternetAvailableUseCase import net.mullvad.mullvadvpn.usecase.LastKnownLocationUseCase import net.mullvad.mullvadvpn.usecase.NewDeviceNotificationUseCase import net.mullvad.mullvadvpn.usecase.OutOfTimeUseCase import net.mullvad.mullvadvpn.usecase.PaymentUseCase import net.mullvad.mullvadvpn.usecase.PlayPaymentUseCase import net.mullvad.mullvadvpn.usecase.SelectedLocationTitleUseCase -import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsUseCase +import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsAvailableUseCase import net.mullvad.mullvadvpn.usecase.TunnelStateNotificationUseCase import net.mullvad.mullvadvpn.usecase.VersionNotificationUseCase import net.mullvad.mullvadvpn.usecase.customlists.CustomListActionUseCase @@ -122,14 +123,15 @@ val uiModule = module { single { VoucherRepository(get(), get()) } single { SplitTunnelingRepository(get()) } single { ApiAccessRepository(get()) } + single { NewDeviceRepository() } single { AccountExpiryNotificationUseCase(get()) } single { TunnelStateNotificationUseCase(get()) } single { VersionNotificationUseCase(get(), BuildConfig.ENABLE_IN_APP_VERSION_NOTIFICATIONS) } - single { NewDeviceNotificationUseCase(get()) } + single { NewDeviceNotificationUseCase(get(), get()) } single { OutOfTimeUseCase(get(), get(), MainScope()) } - single { ConnectivityUseCase(get()) } - single { SystemVpnSettingsUseCase(androidContext()) } + single { InternetAvailableUseCase(get()) } + single { SystemVpnSettingsAvailableUseCase(androidContext()) } single { CustomListActionUseCase(get(), get()) } single { SelectedLocationTitleUseCase(get(), get()) } single { AvailableProvidersUseCase(get()) } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/InAppNotificationController.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/InAppNotificationController.kt index decff575f882..68533cf3db9b 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/InAppNotificationController.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/InAppNotificationController.kt @@ -56,7 +56,7 @@ sealed class InAppNotification { class InAppNotificationController( accountExpiryNotificationUseCase: AccountExpiryNotificationUseCase, - newDeviceNotificationUseCase: NewDeviceNotificationUseCase, + newDeviceNotificationUseRepository: NewDeviceNotificationUseCase, versionNotificationUseCase: VersionNotificationUseCase, tunnelStateNotificationUseCase: TunnelStateNotificationUseCase, scope: CoroutineScope, @@ -64,10 +64,10 @@ class InAppNotificationController( val notifications = combine( - tunnelStateNotificationUseCase.notifications(), - versionNotificationUseCase.notifications(), - accountExpiryNotificationUseCase.notifications(), - newDeviceNotificationUseCase.notifications(), + tunnelStateNotificationUseCase(), + versionNotificationUseCase(), + accountExpiryNotificationUseCase(), + newDeviceNotificationUseRepository(), ) { a, b, c, d -> a + b + c + d } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/NewDeviceRepository.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/NewDeviceRepository.kt new file mode 100644 index 000000000000..37448ed0b975 --- /dev/null +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/NewDeviceRepository.kt @@ -0,0 +1,18 @@ +package net.mullvad.mullvadvpn.repository + +import kotlinx.coroutines.flow.MutableStateFlow +import kotlinx.coroutines.flow.StateFlow + +class NewDeviceRepository { + private val _mutableShowNewDeviceNotification = MutableStateFlow(false) + + val isNewDevice: StateFlow = _mutableShowNewDeviceNotification + + fun newDeviceCreated() { + _mutableShowNewDeviceNotification.value = true + } + + fun clearNewDeviceCreatedNotification() { + _mutableShowNewDeviceNotification.value = false + } +} diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCase.kt index 65822788cb31..4a7f1092a758 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCase.kt @@ -12,7 +12,7 @@ import org.joda.time.DateTime class AccountExpiryNotificationUseCase( private val accountRepository: AccountRepository, ) { - fun notifications(): Flow> = + operator fun invoke(): Flow> = accountRepository.accountData .map(::accountExpiryNotification) .map(::listOfNotNull) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AvailableProvidersUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AvailableProvidersUseCase.kt index f79c0421f692..14aa3824cfce 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AvailableProvidersUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/AvailableProvidersUseCase.kt @@ -8,7 +8,7 @@ import net.mullvad.mullvadvpn.repository.RelayListRepository class AvailableProvidersUseCase(private val relayListRepository: RelayListRepository) { - fun availableProviders(): Flow> = + operator fun invoke(): Flow> = relayListRepository.relayList.map { relayList -> relayList .flatMap(RelayItem.Location.Country::cities) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilteredRelayListUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilteredRelayListUseCase.kt index 265c1272278e..c4e05ccc92cc 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilteredRelayListUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/FilteredRelayListUseCase.kt @@ -13,7 +13,7 @@ class FilteredRelayListUseCase( private val relayListRepository: RelayListRepository, private val relayListFilterRepository: RelayListFilterRepository ) { - fun filteredRelayList() = + operator fun invoke() = combine( relayListRepository.relayList, relayListFilterRepository.selectedOwnership, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/ConnectivityUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/InternetAvailableUseCase.kt similarity index 84% rename from android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/ConnectivityUseCase.kt rename to android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/InternetAvailableUseCase.kt index 35983a86c0e9..a9a49e0cd66b 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/ConnectivityUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/InternetAvailableUseCase.kt @@ -4,8 +4,8 @@ import android.content.Context import android.net.ConnectivityManager import android.net.NetworkCapabilities -class ConnectivityUseCase(val context: Context) { - fun isInternetAvailable(): Boolean { +class InternetAvailableUseCase(val context: Context) { + operator fun invoke(): Boolean { val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceNotificationUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceNotificationUseCase.kt index 06d26a76e8fb..12ce35615556 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceNotificationUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceNotificationUseCase.kt @@ -1,19 +1,20 @@ package net.mullvad.mullvadvpn.usecase -import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.map import net.mullvad.mullvadvpn.lib.shared.DeviceRepository import net.mullvad.mullvadvpn.repository.InAppNotification +import net.mullvad.mullvadvpn.repository.NewDeviceRepository -class NewDeviceNotificationUseCase(private val deviceRepository: DeviceRepository) { - private val _mutableShowNewDeviceNotification = MutableStateFlow(false) - - fun notifications() = +class NewDeviceNotificationUseCase( + private val newDeviceRepository: NewDeviceRepository, + private val deviceRepository: DeviceRepository +) { + operator fun invoke() = combine( deviceRepository.deviceState.map { it?.displayName() }, - _mutableShowNewDeviceNotification + newDeviceRepository.isNewDevice ) { deviceName, newDeviceCreated -> if (newDeviceCreated && deviceName != null) { InAppNotification.NewDevice(deviceName) @@ -21,12 +22,4 @@ class NewDeviceNotificationUseCase(private val deviceRepository: DeviceRepositor } .map(::listOfNotNull) .distinctUntilChanged() - - fun newDeviceCreated() { - _mutableShowNewDeviceNotification.value = true - } - - fun clearNewDeviceCreatedNotification() { - _mutableShowNewDeviceNotification.value = false - } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt index 82efd5d72206..fbd662f95ecd 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/PaymentUseCase.kt @@ -36,6 +36,7 @@ class PlayPaymentUseCase(private val paymentRepository: PaymentRepository) : Pay override val paymentAvailability = _paymentAvailability.asStateFlow() override val purchaseResult = _purchaseResult.asStateFlow() + @Suppress("ensure every public functions method is named 'invoke' with operator modifier") override suspend fun purchaseProduct(productId: ProductId, activityProvider: () -> Activity) { paymentRepository .purchaseProduct(productId, activityProvider) @@ -48,14 +49,17 @@ class PlayPaymentUseCase(private val paymentRepository: PaymentRepository) : Pay .collect(_purchaseResult) } + @Suppress("ensure every public functions method is named 'invoke' with operator modifier") override suspend fun queryPaymentAvailability() { paymentRepository.queryPaymentAvailability().collect(_paymentAvailability) } + @Suppress("ensure every public functions method is named 'invoke' with operator modifier") override suspend fun resetPurchaseResult() { _purchaseResult.emit(null) } + @Suppress("ensure every public functions method is named 'invoke' with operator modifier") override suspend fun verifyPurchases(onSuccessfulVerification: () -> Unit) { paymentRepository .verifyPurchases() @@ -87,18 +91,22 @@ class EmptyPaymentUseCase : PaymentUseCase { override val paymentAvailability = MutableStateFlow(PaymentAvailability.ProductsUnavailable) override val purchaseResult = MutableStateFlow(null) + @Suppress("ensure every public functions method is named 'invoke' with operator modifier") override suspend fun purchaseProduct(productId: ProductId, activityProvider: () -> Activity) { // No op } + @Suppress("ensure every public functions method is named 'invoke' with operator modifier") override suspend fun queryPaymentAvailability() { // No op } + @Suppress("ensure every public functions method is named 'invoke' with operator modifier") override suspend fun resetPurchaseResult() { // No op } + @Suppress("ensure every public functions method is named 'invoke' with operator modifier") override suspend fun verifyPurchases(onSuccessfulVerification: () -> Unit) { // No op } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationTitleUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationTitleUseCase.kt index a37e33492dec..a45da5ae769f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationTitleUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SelectedLocationTitleUseCase.kt @@ -16,7 +16,7 @@ class SelectedLocationTitleUseCase( private val customListsRepository: CustomListsRepository, private val relayListRepository: RelayListRepository, ) { - fun selectedLocationTitle() = + operator fun invoke() = combine( customListsRepository.customLists, relayListRepository.relayList, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SystemVpnSettingsUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SystemVpnSettingsAvailableUseCase.kt similarity index 65% rename from android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SystemVpnSettingsUseCase.kt rename to android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SystemVpnSettingsAvailableUseCase.kt index a2ca2cdc64c3..11ef538acef0 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SystemVpnSettingsUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/SystemVpnSettingsAvailableUseCase.kt @@ -3,7 +3,7 @@ package net.mullvad.mullvadvpn.usecase import android.content.Context import android.content.Intent -class SystemVpnSettingsUseCase(val context: Context) { - fun systemVpnSettingsAvailable(): Boolean = +class SystemVpnSettingsAvailableUseCase(val context: Context) { + operator fun invoke(): Boolean = Intent("android.net.vpn.SETTINGS").resolveActivity(context.packageManager) != null } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCase.kt index ce0878c5176e..888f9f67bf09 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCase.kt @@ -9,7 +9,7 @@ import net.mullvad.mullvadvpn.lib.shared.ConnectionProxy import net.mullvad.mullvadvpn.repository.InAppNotification class TunnelStateNotificationUseCase(private val connectionProxy: ConnectionProxy) { - fun notifications(): Flow> = + operator fun invoke(): Flow> = connectionProxy.tunnelState .distinctUntilChanged() .map(::tunnelStateNotification) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCase.kt index b7dc50a24173..43f1fdac7716 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCase.kt @@ -11,7 +11,7 @@ class VersionNotificationUseCase( private val isVersionInfoNotificationEnabled: Boolean, ) { - fun notifications() = + operator fun invoke() = appVersionInfoRepository .versionInfo() .map { versionInfo -> diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt index 180381f7718a..354316793c45 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListActionUseCase.kt @@ -22,32 +22,32 @@ class CustomListActionUseCase( private val customListsRepository: CustomListsRepository, private val relayListRepository: RelayListRepository ) { - suspend fun performAction( + suspend operator fun invoke( action: CustomListAction ): Either { return when (action) { is CustomListAction.Create -> { - performAction(action) + invoke(action) } is CustomListAction.Rename -> { - performAction(action) + invoke(action) } is CustomListAction.Delete -> { - performAction(action) + invoke(action) } is CustomListAction.UpdateLocations -> { - performAction(action) + invoke(action) } } } - suspend fun performAction(action: CustomListAction.Rename): Either = + suspend operator fun invoke(action: CustomListAction.Rename): Either = customListsRepository .updateCustomListName(action.id, action.newName) .map { Renamed(undo = action.not()) } .mapLeft(::RenameError) - suspend fun performAction( + suspend operator fun invoke( action: CustomListAction.Create ): Either = either { val customListId = @@ -79,7 +79,7 @@ class CustomListActionUseCase( ) } - suspend fun performAction( + suspend operator fun invoke( action: CustomListAction.Delete ): Either = either { val customList = @@ -94,7 +94,7 @@ class CustomListActionUseCase( Deleted(undo = action.not(locations = customList.locations, name = customList.name)) } - suspend fun performAction( + suspend operator fun invoke( action: CustomListAction.UpdateLocations ): Either = either { val customList = diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListRelayItemsUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListRelayItemsUseCase.kt index d28bfe1d5509..3390b8f9a16b 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListRelayItemsUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListRelayItemsUseCase.kt @@ -14,9 +14,7 @@ class CustomListRelayItemsUseCase( private val customListsRepository: CustomListsRepository, private val relayListRepository: RelayListRepository ) { - fun getRelayItemLocationsForCustomList( - customListId: CustomListId - ): Flow> = + operator fun invoke(customListId: CustomListId): Flow> = combine( customListsRepository.customLists.mapNotNull { it?.getById(customListId) }, relayListRepository.relayList diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListsRelayItemUseCase.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListsRelayItemUseCase.kt index 015aa8ab4f5a..93eb914bd0f1 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListsRelayItemUseCase.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/customlists/CustomListsRelayItemUseCase.kt @@ -10,7 +10,7 @@ class CustomListsRelayItemUseCase( private val relayListRepository: RelayListRepository, ) { - fun relayItemCustomLists() = + operator fun invoke() = combine(customListsRepository.customLists, relayListRepository.relayList) { customLists, relayList -> diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt index a27ed9adbd29..b41a175dad5f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/ConnectViewModel.kt @@ -25,8 +25,8 @@ import net.mullvad.mullvadvpn.lib.shared.ConnectionProxy import net.mullvad.mullvadvpn.lib.shared.DeviceRepository import net.mullvad.mullvadvpn.lib.shared.VpnPermissionRepository import net.mullvad.mullvadvpn.repository.InAppNotificationController +import net.mullvad.mullvadvpn.repository.NewDeviceRepository import net.mullvad.mullvadvpn.usecase.LastKnownLocationUseCase -import net.mullvad.mullvadvpn.usecase.NewDeviceNotificationUseCase import net.mullvad.mullvadvpn.usecase.OutOfTimeUseCase import net.mullvad.mullvadvpn.usecase.PaymentUseCase import net.mullvad.mullvadvpn.usecase.SelectedLocationTitleUseCase @@ -40,7 +40,7 @@ class ConnectViewModel( private val accountRepository: AccountRepository, private val deviceRepository: DeviceRepository, inAppNotificationController: InAppNotificationController, - private val newDeviceNotificationUseCase: NewDeviceNotificationUseCase, + private val newDeviceRepository: NewDeviceRepository, selectedLocationTitleUseCase: SelectedLocationTitleUseCase, private val outOfTimeUseCase: OutOfTimeUseCase, private val paymentUseCase: PaymentUseCase, @@ -57,7 +57,7 @@ class ConnectViewModel( @OptIn(FlowPreview::class) val uiState: StateFlow = combine( - selectedLocationTitleUseCase.selectedLocationTitle(), + selectedLocationTitleUseCase(), inAppNotificationController.notifications, connectionProxy.tunnelState, lastKnownLocationUseCase.lastKnownDisconnectedLocation, @@ -167,7 +167,7 @@ class ConnectViewModel( } fun dismissNewDeviceNotification() { - newDeviceNotificationUseCase.clearNewDeviceCreatedNotification() + newDeviceRepository.clearNewDeviceCreatedNotification() } private fun outOfTimeEffect() = diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CreateCustomListDialogViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CreateCustomListDialogViewModel.kt index 043f9895981f..ef453029750b 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CreateCustomListDialogViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CreateCustomListDialogViewModel.kt @@ -37,8 +37,7 @@ class CreateCustomListDialogViewModel( fun createCustomList(name: String) { viewModelScope.launch { - customListActionUseCase - .performAction( + customListActionUseCase( CustomListAction.Create( CustomListName.fromString(name), listOfNotNull(locationCode) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt index 581c11c39716..f25384c1207f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModel.kt @@ -79,8 +79,7 @@ class CustomListLocationsViewModel( fun save() { viewModelScope.launch { _selectedLocations.value?.let { selectedLocations -> - customListActionUseCase - .performAction( + customListActionUseCase( CustomListAction.UpdateLocations( customListId, selectedLocations.calculateLocationsToSave().map { it.id } @@ -191,11 +190,7 @@ class CustomListLocationsViewModel( private suspend fun fetchInitialSelectedLocations() { val selectedLocations = - customListRelayItemsUseCase - .getRelayItemLocationsForCustomList(customListId) - .first() - .withDescendants() - .toSet() + customListRelayItemsUseCase(customListId).first().withDescendants().toSet() _initialLocations.value = selectedLocations _selectedLocations.value = selectedLocations diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListsViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListsViewModel.kt index 3689ad7fc8b4..03d3548ebc95 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListsViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListsViewModel.kt @@ -28,6 +28,6 @@ class CustomListsViewModel( ) fun undoDeleteCustomList(action: CustomListAction.Create) { - viewModelScope.launch { customListActionUseCase.performAction(action) } + viewModelScope.launch { customListActionUseCase(action) } } } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeleteCustomListConfirmationViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeleteCustomListConfirmationViewModel.kt index 79c2a133c20d..8bea330f83cb 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeleteCustomListConfirmationViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/DeleteCustomListConfirmationViewModel.kt @@ -37,8 +37,7 @@ class DeleteCustomListConfirmationViewModel( fun deleteCustomList() { viewModelScope.launch { _error.emit(null) - customListActionUseCase - .performAction(CustomListAction.Delete(customListId)) + customListActionUseCase(CustomListAction.Delete(customListId)) .fold( { _error.tryEmit(it) }, { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt index 7c45bed0d7de..2536f8edd75f 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListNameDialogViewModel.kt @@ -41,8 +41,7 @@ class EditCustomListNameDialogViewModel( fun updateCustomListName(name: String) { viewModelScope.launch { - customListActionUseCase - .performAction( + customListActionUseCase( CustomListAction.Rename( id = customListId, name = initialName, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt index 6e139f4d7f44..728142b3ffbf 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/FilterViewModel.kt @@ -35,7 +35,7 @@ class FilterViewModel( viewModelScope.launch { selectedProviders.value = combine( - availableProvidersUseCase.availableProviders(), + availableProvidersUseCase(), relayListFilterRepository.selectedProviders, ) { allProviders, selectedConstraintProviders -> selectedConstraintProviders.toSelectedProviders(allProviders) @@ -50,7 +50,7 @@ class FilterViewModel( val uiState: StateFlow = combine( selectedOwnership, - availableProvidersUseCase.availableProviders(), + availableProvidersUseCase(), selectedProviders, ) { selectedOwnership, allProviders, selectedProviders -> RelayFilterState( @@ -86,7 +86,7 @@ class FilterViewModel( viewModelScope.launch { selectedProviders.value = if (isChecked) { - availableProvidersUseCase.availableProviders().first() + availableProvidersUseCase().first() } else { emptyList() } diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt index fc2f5e86f9fa..e35baa571eb6 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/LoginViewModel.kt @@ -27,8 +27,8 @@ import net.mullvad.mullvadvpn.compose.state.LoginUiState import net.mullvad.mullvadvpn.lib.model.AccountNumber import net.mullvad.mullvadvpn.lib.model.LoginAccountError import net.mullvad.mullvadvpn.lib.shared.AccountRepository -import net.mullvad.mullvadvpn.usecase.ConnectivityUseCase -import net.mullvad.mullvadvpn.usecase.NewDeviceNotificationUseCase +import net.mullvad.mullvadvpn.repository.NewDeviceRepository +import net.mullvad.mullvadvpn.usecase.InternetAvailableUseCase import net.mullvad.mullvadvpn.util.getOrDefault private const val MINIMUM_LOADING_SPINNER_TIME_MILLIS = 500L @@ -45,8 +45,8 @@ sealed interface LoginUiSideEffect { class LoginViewModel( private val accountRepository: AccountRepository, - private val newDeviceNotificationUseCase: NewDeviceNotificationUseCase, - private val connectivityUseCase: ConnectivityUseCase, + private val newDeviceRepository: NewDeviceRepository, + private val internetAvailableUseCase: InternetAvailableUseCase, private val dispatcher: CoroutineDispatcher = Dispatchers.IO ) : ViewModel() { private val _loginState = MutableStateFlow(LoginUiState.INITIAL.loginState) @@ -123,7 +123,7 @@ class LoginViewModel( } private suspend fun onSuccessfulLogin() { - newDeviceNotificationUseCase.newDeviceCreated() + newDeviceRepository.newDeviceCreated() viewModelScope.launch(dispatcher) { // Find if user is out of time @@ -161,7 +161,7 @@ class LoginViewModel( } private fun isInternetAvailable(): Boolean { - return connectivityUseCase.isInternetAvailable() + return internetAvailableUseCase() } companion object { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt index 2ab757bd78bc..2509fdc8765d 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModel.kt @@ -42,12 +42,12 @@ class SelectLocationViewModel( @Suppress("DestructuringDeclarationWithTooManyEntries") val uiState = combine( - filteredRelayListUseCase.filteredRelayList(), - customListsRelayItemUseCase.relayItemCustomLists(), + filteredRelayListUseCase(), + customListsRelayItemUseCase(), relayListRepository.selectedLocation, _searchTerm, relayListFilterRepository.selectedOwnership, - availableProvidersUseCase.availableProviders(), + availableProvidersUseCase(), relayListFilterRepository.selectedProviders, ) { relayCountries, @@ -135,8 +135,7 @@ class SelectLocationViewModel( viewModelScope.launch { val newLocations = (customList.locations + item).filter { it !in item.descendants() }.map { it.id } - customListActionUseCase - .performAction(CustomListAction.UpdateLocations(customList.id, newLocations)) + customListActionUseCase(CustomListAction.UpdateLocations(customList.id, newLocations)) .fold( { _uiSideEffect.send(SelectLocationSideEffect.GenericError) }, { _uiSideEffect.send(SelectLocationSideEffect.LocationAddedToCustomList(it)) }, @@ -145,14 +144,13 @@ class SelectLocationViewModel( } fun performAction(action: CustomListAction) { - viewModelScope.launch { customListActionUseCase.performAction(action) } + viewModelScope.launch { customListActionUseCase(action) } } fun removeLocationFromList(item: RelayItem.Location, customList: RelayItem.CustomList) { viewModelScope.launch { val newLocations = (customList.locations - item).map { it.id } - customListActionUseCase - .performAction(CustomListAction.UpdateLocations(customList.id, newLocations)) + customListActionUseCase(CustomListAction.UpdateLocations(customList.id, newLocations)) .fold( { _uiSideEffect.send(SelectLocationSideEffect.GenericError) }, { diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt index a0a38ef6f8c9..3c24cba6d690 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModel.kt @@ -29,7 +29,7 @@ import net.mullvad.mullvadvpn.lib.model.Settings import net.mullvad.mullvadvpn.lib.model.WireguardConstraints import net.mullvad.mullvadvpn.repository.RelayListRepository import net.mullvad.mullvadvpn.repository.SettingsRepository -import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsUseCase +import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsAvailableUseCase import net.mullvad.mullvadvpn.util.isCustom sealed interface VpnSettingsSideEffect { @@ -45,7 +45,7 @@ sealed interface VpnSettingsSideEffect { class VpnSettingsViewModel( private val repository: SettingsRepository, private val relayListRepository: RelayListRepository, - private val systemVpnSettingsUseCase: SystemVpnSettingsUseCase, + private val systemVpnSettingsUseCase: SystemVpnSettingsAvailableUseCase, private val dispatcher: CoroutineDispatcher = Dispatchers.IO ) : ViewModel() { @@ -76,8 +76,7 @@ class VpnSettingsViewModel( selectedWireguardPort = settings?.getWireguardPort() ?: Constraint.Any, customWireguardPort = customWgPort, availablePortRanges = portRanges, - systemVpnSettingsAvailable = - systemVpnSettingsUseCase.systemVpnSettingsAvailable() + systemVpnSettingsAvailable = systemVpnSettingsUseCase() ) } .stateIn( diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCaseTest.kt index 11d574b663e0..897ab65e15f4 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCaseTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/AccountExpiryNotificationUseCaseTest.kt @@ -43,15 +43,13 @@ class AccountExpiryNotificationUseCaseTest { @Test fun `initial state should be empty`() = runTest { // Arrange, Act, Assert - accountExpiryNotificationUseCase.notifications().test { - assertTrue { awaitItem().isEmpty() } - } + accountExpiryNotificationUseCase().test { assertTrue { awaitItem().isEmpty() } } } @Test fun `account that expires within 3 days should emit a notification`() = runTest { // Arrange, Act, Assert - accountExpiryNotificationUseCase.notifications().test { + accountExpiryNotificationUseCase().test { assertTrue { awaitItem().isEmpty() } val closeToExpiry = AccountData(mockk(relaxed = true), DateTime.now().plusDays(2)) accountExpiry.value = closeToExpiry @@ -66,7 +64,7 @@ class AccountExpiryNotificationUseCaseTest { @Test fun `account that expires in 4 days should not emit a notification`() = runTest { // Arrange, Act, Assert - accountExpiryNotificationUseCase.notifications().test { + accountExpiryNotificationUseCase().test { assertTrue { awaitItem().isEmpty() } accountExpiry.value = AccountData(mockk(relaxed = true), DateTime.now().plusDays(4)) expectNoEvents() diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt index bb19d42d13af..d98292ccd9e2 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt @@ -77,7 +77,7 @@ class CustomListActionUseCaseTest { ) // Act - val result = customListActionUseCase.performAction(action) + val result = customListActionUseCase(action) // Assert assertEquals(expectedResult, result) @@ -94,7 +94,7 @@ class CustomListActionUseCaseTest { CustomListAlreadyExists.left() // Act - val result = customListActionUseCase.performAction(action) + val result = customListActionUseCase(action) // Assert assertEquals(expectedError, result) @@ -113,7 +113,7 @@ class CustomListActionUseCaseTest { } returns Unit.right() // Act - val result = customListActionUseCase.performAction(action) + val result = customListActionUseCase(action) // Assert assertEquals(expectedResult, result) @@ -133,7 +133,7 @@ class CustomListActionUseCaseTest { val expectedError = RenameError(NameAlreadyExists(newName.value)).left() // Act - val result = customListActionUseCase.performAction(action) + val result = customListActionUseCase(action) // Assert assertEquals(expectedError, result) @@ -158,7 +158,7 @@ class CustomListActionUseCaseTest { mockCustomList.right() // Act - val result = customListActionUseCase.performAction(action) + val result = customListActionUseCase(action) // Assert assertEquals(expectedResult, result) @@ -184,7 +184,7 @@ class CustomListActionUseCaseTest { } returns Unit.right() // Act - val result = customListActionUseCase.performAction(action) + val result = customListActionUseCase(action) // Assert assertEquals(expectedResult, result) diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceUseNotificationCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceUseNotificationCaseTest.kt index 95df8dc359bd..ec487815e157 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceUseNotificationCaseTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/NewDeviceUseNotificationCaseTest.kt @@ -58,13 +58,13 @@ class NewDeviceUseNotificationCaseTest { @Test fun `initial state should be empty`() = runTest { // Arrange, Act, Assert - newDeviceNotificationUseCase.notifications().test { assertTrue { awaitItem().isEmpty() } } + newDeviceNotificationUseCase().test { assertTrue { awaitItem().isEmpty() } } } @Test fun `when newDeviceCreated is called notifications should emit NewDevice notification containing device name`() = runTest { - newDeviceNotificationUseCase.notifications().test { + newDeviceNotificationUseCase().test { // Arrange, Act awaitItem() newDeviceNotificationUseCase.newDeviceCreated() @@ -76,7 +76,7 @@ class NewDeviceUseNotificationCaseTest { @Test fun `clearNewDeviceCreatedNotification should clear notifications`() = runTest { - newDeviceNotificationUseCase.notifications().test { + newDeviceNotificationUseCase().test { // Arrange, Act awaitItem() newDeviceNotificationUseCase.newDeviceCreated() diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCaseTest.kt index a2e8db36fdbe..20a6a1bef08f 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCaseTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/TunnelStateNotificationUseCaseTest.kt @@ -46,12 +46,12 @@ class TunnelStateNotificationUseCaseTest { @Test fun `initial state should be empty`() = runTest { // Arrange, Act, Assert - tunnelStateNotificationUseCase.notifications().test { assertTrue { awaitItem().isEmpty() } } + tunnelStateNotificationUseCase().test { assertTrue { awaitItem().isEmpty() } } } @Test fun `when TunnelState is error use case should emit TunnelStateError notification`() = runTest { - tunnelStateNotificationUseCase.notifications().test { + tunnelStateNotificationUseCase().test { // Arrange, Act assertEquals(emptyList(), awaitItem()) val errorState: ErrorState = mockk() @@ -65,7 +65,7 @@ class TunnelStateNotificationUseCaseTest { @Test fun `when TunnelState is Disconnecting with blocking use case should emit TunnelStateBlocked notification`() = runTest { - tunnelStateNotificationUseCase.notifications().test { + tunnelStateNotificationUseCase().test { // Arrange, Act assertEquals(emptyList(), awaitItem()) tunnelState.emit(TunnelState.Disconnecting(ActionAfterDisconnect.Block)) diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCaseTest.kt index 1630ed757fb4..9d40f9715ce0 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCaseTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/VersionNotificationUseCaseTest.kt @@ -49,13 +49,13 @@ class VersionNotificationUseCaseTest { @Test fun `initial state should be empty`() = runTest { // Arrange, Act, Assert - versionNotificationUseCase.notifications().test { assertTrue { awaitItem().isEmpty() } } + versionNotificationUseCase().test { assertTrue { awaitItem().isEmpty() } } } @Test fun `when a new version is available use case should emit UpdateAvailable with new version`() = runTest { - versionNotificationUseCase.notifications().test { + versionNotificationUseCase().test { // Arrange, Act val upgradeVersionInfo = VersionInfo( @@ -77,7 +77,7 @@ class VersionNotificationUseCaseTest { @Test fun `when an unsupported version use case should emit UnsupportedVersion notification`() = runTest { - versionNotificationUseCase.notifications().test { + versionNotificationUseCase().test { // Arrange, Act val upgradeVersionInfo = VersionInfo( 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 1717ae6cc40e..f95720de142b 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 @@ -27,7 +27,7 @@ import net.mullvad.mullvadvpn.lib.model.AccountData import net.mullvad.mullvadvpn.lib.model.AccountNumber import net.mullvad.mullvadvpn.lib.model.LoginAccountError import net.mullvad.mullvadvpn.lib.shared.AccountRepository -import net.mullvad.mullvadvpn.usecase.ConnectivityUseCase +import net.mullvad.mullvadvpn.usecase.InternetAvailableUseCase import net.mullvad.mullvadvpn.usecase.NewDeviceNotificationUseCase import org.joda.time.DateTime import org.junit.jupiter.api.Assertions.assertEquals @@ -38,7 +38,7 @@ import org.junit.jupiter.api.extension.ExtendWith @ExtendWith(TestCoroutineRule::class) class LoginViewModelTest { - @MockK private lateinit var connectivityUseCase: ConnectivityUseCase + @MockK private lateinit var connectivityUseCase: InternetAvailableUseCase @MockK private lateinit var mockedAccountRepository: AccountRepository @MockK private lateinit var mockedNewDeviceNotificationUseCase: NewDeviceNotificationUseCase @@ -48,7 +48,7 @@ class LoginViewModelTest { fun setup() { Dispatchers.setMain(UnconfinedTestDispatcher()) MockKAnnotations.init(this, relaxUnitFun = true) - every { connectivityUseCase.isInternetAvailable() } returns true + every { connectivityUseCase() } returns true every { mockedNewDeviceNotificationUseCase.newDeviceCreated() } returns Unit coEvery { mockedAccountRepository.fetchAccountHistory() } returns null @@ -56,7 +56,7 @@ class LoginViewModelTest { LoginViewModel( accountRepository = mockedAccountRepository, newDeviceNotificationUseCase = mockedNewDeviceNotificationUseCase, - connectivityUseCase = connectivityUseCase, + internetAvailableUseCase = connectivityUseCase, UnconfinedTestDispatcher() ) } @@ -65,7 +65,7 @@ class LoginViewModelTest { fun `given no internet when logging in then show no internet error`() = runTest { turbineScope { // Arrange - every { connectivityUseCase.isInternetAvailable() } returns false + every { connectivityUseCase() } returns false val uiStates = loginViewModel.uiState.testIn(backgroundScope) // Act diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt index c917bf18d2ff..ac84d86ea8bf 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/VpnSettingsViewModelTest.kt @@ -28,7 +28,7 @@ import net.mullvad.mullvadvpn.lib.model.WireguardConstraints import net.mullvad.mullvadvpn.lib.model.WireguardTunnelOptions import net.mullvad.mullvadvpn.repository.RelayListRepository import net.mullvad.mullvadvpn.repository.SettingsRepository -import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsUseCase +import net.mullvad.mullvadvpn.usecase.SystemVpnSettingsAvailableUseCase import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -38,7 +38,8 @@ import org.junit.jupiter.api.extension.ExtendWith class VpnSettingsViewModelTest { private val mockSettingsRepository: SettingsRepository = mockk() - private val mockSystemVpnSettingsUseCase: SystemVpnSettingsUseCase = mockk(relaxed = true) + private val mockSystemVpnSettingsUseCase: SystemVpnSettingsAvailableUseCase = + mockk(relaxed = true) private val mockRelayListRepository: RelayListRepository = mockk() private val mockSettingsUpdate = MutableStateFlow(null)