Skip to content

Commit ba167ea

Browse files
committed
Updated and fixed tests
1 parent 8d23e02 commit ba167ea

File tree

2 files changed

+44
-45
lines changed

2 files changed

+44
-45
lines changed

android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt

+40-41
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CustomListActionUseCaseTest {
3838
}
3939

4040
@Test
41-
fun `give action create when successful should return created result`() = runTest {
41+
fun `create action should return success when ok`() = runTest {
4242
// Arrange
4343
val name = "test"
4444
val locationCode = "AB"
@@ -81,7 +81,7 @@ class CustomListActionUseCaseTest {
8181
}
8282

8383
@Test
84-
fun `give action create when list name already exits should return error`() = runTest {
84+
fun `create action should return error when name already exists`() = runTest {
8585
// Arrange
8686
val name = "test"
8787
val locationCode = "AB"
@@ -101,7 +101,7 @@ class CustomListActionUseCaseTest {
101101
}
102102

103103
@Test
104-
fun `give action rename when successful should return rename result`() = runTest {
104+
fun `rename action should return success when ok`() = runTest {
105105
// Arrange
106106
val name = "test"
107107
val newName = "test2"
@@ -121,7 +121,7 @@ class CustomListActionUseCaseTest {
121121
}
122122

123123
@Test
124-
fun `give action rename when list name already exists should return error`() = runTest {
124+
fun `rename action should return error when name already exists`() = runTest {
125125
// Arrange
126126
val name = "test"
127127
val newName = "test2"
@@ -144,7 +144,7 @@ class CustomListActionUseCaseTest {
144144
}
145145

146146
@Test
147-
fun `give action delete when successful should return delete result`() = runTest {
147+
fun `delete action should return successful with deleted list`() = runTest {
148148
// Arrange
149149
val mockCustomList: CustomList = mockk()
150150
val mockLocation: GeographicLocationConstraint.Country = mockk()
@@ -173,46 +173,45 @@ class CustomListActionUseCaseTest {
173173
}
174174

175175
@Test
176-
fun `give action update locations when successful should return locations changed result`() =
177-
runTest {
178-
// Arrange
179-
val name = "test"
180-
val oldLocationCodes = listOf("AB", "CD")
181-
val newLocationCodes = listOf("EF", "GH")
182-
val oldLocations: ArrayList<GeographicLocationConstraint> =
183-
arrayListOf(
184-
GeographicLocationConstraint.Country("AB"),
185-
GeographicLocationConstraint.Country("CD")
186-
)
187-
val customListId = "1"
188-
val customList = CustomList(id = customListId, name = name, locations = oldLocations)
189-
val action =
190-
CustomListAction.UpdateLocations(
191-
customListId = customListId,
192-
locations = newLocationCodes
193-
)
194-
val expectedResult =
195-
Result.success(
196-
CustomListResult.LocationsChanged(
197-
name = name,
198-
undo = action.not(locations = oldLocationCodes)
199-
)
176+
fun `update locations action should return success with changed locations`() = runTest {
177+
// Arrange
178+
val name = "test"
179+
val oldLocationCodes = listOf("AB", "CD")
180+
val newLocationCodes = listOf("EF", "GH")
181+
val oldLocations: ArrayList<GeographicLocationConstraint> =
182+
arrayListOf(
183+
GeographicLocationConstraint.Country("AB"),
184+
GeographicLocationConstraint.Country("CD")
185+
)
186+
val customListId = "1"
187+
val customList = CustomList(id = customListId, name = name, locations = oldLocations)
188+
val action =
189+
CustomListAction.UpdateLocations(
190+
customListId = customListId,
191+
locations = newLocationCodes
192+
)
193+
val expectedResult =
194+
Result.success(
195+
CustomListResult.LocationsChanged(
196+
name = name,
197+
undo = action.not(locations = oldLocationCodes)
200198
)
201-
coEvery { mockCustomListsRepository.getCustomListById(customListId) } returns customList
199+
)
200+
coEvery { mockCustomListsRepository.getCustomListById(customListId) } returns customList
202201

203-
coEvery {
204-
mockCustomListsRepository.updateCustomListLocationsFromCodes(
205-
customListId,
206-
newLocationCodes
207-
)
208-
} returns UpdateCustomListResult.Ok
202+
coEvery {
203+
mockCustomListsRepository.updateCustomListLocationsFromCodes(
204+
customListId,
205+
newLocationCodes
206+
)
207+
} returns UpdateCustomListResult.Ok
209208

210-
// Act
211-
val result = customListActionUseCase.performAction(action)
209+
// Act
210+
val result = customListActionUseCase.performAction(action)
212211

213-
// Assert
214-
assertEquals(expectedResult, result)
215-
}
212+
// Assert
213+
assertEquals(expectedResult, result)
214+
}
216215

217216
companion object {
218217
private const val RELAY_LIST_EXTENSIONS =

android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState
1313
import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule
1414
import net.mullvad.mullvadvpn.model.GeographicLocationConstraint
1515
import net.mullvad.mullvadvpn.relaylist.RelayItem
16-
import net.mullvad.mullvadvpn.relaylist.allChildren
16+
import net.mullvad.mullvadvpn.relaylist.descendants
1717
import net.mullvad.mullvadvpn.usecase.RelayListUseCase
1818
import net.mullvad.mullvadvpn.usecase.customlists.CustomListActionUseCase
1919
import org.junit.jupiter.api.Assertions.assertEquals
@@ -83,7 +83,7 @@ class CustomListLocationsViewModelTest {
8383
}
8484
customListFlow.value = listOf(customList)
8585
val expectedSelection =
86-
(DUMMY_COUNTRIES + DUMMY_COUNTRIES.flatMap { it.allChildren() }).toSet()
86+
(DUMMY_COUNTRIES + DUMMY_COUNTRIES.flatMap { it.descendants() }).toSet()
8787
val viewModel = createViewModel(customListId, true)
8888
relayListFlow.value = expectedList
8989

@@ -106,7 +106,7 @@ class CustomListLocationsViewModelTest {
106106
// Arrange
107107
val expectedList = DUMMY_COUNTRIES
108108
val initialSelection =
109-
(DUMMY_COUNTRIES + DUMMY_COUNTRIES.flatMap { it.allChildren() }).toSet()
109+
(DUMMY_COUNTRIES + DUMMY_COUNTRIES.flatMap { it.descendants() }).toSet()
110110
val customListId = "id"
111111
val customListName = "name"
112112
val customList: RelayItem.CustomList = mockk {
@@ -138,7 +138,7 @@ class CustomListLocationsViewModelTest {
138138
// Arrange
139139
val expectedList = DUMMY_COUNTRIES
140140
val initialSelection =
141-
(DUMMY_COUNTRIES + DUMMY_COUNTRIES.flatMap { it.allChildren() }).toSet()
141+
(DUMMY_COUNTRIES + DUMMY_COUNTRIES.flatMap { it.descendants() }).toSet()
142142
val customListId = "id"
143143
val customListName = "name"
144144
val customList: RelayItem.CustomList = mockk {

0 commit comments

Comments
 (0)