diff options
| author | David Göransson <david.goransson@mullvad.net> | 2024-04-16 14:21:40 +0200 |
|---|---|---|
| committer | David Göransson <david.goransson@mullvad.net> | 2024-04-16 14:21:40 +0200 |
| commit | b9a59074141024a9d40723dca5c58cfe15fccbbc (patch) | |
| tree | 012d88915f34106e28b316d541d9c7409f3675f9 /android/app/src/test | |
| parent | c1d3d100074a73351bfa1fdde2ffd26dc759e9c5 (diff) | |
| parent | a8f5a9097d20448774828cd3349f5bbc228843f6 (diff) | |
| download | mullvadvpn-b9a59074141024a9d40723dca5c58cfe15fccbbc.tar.xz mullvadvpn-b9a59074141024a9d40723dca5c58cfe15fccbbc.zip | |
Merge branch 'custom-list-name-is-not-being-trimmed-droid-902'
Diffstat (limited to 'android/app/src/test')
3 files changed, 34 insertions, 16 deletions
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepositoryTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepositoryTest.kt index 129d921c36..9c2ac615c3 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepositoryTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/repository/CustomListsRepositoryTest.kt @@ -13,6 +13,7 @@ import net.mullvad.mullvadvpn.lib.ipc.Request import net.mullvad.mullvadvpn.lib.ipc.events import net.mullvad.mullvadvpn.model.CreateCustomListResult import net.mullvad.mullvadvpn.model.CustomList +import net.mullvad.mullvadvpn.model.CustomListName import net.mullvad.mullvadvpn.model.CustomListsError import net.mullvad.mullvadvpn.model.GeographicLocationConstraint import net.mullvad.mullvadvpn.model.RelayList @@ -94,7 +95,8 @@ class CustomListsRepositoryTest { flowOf(Event.CreateCustomListResultEvent(expectedResult)) // Act - val result = customListsRepository.createCustomList(customListName) + val result = + customListsRepository.createCustomList(CustomListName.fromString(customListName)) // Assert assertEquals(expectedResult, result) @@ -113,7 +115,8 @@ class CustomListsRepositoryTest { flowOf(Event.CreateCustomListResultEvent(expectedResult)) // Act - val result = customListsRepository.createCustomList(customListName) + val result = + customListsRepository.createCustomList(CustomListName.fromString(customListName)) // Assert assertEquals(expectedResult, result) @@ -139,7 +142,11 @@ class CustomListsRepositoryTest { every { mockSettings.customLists.customLists } returns arrayListOf(mockCustomList) // Act - val result = customListsRepository.updateCustomListName(customListId, customListName) + val result = + customListsRepository.updateCustomListName( + customListId, + CustomListName.fromString(customListName) + ) // Assert assertEquals(expectedResult, result) @@ -167,7 +174,11 @@ class CustomListsRepositoryTest { every { mockSettings.customLists.customLists } returns arrayListOf(mockCustomList) // Act - val result = customListsRepository.updateCustomListName(customListId, customListName) + val result = + customListsRepository.updateCustomListName( + customListId, + CustomListName.fromString(customListName) + ) // Assert assertEquals(expectedResult, result) 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 0370f23ffb..fdcb4170f0 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 @@ -11,6 +11,7 @@ import net.mullvad.mullvadvpn.compose.communication.CustomListAction import net.mullvad.mullvadvpn.compose.communication.CustomListResult import net.mullvad.mullvadvpn.model.CreateCustomListResult import net.mullvad.mullvadvpn.model.CustomList +import net.mullvad.mullvadvpn.model.CustomListName import net.mullvad.mullvadvpn.model.CustomListsError import net.mullvad.mullvadvpn.model.GeographicLocationConstraint import net.mullvad.mullvadvpn.model.UpdateCustomListResult @@ -40,7 +41,7 @@ class CustomListActionUseCaseTest { @Test fun `create action should return success when ok`() = runTest { // Arrange - val name = "test" + val name = CustomListName.fromString("test") val locationCode = "AB" val locationName = "Acklaba" val createdId = "1" @@ -83,7 +84,7 @@ class CustomListActionUseCaseTest { @Test fun `create action should return error when name already exists`() = runTest { // Arrange - val name = "test" + val name = CustomListName.fromString("test") val locationCode = "AB" val action = CustomListAction.Create(name = name, locations = listOf(locationCode)) val expectedError = CustomListsError.CustomListExists @@ -103,8 +104,8 @@ class CustomListActionUseCaseTest { @Test fun `rename action should return success when ok`() = runTest { // Arrange - val name = "test" - val newName = "test2" + val name = CustomListName.fromString("test") + val newName = CustomListName.fromString("test2") val customListId = "1" val action = CustomListAction.Rename(customListId = customListId, name = name, newName = newName) @@ -123,8 +124,8 @@ class CustomListActionUseCaseTest { @Test fun `rename action should return error when name already exists`() = runTest { // Arrange - val name = "test" - val newName = "test2" + val name = CustomListName.fromString("test") + val newName = CustomListName.fromString("test2") val customListId = "1" val action = CustomListAction.Rename(customListId = customListId, name = name, newName = newName) @@ -149,7 +150,7 @@ class CustomListActionUseCaseTest { val mockCustomList: CustomList = mockk() val mockLocation: GeographicLocationConstraint.Country = mockk() val mockLocations: ArrayList<GeographicLocationConstraint> = arrayListOf(mockLocation) - val name = "test" + val name = CustomListName.fromString("test") val customListId = "1" val locationCode = "AB" val action = CustomListAction.Delete(customListId = customListId) @@ -160,7 +161,7 @@ class CustomListActionUseCaseTest { ) ) every { mockCustomList.locations } returns mockLocations - every { mockCustomList.name } returns name + every { mockCustomList.name } returns name.value every { mockLocation.countryCode } returns locationCode coEvery { mockCustomListsRepository.deleteCustomList(id = customListId) } returns true every { mockCustomListsRepository.getCustomListById(customListId) } returns mockCustomList @@ -175,7 +176,7 @@ class CustomListActionUseCaseTest { @Test fun `update locations action should return success with changed locations`() = runTest { // Arrange - val name = "test" + val name = CustomListName.fromString("test") val oldLocationCodes = listOf("AB", "CD") val newLocationCodes = listOf("EF", "GH") val oldLocations: ArrayList<GeographicLocationConstraint> = @@ -184,7 +185,7 @@ class CustomListActionUseCaseTest { GeographicLocationConstraint.Country("CD") ) val customListId = "1" - val customList = CustomList(id = customListId, name = name, locations = oldLocations) + val customList = CustomList(id = customListId, name = name.value, locations = oldLocations) val action = CustomListAction.UpdateLocations( customListId = customListId, diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListViewModelTest.kt index 33986961b3..cbc5ff1c50 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/EditCustomListViewModelTest.kt @@ -8,6 +8,7 @@ import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.test.runTest import net.mullvad.mullvadvpn.compose.state.EditCustomListState import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule +import net.mullvad.mullvadvpn.model.CustomListName import net.mullvad.mullvadvpn.relaylist.RelayItem import net.mullvad.mullvadvpn.usecase.RelayListUseCase import org.junit.jupiter.api.Assertions.assertEquals @@ -23,7 +24,12 @@ class EditCustomListViewModelTest { // Arrange val customListId = "2" val customList = - RelayItem.CustomList(id = "1", name = "test", expanded = false, locations = emptyList()) + RelayItem.CustomList( + id = "1", + customListName = CustomListName.fromString("test"), + expanded = false, + locations = emptyList() + ) every { mockRelayListUseCase.customLists() } returns flowOf(listOf(customList)) val viewModel = createViewModel(customListId) @@ -41,7 +47,7 @@ class EditCustomListViewModelTest { val customList = RelayItem.CustomList( id = customListId, - name = "test", + customListName = CustomListName.fromString("test"), expanded = false, locations = emptyList() ) |
