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.session.clientinfo.UpdateMatrixClientInfoUseCase
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.sync.FilterService
import timber.log.Timber
@ -30,6 +31,7 @@ class ConfigureAndStartSessionUseCase @Inject constructor(
@ApplicationContext private val context: Context,
private val webRtcCallManager: WebRtcCallManager,
private val updateMatrixClientInfoUseCase: UpdateMatrixClientInfoUseCase,
private val vectorPreferences: VectorPreferences,
) {
suspend fun execute(session: Session, startSyncing: Boolean = true) {
@ -41,6 +43,8 @@ class ConfigureAndStartSessionUseCase @Inject constructor(
}
session.pushersService().refreshPushers()
webRtcCallManager.checkForProtocolsSupportIfNeeded()
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.test.fakes.FakeContext
import im.vector.app.test.fakes.FakeSession
import im.vector.app.test.fakes.FakeVectorPreferences
import im.vector.app.test.fakes.FakeWebRtcCallManager
import io.mockk.coJustRun
import io.mockk.coVerify
@ -41,11 +42,13 @@ class ConfigureAndStartSessionUseCaseTest {
private val fakeContext = FakeContext()
private val fakeWebRtcCallManager = FakeWebRtcCallManager()
private val fakeUpdateMatrixClientInfoUseCase = mockk<UpdateMatrixClientInfoUseCase>()
private val fakeVectorPreferences = FakeVectorPreferences()
private val configureAndStartSessionUseCase = ConfigureAndStartSessionUseCase(
context = fakeContext.instance,
webRtcCallManager = fakeWebRtcCallManager.instance,
updateMatrixClientInfoUseCase = fakeUpdateMatrixClientInfoUseCase,
vectorPreferences = fakeVectorPreferences.instance,
)
@Before
@ -59,11 +62,12 @@ class ConfigureAndStartSessionUseCaseTest {
}
@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
val fakeSession = givenASession()
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = true)
// When
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = true)
@ -76,12 +80,32 @@ class ConfigureAndStartSessionUseCaseTest {
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
fun `given a session and no start sync needed 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 = true)
// When
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = false)

View File

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