Checking lab flag before updating the client info

This commit is contained in:
Maxime NATUREL 2022-10-12 16:00:32 +02:00
parent f753e475d8
commit 8b30ab69c5
3 changed files with 34 additions and 2 deletions

View file

@ -21,6 +21,7 @@ import dagger.hilt.android.qualifiers.ApplicationContext
import im.vector.app.core.extensions.startSyncing import im.vector.app.core.extensions.startSyncing
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
import im.vector.app.features.call.webrtc.WebRtcCallManager import im.vector.app.features.call.webrtc.WebRtcCallManager
import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.api.session.sync.FilterService import org.matrix.android.sdk.api.session.sync.FilterService
import timber.log.Timber import timber.log.Timber
@ -30,6 +31,7 @@ class ConfigureAndStartSessionUseCase @Inject constructor(
@ApplicationContext private val context: Context, @ApplicationContext private val context: Context,
private val webRtcCallManager: WebRtcCallManager, private val webRtcCallManager: WebRtcCallManager,
private val updateMatrixClientInfoUseCase: UpdateMatrixClientInfoUseCase, private val updateMatrixClientInfoUseCase: UpdateMatrixClientInfoUseCase,
private val vectorPreferences: VectorPreferences,
) { ) {
suspend fun execute(session: Session, startSyncing: Boolean = true) { suspend fun execute(session: Session, startSyncing: Boolean = true) {
@ -41,6 +43,8 @@ class ConfigureAndStartSessionUseCase @Inject constructor(
} }
session.pushersService().refreshPushers() session.pushersService().refreshPushers()
webRtcCallManager.checkForProtocolsSupportIfNeeded() webRtcCallManager.checkForProtocolsSupportIfNeeded()
updateMatrixClientInfoUseCase.execute(session) if (vectorPreferences.isClientInfoRecordingEnabled()) {
updateMatrixClientInfoUseCase.execute(session)
}
} }
} }

View file

@ -20,6 +20,7 @@ import im.vector.app.core.extensions.startSyncing
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
import im.vector.app.test.fakes.FakeContext import im.vector.app.test.fakes.FakeContext
import im.vector.app.test.fakes.FakeSession import im.vector.app.test.fakes.FakeSession
import im.vector.app.test.fakes.FakeVectorPreferences
import im.vector.app.test.fakes.FakeWebRtcCallManager import im.vector.app.test.fakes.FakeWebRtcCallManager
import io.mockk.coJustRun import io.mockk.coJustRun
import io.mockk.coVerify import io.mockk.coVerify
@ -41,11 +42,13 @@ class ConfigureAndStartSessionUseCaseTest {
private val fakeContext = FakeContext() private val fakeContext = FakeContext()
private val fakeWebRtcCallManager = FakeWebRtcCallManager() private val fakeWebRtcCallManager = FakeWebRtcCallManager()
private val fakeUpdateMatrixClientInfoUseCase = mockk<UpdateMatrixClientInfoUseCase>() private val fakeUpdateMatrixClientInfoUseCase = mockk<UpdateMatrixClientInfoUseCase>()
private val fakeVectorPreferences = FakeVectorPreferences()
private val configureAndStartSessionUseCase = ConfigureAndStartSessionUseCase( private val configureAndStartSessionUseCase = ConfigureAndStartSessionUseCase(
context = fakeContext.instance, context = fakeContext.instance,
webRtcCallManager = fakeWebRtcCallManager.instance, webRtcCallManager = fakeWebRtcCallManager.instance,
updateMatrixClientInfoUseCase = fakeUpdateMatrixClientInfoUseCase, updateMatrixClientInfoUseCase = fakeUpdateMatrixClientInfoUseCase,
vectorPreferences = fakeVectorPreferences.instance,
) )
@Before @Before
@ -59,11 +62,12 @@ class ConfigureAndStartSessionUseCaseTest {
} }
@Test @Test
fun `given a session and start sync needed when configuring and starting the session then it should be configured properly`() = runTest { fun `given start sync needed and client info recording enabled when configuring and starting the session then it should be configured properly`() = runTest {
// Given // Given
val fakeSession = givenASession() val fakeSession = givenASession()
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds() fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) } coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = true)
// When // When
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = true) configureAndStartSessionUseCase.execute(fakeSession, startSyncing = true)
@ -76,12 +80,32 @@ class ConfigureAndStartSessionUseCaseTest {
coVerify { fakeUpdateMatrixClientInfoUseCase.execute(fakeSession) } coVerify { fakeUpdateMatrixClientInfoUseCase.execute(fakeSession) }
} }
@Test
fun `given start sync needed and client info recording disabled when configuring and starting the session then it should be configured properly`() = runTest {
// Given
val fakeSession = givenASession()
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = false)
// When
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = true)
// Then
verify { fakeSession.startSyncing(fakeContext.instance) }
fakeSession.fakeFilterService.verifySetFilter(FilterService.FilterPreset.ElementFilter)
fakeSession.fakePushersService.verifyRefreshPushers()
fakeWebRtcCallManager.verifyCheckForProtocolsSupportIfNeeded()
coVerify(inverse = true) { fakeUpdateMatrixClientInfoUseCase.execute(fakeSession) }
}
@Test @Test
fun `given a session and no start sync needed when configuring and starting the session then it should be configured properly`() = runTest { fun `given a session and no start sync needed when configuring and starting the session then it should be configured properly`() = runTest {
// Given // Given
val fakeSession = givenASession() val fakeSession = givenASession()
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds() fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) } coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = true)
// When // When
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = false) configureAndStartSessionUseCase.execute(fakeSession, startSyncing = false)

View file

@ -36,4 +36,8 @@ class FakeVectorPreferences {
fun verifySetSpaceBackstack(value: List<String?>, inverse: Boolean = false) { fun verifySetSpaceBackstack(value: List<String?>, inverse: Boolean = false) {
verify(inverse = inverse) { instance.setSpaceBackstack(value) } verify(inverse = inverse) { instance.setSpaceBackstack(value) }
} }
fun givenIsClientInfoRecordingEnabled(isEnabled: Boolean) {
every { instance.isClientInfoRecordingEnabled() } returns isEnabled
}
} }