diff options
| author | David Göransson <david.goransson@mullvad.net> | 2025-04-17 10:35:21 +0200 |
|---|---|---|
| committer | David Göransson <david.goransson@mullvad.net> | 2025-04-17 16:17:54 +0200 |
| commit | 0bcf6d3b84c5ab1505ae370252a1d541baee70f2 (patch) | |
| tree | 2f71dd6330c3fc15f00d6873b68fc14695791445 /android | |
| parent | d1b0564fc8c1d335cd107707250a514b741ee555 (diff) | |
| download | mullvadvpn-0bcf6d3b84c5ab1505ae370252a1d541baee70f2.tar.xz mullvadvpn-0bcf6d3b84c5ab1505ae370252a1d541baee70f2.zip | |
Fix test
Diffstat (limited to 'android')
| -rw-r--r-- | android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt | 22 | ||||
| -rw-r--r-- | android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt | 4 |
2 files changed, 14 insertions, 12 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt index fe822e489b..32dd9a8e0e 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepository.kt @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.repository import arrow.core.Either import arrow.core.raise.either +import co.touchlab.kermit.Logger import kotlinx.coroutines.CoroutineDispatcher import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -9,7 +10,6 @@ import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.stateIn -import net.mullvad.mullvadvpn.lib.common.util.firstOrNullWithTimeout import net.mullvad.mullvadvpn.lib.daemon.grpc.ManagementService import net.mullvad.mullvadvpn.lib.model.CustomList import net.mullvad.mullvadvpn.lib.model.CustomListId @@ -55,15 +55,15 @@ class CustomListsRepository( .bind() } - suspend fun getCustomListById(id: CustomListId): Either<GetCustomListError, CustomList> = - either { - customLists.firstOrNullWithTimeout(GET_CUSTOM_LIST_TIMEOUT_MS)?.find { customList -> - customList.id == id - } ?: raise(GetCustomListError(id)) - } - .mapLeft { GetCustomListError(id) } - - companion object { - private const val GET_CUSTOM_LIST_TIMEOUT_MS = 5000L + /** + * There is no guarantee this will return a up to date custom list. E.g if you invoked + * updateCustomList just before this you might get an out of date value. + */ + fun getCustomListById(id: CustomListId): Either<GetCustomListError, CustomList> = either { + val customLists = + customLists.value + ?: raise(GetCustomListError(id)).also { Logger.e("Custom lists never loaded") } + customLists.firstOrNull { customList -> customList.id == id } + ?: raise(GetCustomListError(id)) } } 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 233d429bc4..03d46cbde0 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 @@ -64,7 +64,9 @@ class CustomListActionUseCaseTest { .right() coEvery { mockCustomListsRepository.createCustomList(name) } returns createdId.right() coEvery { - mockCustomListsRepository.updateCustomListLocations(createdId, listOf(locationId)) + mockCustomListsRepository.updateCustomList( + CustomList(createdId, name, listOf(locationId)) + ) } returns Unit.right() relayListFlow.value = listOf( |
