Fix method used to check if background sync is enabled

This commit is contained in:
Maxime NATUREL 2022-11-24 18:01:34 +01:00
parent a2ae3af69d
commit 68d00e00d1
3 changed files with 16 additions and 7 deletions

View File

@ -16,6 +16,7 @@
package im.vector.app.features.settings.devices.v2.notification package im.vector.app.features.settings.devices.v2.notification
import im.vector.app.core.pushers.UnifiedPushHelper
import im.vector.app.features.settings.VectorPreferences import im.vector.app.features.settings.VectorPreferences
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
import org.matrix.android.sdk.api.session.Session import org.matrix.android.sdk.api.session.Session
@ -27,13 +28,14 @@ import javax.inject.Inject
*/ */
class UpdateNotificationSettingsAccountDataUseCase @Inject constructor( class UpdateNotificationSettingsAccountDataUseCase @Inject constructor(
private val vectorPreferences: VectorPreferences, private val vectorPreferences: VectorPreferences,
private val unifiedPushHelper: UnifiedPushHelper,
private val getNotificationSettingsAccountDataUseCase: GetNotificationSettingsAccountDataUseCase, private val getNotificationSettingsAccountDataUseCase: GetNotificationSettingsAccountDataUseCase,
private val setNotificationSettingsAccountDataUseCase: SetNotificationSettingsAccountDataUseCase, private val setNotificationSettingsAccountDataUseCase: SetNotificationSettingsAccountDataUseCase,
private val deleteNotificationSettingsAccountDataUseCase: DeleteNotificationSettingsAccountDataUseCase, private val deleteNotificationSettingsAccountDataUseCase: DeleteNotificationSettingsAccountDataUseCase,
) { ) {
suspend fun execute(session: Session) { suspend fun execute(session: Session) {
if (vectorPreferences.isBackgroundSyncEnabled()) { if (unifiedPushHelper.isBackgroundSync()) {
setCurrentNotificationStatus(session) setCurrentNotificationStatus(session)
} else { } else {
deleteCurrentNotificationStatus(session) deleteCurrentNotificationStatus(session)

View File

@ -17,6 +17,7 @@
package im.vector.app.features.settings.devices.v2.notification package im.vector.app.features.settings.devices.v2.notification
import im.vector.app.test.fakes.FakeSession import im.vector.app.test.fakes.FakeSession
import im.vector.app.test.fakes.FakeUnifiedPushHelper
import im.vector.app.test.fakes.FakeVectorPreferences import im.vector.app.test.fakes.FakeVectorPreferences
import io.mockk.coJustRun import io.mockk.coJustRun
import io.mockk.coVerify import io.mockk.coVerify
@ -30,12 +31,14 @@ import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
class UpdateNotificationSettingsAccountDataUseCaseTest { class UpdateNotificationSettingsAccountDataUseCaseTest {
private val fakeVectorPreferences = FakeVectorPreferences() private val fakeVectorPreferences = FakeVectorPreferences()
private val fakeUnifiedPushHelper = FakeUnifiedPushHelper()
private val fakeGetNotificationSettingsAccountDataUseCase = mockk<GetNotificationSettingsAccountDataUseCase>() private val fakeGetNotificationSettingsAccountDataUseCase = mockk<GetNotificationSettingsAccountDataUseCase>()
private val fakeSetNotificationSettingsAccountDataUseCase = mockk<SetNotificationSettingsAccountDataUseCase>() private val fakeSetNotificationSettingsAccountDataUseCase = mockk<SetNotificationSettingsAccountDataUseCase>()
private val fakeDeleteNotificationSettingsAccountDataUseCase = mockk<DeleteNotificationSettingsAccountDataUseCase>() private val fakeDeleteNotificationSettingsAccountDataUseCase = mockk<DeleteNotificationSettingsAccountDataUseCase>()
private val updateNotificationSettingsAccountDataUseCase = UpdateNotificationSettingsAccountDataUseCase( private val updateNotificationSettingsAccountDataUseCase = UpdateNotificationSettingsAccountDataUseCase(
vectorPreferences = fakeVectorPreferences.instance, vectorPreferences = fakeVectorPreferences.instance,
unifiedPushHelper = fakeUnifiedPushHelper.instance,
getNotificationSettingsAccountDataUseCase = fakeGetNotificationSettingsAccountDataUseCase, getNotificationSettingsAccountDataUseCase = fakeGetNotificationSettingsAccountDataUseCase,
setNotificationSettingsAccountDataUseCase = fakeSetNotificationSettingsAccountDataUseCase, setNotificationSettingsAccountDataUseCase = fakeSetNotificationSettingsAccountDataUseCase,
deleteNotificationSettingsAccountDataUseCase = fakeDeleteNotificationSettingsAccountDataUseCase, deleteNotificationSettingsAccountDataUseCase = fakeDeleteNotificationSettingsAccountDataUseCase,
@ -50,7 +53,7 @@ class UpdateNotificationSettingsAccountDataUseCaseTest {
coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any(), any()) } coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any(), any()) }
val areNotificationsEnabled = true val areNotificationsEnabled = true
fakeVectorPreferences.givenAreNotificationEnabled(areNotificationsEnabled) fakeVectorPreferences.givenAreNotificationEnabled(areNotificationsEnabled)
fakeVectorPreferences.givenIsBackgroundSyncEnabled(true) fakeUnifiedPushHelper.givenIsBackgroundSyncReturns(true)
every { fakeGetNotificationSettingsAccountDataUseCase.execute(any(), any()) } returns every { fakeGetNotificationSettingsAccountDataUseCase.execute(any(), any()) } returns
LocalNotificationSettingsContent( LocalNotificationSettingsContent(
isSilenced = null isSilenced = null
@ -64,7 +67,7 @@ class UpdateNotificationSettingsAccountDataUseCaseTest {
// Then // Then
verify { verify {
fakeVectorPreferences.instance.isBackgroundSyncEnabled() fakeUnifiedPushHelper.instance.isBackgroundSync()
fakeVectorPreferences.instance.areNotificationEnabledForDevice() fakeVectorPreferences.instance.areNotificationEnabledForDevice()
fakeGetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId) fakeGetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId)
} }
@ -81,7 +84,7 @@ class UpdateNotificationSettingsAccountDataUseCaseTest {
coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any(), any()) } coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any(), any()) }
val areNotificationsEnabled = true val areNotificationsEnabled = true
fakeVectorPreferences.givenAreNotificationEnabled(areNotificationsEnabled) fakeVectorPreferences.givenAreNotificationEnabled(areNotificationsEnabled)
fakeVectorPreferences.givenIsBackgroundSyncEnabled(true) fakeUnifiedPushHelper.givenIsBackgroundSyncReturns(true)
every { fakeGetNotificationSettingsAccountDataUseCase.execute(any(), any()) } returns every { fakeGetNotificationSettingsAccountDataUseCase.execute(any(), any()) } returns
LocalNotificationSettingsContent( LocalNotificationSettingsContent(
isSilenced = false isSilenced = false
@ -95,7 +98,7 @@ class UpdateNotificationSettingsAccountDataUseCaseTest {
// Then // Then
verify { verify {
fakeVectorPreferences.instance.isBackgroundSyncEnabled() fakeUnifiedPushHelper.instance.isBackgroundSync()
fakeVectorPreferences.instance.areNotificationEnabledForDevice() fakeVectorPreferences.instance.areNotificationEnabledForDevice()
fakeGetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId) fakeGetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId)
} }
@ -110,14 +113,14 @@ class UpdateNotificationSettingsAccountDataUseCaseTest {
val aSession = FakeSession() val aSession = FakeSession()
aSession.givenSessionId(aDeviceId) aSession.givenSessionId(aDeviceId)
coJustRun { fakeDeleteNotificationSettingsAccountDataUseCase.execute(any()) } coJustRun { fakeDeleteNotificationSettingsAccountDataUseCase.execute(any()) }
fakeVectorPreferences.givenIsBackgroundSyncEnabled(false) fakeUnifiedPushHelper.givenIsBackgroundSyncReturns(false)
// When // When
updateNotificationSettingsAccountDataUseCase.execute(aSession) updateNotificationSettingsAccountDataUseCase.execute(aSession)
// Then // Then
verify { verify {
fakeVectorPreferences.instance.isBackgroundSyncEnabled() fakeUnifiedPushHelper.instance.isBackgroundSync()
} }
coVerify { fakeDeleteNotificationSettingsAccountDataUseCase.execute(aSession) } coVerify { fakeDeleteNotificationSettingsAccountDataUseCase.execute(aSession) }
coVerify(inverse = true) { fakeSetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId, any()) } coVerify(inverse = true) { fakeSetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId, any()) }

View File

@ -31,4 +31,8 @@ class FakeUnifiedPushHelper {
fun givenGetEndpointOrTokenReturns(endpoint: String?) { fun givenGetEndpointOrTokenReturns(endpoint: String?) {
every { instance.getEndpointOrToken() } returns endpoint every { instance.getEndpointOrToken() } returns endpoint
} }
fun givenIsBackgroundSyncReturns(enabled: Boolean) {
every { instance.isBackgroundSync() } returns enabled
}
} }