Ignore local errors when unregistering UnifiedPush, to not block switching to another push provider.
This commit is contained in:
committed by
Benoit Marty
parent
d275ed9150
commit
35e14a3d46
@@ -23,6 +23,7 @@ import io.element.android.libraries.di.ApplicationContext
|
||||
import io.element.android.libraries.matrix.api.MatrixClient
|
||||
import io.element.android.libraries.pushproviders.api.PusherSubscriber
|
||||
import org.unifiedpush.android.connector.UnifiedPush
|
||||
import timber.log.Timber
|
||||
import javax.inject.Inject
|
||||
|
||||
interface UnregisterUnifiedPushUseCase {
|
||||
@@ -39,7 +40,11 @@ class DefaultUnregisterUnifiedPushUseCase @Inject constructor(
|
||||
val endpoint = unifiedPushStore.getEndpoint(clientSecret)
|
||||
val gateway = unifiedPushStore.getPushGateway(clientSecret)
|
||||
if (endpoint == null || gateway == null) {
|
||||
return Result.failure(IllegalStateException("No endpoint or gateway found for client secret"))
|
||||
Timber.w("No endpoint or gateway found for client secret")
|
||||
// Ensure we don't have any remaining data, but ignore this error
|
||||
unifiedPushStore.storeUpEndpoint(clientSecret, null)
|
||||
unifiedPushStore.storePushGateway(clientSecret, null)
|
||||
return Result.success(Unit)
|
||||
}
|
||||
return pusherSubscriber.unregisterPusher(matrixClient, endpoint, gateway)
|
||||
.onSuccess {
|
||||
|
||||
@@ -64,29 +64,49 @@ class DefaultUnregisterUnifiedPushUseCaseTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test un registration error - no endpoint`() = runTest {
|
||||
fun `test un registration error - no endpoint - will not unregister but return success`() = runTest {
|
||||
val matrixClient = FakeMatrixClient()
|
||||
val storeUpEndpointResult = lambdaRecorder { _: String, _: String? -> }
|
||||
val storePushGatewayResult = lambdaRecorder { _: String, _: String? -> }
|
||||
val useCase = createDefaultUnregisterUnifiedPushUseCase(
|
||||
unifiedPushStore = FakeUnifiedPushStore(
|
||||
getEndpointResult = { null },
|
||||
getPushGatewayResult = { "aGateway" },
|
||||
storeUpEndpointResult = storeUpEndpointResult,
|
||||
storePushGatewayResult = storePushGatewayResult,
|
||||
),
|
||||
)
|
||||
val result = useCase.execute(matrixClient, A_SECRET)
|
||||
assertThat(result.isFailure).isTrue()
|
||||
assertThat(result.isSuccess).isTrue()
|
||||
storeUpEndpointResult.assertions()
|
||||
.isCalledOnce()
|
||||
.with(value(A_SECRET), value(null))
|
||||
storePushGatewayResult.assertions()
|
||||
.isCalledOnce()
|
||||
.with(value(A_SECRET), value(null))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `test un registration error - no gateway`() = runTest {
|
||||
fun `test un registration error - no gateway - will not unregister but return success`() = runTest {
|
||||
val matrixClient = FakeMatrixClient()
|
||||
val storeUpEndpointResult = lambdaRecorder { _: String, _: String? -> }
|
||||
val storePushGatewayResult = lambdaRecorder { _: String, _: String? -> }
|
||||
val useCase = createDefaultUnregisterUnifiedPushUseCase(
|
||||
unifiedPushStore = FakeUnifiedPushStore(
|
||||
getEndpointResult = { "aEndpoint" },
|
||||
getPushGatewayResult = { null },
|
||||
storeUpEndpointResult = storeUpEndpointResult,
|
||||
storePushGatewayResult = storePushGatewayResult,
|
||||
),
|
||||
)
|
||||
val result = useCase.execute(matrixClient, A_SECRET)
|
||||
assertThat(result.isFailure).isTrue()
|
||||
assertThat(result.isSuccess).isTrue()
|
||||
storeUpEndpointResult.assertions()
|
||||
.isCalledOnce()
|
||||
.with(value(A_SECRET), value(null))
|
||||
storePushGatewayResult.assertions()
|
||||
.isCalledOnce()
|
||||
.with(value(A_SECRET), value(null))
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user