Updating unit tests

This commit is contained in:
Maxime NATUREL 2022-10-13 15:21:25 +02:00
parent 28ce915f18
commit 316f1efe32
2 changed files with 37 additions and 8 deletions

View File

@ -144,10 +144,11 @@ class GetDeviceFullInfoListUseCaseTest {
matrixClientInfo = matrixClientInfo3,
)
val expectedResult = listOf(expectedResult3, expectedResult2, expectedResult1)
every { filterDevicesUseCase.execute(any(), any()) } returns expectedResult
every { filterDevicesUseCase.execute(any(), any(), any()) } returns expectedResult
val filterType = DeviceManagerFilterType.ALL_SESSIONS
// When
val result = getDeviceFullInfoListUseCase.execute(DeviceManagerFilterType.ALL_SESSIONS, excludeCurrentDevice = false)
val result = getDeviceFullInfoListUseCase.execute(filterType, excludeCurrentDevice = false)
.test(this)
// Then
@ -166,6 +167,7 @@ class GetDeviceFullInfoListUseCaseTest {
getMatrixClientInfoUseCase.execute(fakeActiveSessionHolder.fakeSession, A_DEVICE_ID_1)
getMatrixClientInfoUseCase.execute(fakeActiveSessionHolder.fakeSession, A_DEVICE_ID_2)
getMatrixClientInfoUseCase.execute(fakeActiveSessionHolder.fakeSession, A_DEVICE_ID_3)
filterDevicesUseCase.execute(currentSessionCrossSigningInfo, expectedResult, filterType, emptyList())
}
}

View File

@ -20,6 +20,7 @@ import im.vector.app.core.session.clientinfo.MatrixClientInfoContent
import im.vector.app.features.settings.devices.v2.DeviceFullInfo
import im.vector.app.features.settings.devices.v2.details.extended.DeviceExtendedInfo
import im.vector.app.features.settings.devices.v2.list.DeviceType
import im.vector.app.features.settings.devices.v2.verification.CurrentSessionCrossSigningInfo
import org.amshove.kluent.shouldBeEqualTo
import org.amshove.kluent.shouldContainAll
import org.junit.Test
@ -94,32 +95,58 @@ class FilterDevicesUseCaseTest {
@Test
fun `given a device list when filter type is ALL_SESSIONS then returns the same list`() {
val filteredDeviceList = filterDevicesUseCase.execute(devices, DeviceManagerFilterType.ALL_SESSIONS, emptyList())
val currentSessionCrossSigningInfo = givenCurrentSessionVerified(true)
val filteredDeviceList = filterDevicesUseCase.execute(currentSessionCrossSigningInfo, devices, DeviceManagerFilterType.ALL_SESSIONS, emptyList())
filteredDeviceList.size shouldBeEqualTo devices.size
}
@Test
fun `given a device list when filter type is VERIFIED then returns only verified devices`() {
val filteredDeviceList = filterDevicesUseCase.execute(devices, DeviceManagerFilterType.VERIFIED, emptyList())
fun `given a device list and current session is verified when filter type is VERIFIED then returns only verified devices`() {
val currentSessionCrossSigningInfo = givenCurrentSessionVerified(true)
val filteredDeviceList = filterDevicesUseCase.execute(currentSessionCrossSigningInfo, devices, DeviceManagerFilterType.VERIFIED, emptyList())
filteredDeviceList.size shouldBeEqualTo 2
filteredDeviceList shouldContainAll listOf(activeVerifiedDevice, inactiveVerifiedDevice)
}
@Test
fun `given a device list when filter type is UNVERIFIED then returns only unverified devices`() {
val filteredDeviceList = filterDevicesUseCase.execute(devices, DeviceManagerFilterType.UNVERIFIED, emptyList())
fun `given a device list and current session is unverified when filter type is VERIFIED then returns empty list of devices`() {
val currentSessionCrossSigningInfo = givenCurrentSessionVerified(false)
val filteredDeviceList = filterDevicesUseCase.execute(currentSessionCrossSigningInfo, devices, DeviceManagerFilterType.VERIFIED, emptyList())
filteredDeviceList.size shouldBeEqualTo 0
}
@Test
fun `given a device list and current session is verified when filter type is UNVERIFIED then returns only unverified devices`() {
val currentSessionCrossSigningInfo = givenCurrentSessionVerified(true)
val filteredDeviceList = filterDevicesUseCase.execute(currentSessionCrossSigningInfo, devices, DeviceManagerFilterType.UNVERIFIED, emptyList())
filteredDeviceList.size shouldBeEqualTo 2
filteredDeviceList shouldContainAll listOf(activeUnverifiedDevice, inactiveUnverifiedDevice)
}
@Test
fun `given a device list and current session is unverified when filter type is UNVERIFIED then returns empty list of devices`() {
val currentSessionCrossSigningInfo = givenCurrentSessionVerified(false)
val filteredDeviceList = filterDevicesUseCase.execute(currentSessionCrossSigningInfo, devices, DeviceManagerFilterType.UNVERIFIED, emptyList())
filteredDeviceList.size shouldBeEqualTo 0
}
@Test
fun `given a device list when filter type is INACTIVE then returns only inactive devices`() {
val filteredDeviceList = filterDevicesUseCase.execute(devices, DeviceManagerFilterType.INACTIVE, emptyList())
val currentSessionCrossSigningInfo = givenCurrentSessionVerified(true)
val filteredDeviceList = filterDevicesUseCase.execute(currentSessionCrossSigningInfo, devices, DeviceManagerFilterType.INACTIVE, emptyList())
filteredDeviceList.size shouldBeEqualTo 2
filteredDeviceList shouldContainAll listOf(inactiveVerifiedDevice, inactiveUnverifiedDevice)
}
private fun givenCurrentSessionVerified(isVerified: Boolean): CurrentSessionCrossSigningInfo = CurrentSessionCrossSigningInfo(
isCrossSigningVerified = isVerified,
isCrossSigningInitialized = true,
deviceId = ""
)
}