From 316f1efe324c97fe8f8fc86066b65c15792738f5 Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Thu, 13 Oct 2022 15:21:25 +0200 Subject: [PATCH] Updating unit tests --- .../v2/GetDeviceFullInfoListUseCaseTest.kt | 6 ++- .../v2/filter/FilterDevicesUseCaseTest.kt | 39 ++++++++++++++++--- 2 files changed, 37 insertions(+), 8 deletions(-) diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/GetDeviceFullInfoListUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/GetDeviceFullInfoListUseCaseTest.kt index ebdb74b74d..17ad58668a 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/GetDeviceFullInfoListUseCaseTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/GetDeviceFullInfoListUseCaseTest.kt @@ -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()) } } diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/filter/FilterDevicesUseCaseTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/filter/FilterDevicesUseCaseTest.kt index 3a418cf2c0..79dff5bc16 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/filter/FilterDevicesUseCaseTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/filter/FilterDevicesUseCaseTest.kt @@ -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 = "" + ) }