Improve current push provider test: give info about the distributor.
This commit is contained in:
@@ -24,6 +24,11 @@ interface PushProvider {
|
||||
*/
|
||||
val name: String
|
||||
|
||||
/**
|
||||
* true if the Push provider supports multiple distributors.
|
||||
*/
|
||||
val supportMultipleDistributors: Boolean
|
||||
|
||||
/**
|
||||
* Return the list of available distributors.
|
||||
*/
|
||||
@@ -34,6 +39,11 @@ interface PushProvider {
|
||||
*/
|
||||
suspend fun registerWith(matrixClient: MatrixClient, distributor: Distributor): Result<Unit>
|
||||
|
||||
/**
|
||||
* Return the current distributor, or null if none.
|
||||
*/
|
||||
suspend fun getCurrentDistributorValue(sessionId: SessionId): String?
|
||||
|
||||
/**
|
||||
* Return the current distributor, or null if none.
|
||||
*/
|
||||
|
||||
@@ -32,6 +32,7 @@ class FirebasePushProvider(
|
||||
) : PushProvider {
|
||||
override val index = FirebaseConfig.INDEX
|
||||
override val name = FirebaseConfig.NAME
|
||||
override val supportMultipleDistributors = false
|
||||
|
||||
override fun getDistributors(): List<Distributor> {
|
||||
return listOfNotNull(
|
||||
@@ -54,6 +55,8 @@ class FirebasePushProvider(
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun getCurrentDistributorValue(sessionId: SessionId): String = firebaseDistributor.value
|
||||
|
||||
override suspend fun getCurrentDistributor(sessionId: SessionId) = firebaseDistributor
|
||||
|
||||
override suspend fun unregister(matrixClient: MatrixClient): Result<Unit> {
|
||||
|
||||
@@ -17,7 +17,9 @@ import io.element.android.tests.testutils.lambda.lambdaError
|
||||
class FakePushProvider(
|
||||
override val index: Int = 0,
|
||||
override val name: String = "aFakePushProvider",
|
||||
override val supportMultipleDistributors: Boolean = false,
|
||||
private val distributors: List<Distributor> = listOf(Distributor("aDistributorValue", "aDistributorName")),
|
||||
private val currentDistributorValue: () -> String? = { lambdaError() },
|
||||
private val currentDistributor: () -> Distributor? = { distributors.firstOrNull() },
|
||||
private val currentUserPushConfig: CurrentUserPushConfig? = null,
|
||||
private val registerWithResult: (MatrixClient, Distributor) -> Result<Unit> = { _, _ -> lambdaError() },
|
||||
@@ -32,6 +34,10 @@ class FakePushProvider(
|
||||
return registerWithResult(matrixClient, distributor)
|
||||
}
|
||||
|
||||
override suspend fun getCurrentDistributorValue(sessionId: SessionId): String? {
|
||||
return currentDistributorValue()
|
||||
}
|
||||
|
||||
override suspend fun getCurrentDistributor(sessionId: SessionId): Distributor? {
|
||||
return currentDistributor()
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ class UnifiedPushProvider(
|
||||
) : PushProvider {
|
||||
override val index = UnifiedPushConfig.INDEX
|
||||
override val name = UnifiedPushConfig.NAME
|
||||
override val supportMultipleDistributors = true
|
||||
|
||||
override fun getDistributors(): List<Distributor> {
|
||||
return unifiedPushDistributorProvider.getDistributors()
|
||||
@@ -42,6 +43,10 @@ class UnifiedPushProvider(
|
||||
}
|
||||
}
|
||||
|
||||
override suspend fun getCurrentDistributorValue(sessionId: SessionId): String? {
|
||||
return unifiedPushStore.getDistributorValue(sessionId)
|
||||
}
|
||||
|
||||
override suspend fun getCurrentDistributor(sessionId: SessionId): Distributor? {
|
||||
val distributorValue = unifiedPushStore.getDistributorValue(sessionId)
|
||||
return getDistributors().find { it.value == distributorValue }
|
||||
|
||||
Reference in New Issue
Block a user