Change signature of selectPushProvider and add missing unit test.

This commit is contained in:
Benoit Marty 2024-11-15 15:13:24 +01:00
parent d97d561b13
commit 500659d4e1
6 changed files with 27 additions and 11 deletions

View file

@ -142,7 +142,7 @@ class LoggedInPresenter @Inject constructor(
.also { Timber.tag(pusherTag.value).w("No distributors available") } .also { Timber.tag(pusherTag.value).w("No distributors available") }
.also { .also {
// In this case, consider the push provider is chosen. // In this case, consider the push provider is chosen.
pushService.selectPushProvider(matrixClient, pushProvider) pushService.selectPushProvider(matrixClient.sessionId, pushProvider)
} }
.also { pusherRegistrationState.value = AsyncData.Failure(PusherRegistrationFailure.NoDistributorsAvailable()) } .also { pusherRegistrationState.value = AsyncData.Failure(PusherRegistrationFailure.NoDistributorsAvailable()) }
pushService.registerWith(matrixClient, pushProvider, distributor) pushService.registerWith(matrixClient, pushProvider, distributor)

View file

@ -378,7 +378,7 @@ class LoggedInPresenterTest {
val lambda = lambdaRecorder<MatrixClient, PushProvider, Distributor, Result<Unit>> { _, _, _ -> val lambda = lambdaRecorder<MatrixClient, PushProvider, Distributor, Result<Unit>> { _, _, _ ->
Result.success(Unit) Result.success(Unit)
} }
val selectPushProviderLambda = lambdaRecorder<MatrixClient, PushProvider, Unit> { _, _ -> } val selectPushProviderLambda = lambdaRecorder<SessionId, PushProvider, Unit> { _, _ -> }
val sessionVerificationService = FakeSessionVerificationService( val sessionVerificationService = FakeSessionVerificationService(
initialSessionVerifiedStatus = SessionVerifiedStatus.Verified initialSessionVerifiedStatus = SessionVerifiedStatus.Verified
) )
@ -408,8 +408,8 @@ class LoggedInPresenterTest {
selectPushProviderLambda.assertions() selectPushProviderLambda.assertions()
.isCalledOnce() .isCalledOnce()
.with( .with(
// MatrixClient // SessionId
any(), value(A_SESSION_ID),
// PushProvider // PushProvider
value(pushProvider), value(pushProvider),
) )
@ -481,7 +481,7 @@ class LoggedInPresenterTest {
registerWithLambda: (MatrixClient, PushProvider, Distributor) -> Result<Unit> = { _, _, _ -> registerWithLambda: (MatrixClient, PushProvider, Distributor) -> Result<Unit> = { _, _, _ ->
Result.success(Unit) Result.success(Unit)
}, },
selectPushProviderLambda: (MatrixClient, PushProvider) -> Unit = { _, _ -> lambdaError() }, selectPushProviderLambda: (SessionId, PushProvider) -> Unit = { _, _ -> lambdaError() },
currentPushProvider: () -> PushProvider? = { null }, currentPushProvider: () -> PushProvider? = { null },
setIgnoreRegistrationErrorLambda: (SessionId, Boolean) -> Unit = { _, _ -> lambdaError() }, setIgnoreRegistrationErrorLambda: (SessionId, Boolean) -> Unit = { _, _ -> lambdaError() },
): PushService { ): PushService {

View file

@ -40,7 +40,7 @@ interface PushService {
* To be used when there is no distributor available. * To be used when there is no distributor available.
*/ */
suspend fun selectPushProvider( suspend fun selectPushProvider(
matrixClient: MatrixClient, sessionId: SessionId,
pushProvider: PushProvider, pushProvider: PushProvider,
) )

View file

@ -76,11 +76,11 @@ class DefaultPushService @Inject constructor(
} }
override suspend fun selectPushProvider( override suspend fun selectPushProvider(
matrixClient: MatrixClient, sessionId: SessionId,
pushProvider: PushProvider, pushProvider: PushProvider,
) { ) {
Timber.d("Select ${pushProvider.name}") Timber.d("Select ${pushProvider.name}")
val userPushStore = userPushStoreFactory.getOrCreate(matrixClient.sessionId) val userPushStore = userPushStoreFactory.getOrCreate(sessionId)
userPushStore.setPushProviderName(pushProvider.name) userPushStore.setPushProviderName(pushProvider.name)
} }

View file

@ -265,6 +265,22 @@ class DefaultPushServiceTest {
assertThat(pushClientSecretStore.getSecret(A_SESSION_ID)).isNull() assertThat(pushClientSecretStore.getSecret(A_SESSION_ID)).isNull()
} }
@Test
fun `selectPushProvider should store the data in the store`() = runTest {
val userPushStore = FakeUserPushStore()
val defaultPushService = createDefaultPushService(
userPushStoreFactory = FakeUserPushStoreFactory(
userPushStore = { userPushStore },
),
)
val aPushProvider = FakePushProvider(
name = "aCurrentPushProvider",
)
assertThat(userPushStore.getPushProviderName()).isNull()
defaultPushService.selectPushProvider(A_SESSION_ID, aPushProvider)
assertThat(userPushStore.getPushProviderName()).isEqualTo(aPushProvider.name)
}
private fun createDefaultPushService( private fun createDefaultPushService(
testPush: TestPush = FakeTestPush(), testPush: TestPush = FakeTestPush(),
userPushStoreFactory: UserPushStoreFactory = FakeUserPushStoreFactory(), userPushStoreFactory: UserPushStoreFactory = FakeUserPushStoreFactory(),

View file

@ -24,7 +24,7 @@ class FakePushService(
Result.success(Unit) Result.success(Unit)
}, },
private val currentPushProvider: () -> PushProvider? = { availablePushProviders.firstOrNull() }, private val currentPushProvider: () -> PushProvider? = { availablePushProviders.firstOrNull() },
private val selectPushProviderLambda: suspend (MatrixClient, PushProvider) -> Unit = { _, _ -> lambdaError() }, private val selectPushProviderLambda: suspend (SessionId, PushProvider) -> Unit = { _, _ -> lambdaError() },
private val setIgnoreRegistrationErrorLambda: (SessionId, Boolean) -> Unit = { _, _ -> lambdaError() }, private val setIgnoreRegistrationErrorLambda: (SessionId, Boolean) -> Unit = { _, _ -> lambdaError() },
) : PushService { ) : PushService {
override suspend fun getCurrentPushProvider(): PushProvider? { override suspend fun getCurrentPushProvider(): PushProvider? {
@ -50,8 +50,8 @@ class FakePushService(
} }
} }
override suspend fun selectPushProvider(matrixClient: MatrixClient, pushProvider: PushProvider) { override suspend fun selectPushProvider(sessionId: SessionId, pushProvider: PushProvider) {
selectPushProviderLambda(matrixClient, pushProvider) selectPushProviderLambda(sessionId, pushProvider)
} }
private val ignoreRegistrationError = MutableStateFlow(false) private val ignoreRegistrationError = MutableStateFlow(false)