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 {
// 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()) }
pushService.registerWith(matrixClient, pushProvider, distributor)

View file

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

View file

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

View file

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

View file

@ -265,6 +265,22 @@ class DefaultPushServiceTest {
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(
testPush: TestPush = FakeTestPush(),
userPushStoreFactory: UserPushStoreFactory = FakeUserPushStoreFactory(),

View file

@ -24,7 +24,7 @@ class FakePushService(
Result.success(Unit)
},
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() },
) : PushService {
override suspend fun getCurrentPushProvider(): PushProvider? {
@ -50,8 +50,8 @@ class FakePushService(
}
}
override suspend fun selectPushProvider(matrixClient: MatrixClient, pushProvider: PushProvider) {
selectPushProviderLambda(matrixClient, pushProvider)
override suspend fun selectPushProvider(sessionId: SessionId, pushProvider: PushProvider) {
selectPushProviderLambda(sessionId, pushProvider)
}
private val ignoreRegistrationError = MutableStateFlow(false)