Merge pull request #5471 from element-hq/feature/bma/improveUnifiedPushTroubleshotTest
Improve current push provider test: give info about the distributor.
This commit is contained in:
commit
59ef782b3e
6 changed files with 165 additions and 15 deletions
|
|
@ -7,10 +7,11 @@
|
|||
|
||||
package io.element.android.libraries.push.impl.troubleshoot
|
||||
|
||||
import dev.zacsweers.metro.AppScope
|
||||
import dev.zacsweers.metro.ContributesIntoSet
|
||||
import dev.zacsweers.metro.Inject
|
||||
import io.element.android.libraries.push.api.GetCurrentPushProvider
|
||||
import io.element.android.libraries.di.SessionScope
|
||||
import io.element.android.libraries.matrix.api.core.SessionId
|
||||
import io.element.android.libraries.push.api.PushService
|
||||
import io.element.android.libraries.push.impl.R
|
||||
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTest
|
||||
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestDelegate
|
||||
|
|
@ -19,10 +20,11 @@ import io.element.android.services.toolbox.api.strings.StringProvider
|
|||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
@ContributesIntoSet(AppScope::class)
|
||||
@ContributesIntoSet(SessionScope::class)
|
||||
@Inject
|
||||
class CurrentPushProviderTest(
|
||||
private val getCurrentPushProvider: GetCurrentPushProvider,
|
||||
private val pushService: PushService,
|
||||
private val sessionId: SessionId,
|
||||
private val stringProvider: StringProvider,
|
||||
) : NotificationTroubleshootTest {
|
||||
override val order = 110
|
||||
|
|
@ -35,17 +37,55 @@ class CurrentPushProviderTest(
|
|||
|
||||
override suspend fun run(coroutineScope: CoroutineScope) {
|
||||
delegate.start()
|
||||
val provider = getCurrentPushProvider.getCurrentPushProvider()
|
||||
if (provider != null) {
|
||||
delegate.updateState(
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_current_push_provider_success, provider),
|
||||
status = NotificationTroubleshootTestState.Status.Success
|
||||
)
|
||||
} else {
|
||||
val pushProvider = pushService.getCurrentPushProvider()
|
||||
if (pushProvider == null) {
|
||||
delegate.updateState(
|
||||
description = stringProvider.getString(R.string.troubleshoot_notifications_test_current_push_provider_failure),
|
||||
status = NotificationTroubleshootTestState.Status.Failure()
|
||||
)
|
||||
} else if (pushProvider.supportMultipleDistributors.not()) {
|
||||
delegate.updateState(
|
||||
description = stringProvider.getString(
|
||||
R.string.troubleshoot_notifications_test_current_push_provider_success,
|
||||
pushProvider.name
|
||||
),
|
||||
status = NotificationTroubleshootTestState.Status.Success
|
||||
)
|
||||
} else {
|
||||
val distributorValue = pushProvider.getCurrentDistributorValue(sessionId)
|
||||
if (distributorValue == null) {
|
||||
// No distributors configured
|
||||
delegate.updateState(
|
||||
description = stringProvider.getString(
|
||||
R.string.troubleshoot_notifications_test_current_push_provider_failure_no_distributor,
|
||||
pushProvider.name
|
||||
),
|
||||
status = NotificationTroubleshootTestState.Status.Failure(false)
|
||||
)
|
||||
} else {
|
||||
val distributor = pushProvider.getDistributors().find { it.value == distributorValue }
|
||||
if (distributor == null) {
|
||||
// Distributor has been uninstalled?
|
||||
delegate.updateState(
|
||||
description = stringProvider.getString(
|
||||
R.string.troubleshoot_notifications_test_current_push_provider_failure_distributor_not_found,
|
||||
pushProvider.name,
|
||||
distributorValue,
|
||||
distributorValue,
|
||||
),
|
||||
status = NotificationTroubleshootTestState.Status.Failure(false)
|
||||
)
|
||||
} else {
|
||||
delegate.updateState(
|
||||
description = stringProvider.getString(
|
||||
R.string.troubleshoot_notifications_test_current_push_provider_success_with_distributor,
|
||||
pushProvider.name,
|
||||
distributorValue,
|
||||
),
|
||||
status = NotificationTroubleshootTestState.Status.Success
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,10 @@
|
|||
package io.element.android.libraries.push.impl.troubleshoot
|
||||
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import io.element.android.libraries.push.test.FakeGetCurrentPushProvider
|
||||
import io.element.android.libraries.matrix.test.A_SESSION_ID
|
||||
import io.element.android.libraries.push.test.FakePushService
|
||||
import io.element.android.libraries.pushproviders.api.Distributor
|
||||
import io.element.android.libraries.pushproviders.test.FakePushProvider
|
||||
import io.element.android.libraries.troubleshoot.api.test.NotificationTroubleshootTestState
|
||||
import io.element.android.libraries.troubleshoot.test.runAndTestState
|
||||
import io.element.android.services.toolbox.test.strings.FakeStringProvider
|
||||
|
|
@ -17,10 +20,18 @@ import org.junit.Test
|
|||
|
||||
class CurrentPushProviderTestTest {
|
||||
@Test
|
||||
fun `test CurrentPushProviderTest with a push provider`() = runTest {
|
||||
fun `test CurrentPushProviderTest with a push provider and a distributor`() = runTest {
|
||||
val sut = CurrentPushProviderTest(
|
||||
getCurrentPushProvider = FakeGetCurrentPushProvider("foo"),
|
||||
pushService = FakePushService(
|
||||
currentPushProvider = {
|
||||
FakePushProvider(
|
||||
name = "foo",
|
||||
currentDistributorValue = { "aDistributor" },
|
||||
)
|
||||
}
|
||||
),
|
||||
stringProvider = FakeStringProvider(),
|
||||
sessionId = A_SESSION_ID,
|
||||
)
|
||||
sut.runAndTestState {
|
||||
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
|
||||
|
|
@ -31,11 +42,86 @@ class CurrentPushProviderTestTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test CurrentPushProviderTest with a push provider supporting multiple distributors, distributor found`() = runTest {
|
||||
val sut = CurrentPushProviderTest(
|
||||
pushService = FakePushService(
|
||||
currentPushProvider = {
|
||||
FakePushProvider(
|
||||
name = "foo",
|
||||
currentDistributorValue = { "aDistributor" },
|
||||
supportMultipleDistributors = true,
|
||||
distributors = listOf(Distributor("aDistributor", "aDistributor"))
|
||||
)
|
||||
},
|
||||
),
|
||||
stringProvider = FakeStringProvider(),
|
||||
sessionId = A_SESSION_ID,
|
||||
)
|
||||
sut.runAndTestState {
|
||||
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
|
||||
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
|
||||
val lastItem = awaitItem()
|
||||
assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Success)
|
||||
assertThat(lastItem.description).contains("foo")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test CurrentPushProviderTest with a push provider supporting multiple distributors, no distributor`() = runTest {
|
||||
val sut = CurrentPushProviderTest(
|
||||
pushService = FakePushService(
|
||||
currentPushProvider = {
|
||||
FakePushProvider(
|
||||
name = "foo",
|
||||
currentDistributorValue = { null },
|
||||
supportMultipleDistributors = true,
|
||||
)
|
||||
},
|
||||
),
|
||||
stringProvider = FakeStringProvider(),
|
||||
sessionId = A_SESSION_ID,
|
||||
)
|
||||
sut.runAndTestState {
|
||||
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
|
||||
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
|
||||
val lastItem = awaitItem()
|
||||
assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test CurrentPushProviderTest with a push provider supporting multiple distributors, distributor not found`() = runTest {
|
||||
val sut = CurrentPushProviderTest(
|
||||
pushService = FakePushService(
|
||||
currentPushProvider = {
|
||||
FakePushProvider(
|
||||
name = "foo",
|
||||
currentDistributorValue = { "aDistributor" },
|
||||
supportMultipleDistributors = true,
|
||||
distributors = emptyList()
|
||||
)
|
||||
},
|
||||
),
|
||||
stringProvider = FakeStringProvider(),
|
||||
sessionId = A_SESSION_ID,
|
||||
)
|
||||
sut.runAndTestState {
|
||||
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
|
||||
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.InProgress)
|
||||
val lastItem = awaitItem()
|
||||
assertThat(lastItem.status).isEqualTo(NotificationTroubleshootTestState.Status.Failure())
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test CurrentPushProviderTest without push provider`() = runTest {
|
||||
val sut = CurrentPushProviderTest(
|
||||
getCurrentPushProvider = FakeGetCurrentPushProvider(null),
|
||||
pushService = FakePushService(
|
||||
currentPushProvider = { null },
|
||||
),
|
||||
stringProvider = FakeStringProvider(),
|
||||
sessionId = A_SESSION_ID,
|
||||
)
|
||||
sut.runAndTestState {
|
||||
assertThat(awaitItem().status).isEqualTo(NotificationTroubleshootTestState.Status.Idle(true))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue