Some refactorings + update unit tests
This commit is contained in:
parent
7c51174d7e
commit
ab6a6b53c8
@ -25,6 +25,7 @@ import im.vector.app.features.call.webrtc.WebRtcCallManager
|
|||||||
import im.vector.app.features.session.coroutineScope
|
import im.vector.app.features.session.coroutineScope
|
||||||
import im.vector.app.features.settings.VectorPreferences
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import im.vector.app.features.sync.SyncUtils
|
import im.vector.app.features.sync.SyncUtils
|
||||||
|
import im.vector.app.features.settings.devices.v2.notification.UpdateNotificationSettingsAccountDataUseCase
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import timber.log.Timber
|
import timber.log.Timber
|
||||||
@ -36,6 +37,7 @@ class ConfigureAndStartSessionUseCase @Inject constructor(
|
|||||||
private val updateMatrixClientInfoUseCase: UpdateMatrixClientInfoUseCase,
|
private val updateMatrixClientInfoUseCase: UpdateMatrixClientInfoUseCase,
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
private val enableNotificationsSettingUpdater: EnableNotificationsSettingUpdater,
|
private val enableNotificationsSettingUpdater: EnableNotificationsSettingUpdater,
|
||||||
|
private val updateNotificationSettingsAccountDataUseCase: UpdateNotificationSettingsAccountDataUseCase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun execute(session: Session, startSyncing: Boolean = true) {
|
fun execute(session: Session, startSyncing: Boolean = true) {
|
||||||
@ -49,11 +51,24 @@ class ConfigureAndStartSessionUseCase @Inject constructor(
|
|||||||
}
|
}
|
||||||
session.pushersService().refreshPushers()
|
session.pushersService().refreshPushers()
|
||||||
webRtcCallManager.checkForProtocolsSupportIfNeeded()
|
webRtcCallManager.checkForProtocolsSupportIfNeeded()
|
||||||
|
updateMatrixClientInfoIfNeeded(session)
|
||||||
|
createNotificationSettingsAccountDataIfNeeded(session)
|
||||||
|
enableNotificationsSettingUpdater.onSessionsStarted(session)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun updateMatrixClientInfoIfNeeded(session: Session) {
|
||||||
session.coroutineScope.launch {
|
session.coroutineScope.launch {
|
||||||
if (vectorPreferences.isClientInfoRecordingEnabled()) {
|
if (vectorPreferences.isClientInfoRecordingEnabled()) {
|
||||||
updateMatrixClientInfoUseCase.execute(session)
|
updateMatrixClientInfoUseCase.execute(session)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enableNotificationsSettingUpdater.onSessionsStarted(session)
|
}
|
||||||
|
|
||||||
|
private fun createNotificationSettingsAccountDataIfNeeded(session: Session) {
|
||||||
|
session.coroutineScope.launch {
|
||||||
|
if (vectorPreferences.isBackgroundSyncEnabled()) {
|
||||||
|
updateNotificationSettingsAccountDataUseCase.execute(session)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,20 +16,14 @@
|
|||||||
|
|
||||||
package im.vector.app.features.settings.devices.v2.notification
|
package im.vector.app.features.settings.devices.v2.notification
|
||||||
|
|
||||||
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
|
||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes
|
|
||||||
import org.matrix.android.sdk.api.session.events.model.toModel
|
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class CheckIfCanToggleNotificationsViaAccountDataUseCase @Inject constructor() {
|
class CheckIfCanToggleNotificationsViaAccountDataUseCase @Inject constructor(
|
||||||
|
private val getNotificationSettingsAccountDataUseCase: GetNotificationSettingsAccountDataUseCase,
|
||||||
|
) {
|
||||||
|
|
||||||
fun execute(session: Session, deviceId: String): Boolean {
|
fun execute(session: Session, deviceId: String): Boolean {
|
||||||
return session
|
return getNotificationSettingsAccountDataUseCase.execute(session, deviceId)?.isSilenced != null
|
||||||
.accountDataService()
|
|
||||||
.getUserAccountDataEvent(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId)
|
|
||||||
?.content
|
|
||||||
.toModel<LocalNotificationSettingsContent>()
|
|
||||||
?.isSilenced != null
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,17 +17,22 @@
|
|||||||
package im.vector.app.features.settings.devices.v2.notification
|
package im.vector.app.features.settings.devices.v2.notification
|
||||||
|
|
||||||
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 javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete the content of any associated notification settings to the current session.
|
||||||
|
*/
|
||||||
class DeleteNotificationSettingsAccountDataUseCase @Inject constructor(
|
class DeleteNotificationSettingsAccountDataUseCase @Inject constructor(
|
||||||
private val setNotificationSettingsAccountDataUseCase: SetNotificationSettingsAccountDataUseCase,
|
private val setNotificationSettingsAccountDataUseCase: SetNotificationSettingsAccountDataUseCase,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// TODO to be called when switching to push notifications method
|
// TODO to be called when switching to push notifications method (check notification method setting)
|
||||||
suspend fun execute(deviceId: String) {
|
suspend fun execute(session: Session) {
|
||||||
|
val deviceId = session.sessionParams.deviceId ?: return
|
||||||
val emptyNotificationSettingsContent = LocalNotificationSettingsContent(
|
val emptyNotificationSettingsContent = LocalNotificationSettingsContent(
|
||||||
isSilenced = null
|
isSilenced = null
|
||||||
)
|
)
|
||||||
setNotificationSettingsAccountDataUseCase.execute(deviceId, emptyNotificationSettingsContent)
|
setNotificationSettingsAccountDataUseCase.execute(session, deviceId, emptyNotificationSettingsContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.app.features.settings.devices.v2.notification
|
||||||
|
|
||||||
|
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
||||||
|
import org.matrix.android.sdk.api.session.Session
|
||||||
|
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes
|
||||||
|
import org.matrix.android.sdk.api.session.events.model.toModel
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
class GetNotificationSettingsAccountDataUseCase @Inject constructor() {
|
||||||
|
|
||||||
|
fun execute(session: Session, deviceId: String): LocalNotificationSettingsContent? {
|
||||||
|
return session
|
||||||
|
.accountDataService()
|
||||||
|
.getUserAccountDataEvent(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId)
|
||||||
|
?.content
|
||||||
|
.toModel<LocalNotificationSettingsContent>()
|
||||||
|
}
|
||||||
|
}
|
@ -16,18 +16,15 @@
|
|||||||
|
|
||||||
package im.vector.app.features.settings.devices.v2.notification
|
package im.vector.app.features.settings.devices.v2.notification
|
||||||
|
|
||||||
import im.vector.app.core.di.ActiveSessionHolder
|
|
||||||
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.accountdata.UserAccountDataTypes
|
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes
|
||||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class SetNotificationSettingsAccountDataUseCase @Inject constructor(
|
class SetNotificationSettingsAccountDataUseCase @Inject constructor() {
|
||||||
private val activeSessionHolder: ActiveSessionHolder,
|
|
||||||
) {
|
|
||||||
|
|
||||||
suspend fun execute(deviceId: String, localNotificationSettingsContent: LocalNotificationSettingsContent) {
|
suspend fun execute(session: Session, deviceId: String, localNotificationSettingsContent: LocalNotificationSettingsContent) {
|
||||||
val session = activeSessionHolder.getSafeActiveSession() ?: return
|
|
||||||
session.accountDataService().updateUserAccountData(
|
session.accountDataService().updateUserAccountData(
|
||||||
UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId,
|
UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId,
|
||||||
localNotificationSettingsContent.toContent(),
|
localNotificationSettingsContent.toContent(),
|
||||||
|
@ -39,7 +39,7 @@ class ToggleNotificationUseCase @Inject constructor(
|
|||||||
|
|
||||||
if (checkIfCanToggleNotificationsViaAccountDataUseCase.execute(session, deviceId)) {
|
if (checkIfCanToggleNotificationsViaAccountDataUseCase.execute(session, deviceId)) {
|
||||||
val newNotificationSettingsContent = LocalNotificationSettingsContent(isSilenced = !enabled)
|
val newNotificationSettingsContent = LocalNotificationSettingsContent(isSilenced = !enabled)
|
||||||
setNotificationSettingsAccountDataUseCase.execute(deviceId, newNotificationSettingsContent)
|
setNotificationSettingsAccountDataUseCase.execute(session, deviceId, newNotificationSettingsContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,18 +21,25 @@ import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
|||||||
import org.matrix.android.sdk.api.session.Session
|
import org.matrix.android.sdk.api.session.Session
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
class CreateNotificationSettingsAccountDataUseCase @Inject constructor(
|
/**
|
||||||
|
* Update the notification settings account data for the current session.
|
||||||
|
*/
|
||||||
|
class UpdateNotificationSettingsAccountDataUseCase @Inject constructor(
|
||||||
private val vectorPreferences: VectorPreferences,
|
private val vectorPreferences: VectorPreferences,
|
||||||
|
private val getNotificationSettingsAccountDataUseCase: GetNotificationSettingsAccountDataUseCase,
|
||||||
private val setNotificationSettingsAccountDataUseCase: SetNotificationSettingsAccountDataUseCase
|
private val setNotificationSettingsAccountDataUseCase: SetNotificationSettingsAccountDataUseCase
|
||||||
) {
|
) {
|
||||||
|
|
||||||
// TODO to be called on session start when background sync is enabled + when switching to background sync
|
// TODO to be called when switching to background sync (in notification method setting)
|
||||||
suspend fun execute(session: Session) {
|
suspend fun execute(session: Session) {
|
||||||
val deviceId = session.sessionParams.deviceId ?: return
|
val deviceId = session.sessionParams.deviceId ?: return
|
||||||
val isSilenced = !vectorPreferences.areNotificationEnabledForDevice()
|
val isSilencedLocal = !vectorPreferences.areNotificationEnabledForDevice()
|
||||||
|
val isSilencedRemote = getNotificationSettingsAccountDataUseCase.execute(session, deviceId)?.isSilenced
|
||||||
|
if (isSilencedLocal != isSilencedRemote) {
|
||||||
val notificationSettingsContent = LocalNotificationSettingsContent(
|
val notificationSettingsContent = LocalNotificationSettingsContent(
|
||||||
isSilenced = isSilenced
|
isSilenced = isSilencedLocal
|
||||||
)
|
)
|
||||||
setNotificationSettingsAccountDataUseCase.execute(deviceId, notificationSettingsContent)
|
setNotificationSettingsAccountDataUseCase.execute(session, deviceId, notificationSettingsContent)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -20,6 +20,7 @@ import im.vector.app.core.extensions.startSyncing
|
|||||||
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
|
import im.vector.app.core.session.clientinfo.UpdateMatrixClientInfoUseCase
|
||||||
import im.vector.app.features.session.coroutineScope
|
import im.vector.app.features.session.coroutineScope
|
||||||
import im.vector.app.features.sync.SyncUtils
|
import im.vector.app.features.sync.SyncUtils
|
||||||
|
import im.vector.app.features.settings.devices.v2.notification.UpdateNotificationSettingsAccountDataUseCase
|
||||||
import im.vector.app.test.fakes.FakeContext
|
import im.vector.app.test.fakes.FakeContext
|
||||||
import im.vector.app.test.fakes.FakeEnableNotificationsSettingUpdater
|
import im.vector.app.test.fakes.FakeEnableNotificationsSettingUpdater
|
||||||
import im.vector.app.test.fakes.FakeSession
|
import im.vector.app.test.fakes.FakeSession
|
||||||
@ -47,6 +48,7 @@ class ConfigureAndStartSessionUseCaseTest {
|
|||||||
private val fakeUpdateMatrixClientInfoUseCase = mockk<UpdateMatrixClientInfoUseCase>()
|
private val fakeUpdateMatrixClientInfoUseCase = mockk<UpdateMatrixClientInfoUseCase>()
|
||||||
private val fakeVectorPreferences = FakeVectorPreferences()
|
private val fakeVectorPreferences = FakeVectorPreferences()
|
||||||
private val fakeEnableNotificationsSettingUpdater = FakeEnableNotificationsSettingUpdater()
|
private val fakeEnableNotificationsSettingUpdater = FakeEnableNotificationsSettingUpdater()
|
||||||
|
private val fakeUpdateNotificationSettingsAccountDataUseCase = mockk<UpdateNotificationSettingsAccountDataUseCase>()
|
||||||
|
|
||||||
private val configureAndStartSessionUseCase = ConfigureAndStartSessionUseCase(
|
private val configureAndStartSessionUseCase = ConfigureAndStartSessionUseCase(
|
||||||
context = fakeContext.instance,
|
context = fakeContext.instance,
|
||||||
@ -54,6 +56,7 @@ class ConfigureAndStartSessionUseCaseTest {
|
|||||||
updateMatrixClientInfoUseCase = fakeUpdateMatrixClientInfoUseCase,
|
updateMatrixClientInfoUseCase = fakeUpdateMatrixClientInfoUseCase,
|
||||||
vectorPreferences = fakeVectorPreferences.instance,
|
vectorPreferences = fakeVectorPreferences.instance,
|
||||||
enableNotificationsSettingUpdater = fakeEnableNotificationsSettingUpdater.instance,
|
enableNotificationsSettingUpdater = fakeEnableNotificationsSettingUpdater.instance,
|
||||||
|
updateNotificationSettingsAccountDataUseCase = fakeUpdateNotificationSettingsAccountDataUseCase,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@ -68,47 +71,55 @@ class ConfigureAndStartSessionUseCaseTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given start sync needed and client info recording enabled when execute then it should be configured properly`() = runTest {
|
fun `given start sync needed and enabled related preferences when execute then it should be configured properly`() = runTest {
|
||||||
// Given
|
// Given
|
||||||
val fakeSession = givenASession()
|
val aSession = givenASession()
|
||||||
every { fakeSession.coroutineScope } returns this
|
every { aSession.coroutineScope } returns this
|
||||||
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
|
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
|
||||||
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
|
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
|
||||||
|
coJustRun { fakeUpdateNotificationSettingsAccountDataUseCase.execute(any()) }
|
||||||
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = true)
|
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = true)
|
||||||
fakeEnableNotificationsSettingUpdater.givenOnSessionsStarted(fakeSession)
|
fakeVectorPreferences.givenIsBackgroundSyncEnabled(isEnabled = true)
|
||||||
|
fakeEnableNotificationsSettingUpdater.givenOnSessionsStarted(aSession)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = true)
|
configureAndStartSessionUseCase.execute(aSession, startSyncing = true)
|
||||||
advanceUntilIdle()
|
advanceUntilIdle()
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
verify { fakeSession.startSyncing(fakeContext.instance) }
|
verify { aSession.startSyncing(fakeContext.instance) }
|
||||||
fakeSession.fakeFilterService.verifySetSyncFilter(SyncUtils.getSyncFilterBuilder())
|
aSession.fakeFilterService.verifySetSyncFilter(SyncUtils.getSyncFilterBuilder())
|
||||||
fakeSession.fakePushersService.verifyRefreshPushers()
|
aSession.fakePushersService.verifyRefreshPushers()
|
||||||
fakeWebRtcCallManager.verifyCheckForProtocolsSupportIfNeeded()
|
fakeWebRtcCallManager.verifyCheckForProtocolsSupportIfNeeded()
|
||||||
coVerify { fakeUpdateMatrixClientInfoUseCase.execute(fakeSession) }
|
coVerify {
|
||||||
|
fakeUpdateMatrixClientInfoUseCase.execute(aSession)
|
||||||
|
fakeUpdateNotificationSettingsAccountDataUseCase.execute(aSession)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given start sync needed and client info recording disabled when execute then it should be configured properly`() = runTest {
|
fun `given start sync needed and disabled related preferences when execute then it should be configured properly`() = runTest {
|
||||||
// Given
|
// Given
|
||||||
val fakeSession = givenASession()
|
val aSession = givenASession()
|
||||||
every { fakeSession.coroutineScope } returns this
|
every { aSession.coroutineScope } returns this
|
||||||
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
|
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
|
||||||
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
|
|
||||||
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = false)
|
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = false)
|
||||||
fakeEnableNotificationsSettingUpdater.givenOnSessionsStarted(fakeSession)
|
fakeVectorPreferences.givenIsBackgroundSyncEnabled(isEnabled = false)
|
||||||
|
fakeEnableNotificationsSettingUpdater.givenOnSessionsStarted(aSession)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
configureAndStartSessionUseCase.execute(fakeSession, startSyncing = true)
|
configureAndStartSessionUseCase.execute(aSession, startSyncing = true)
|
||||||
advanceUntilIdle()
|
advanceUntilIdle()
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
verify { fakeSession.startSyncing(fakeContext.instance) }
|
verify { aSession.startSyncing(fakeContext.instance) }
|
||||||
fakeSession.fakeFilterService.verifySetSyncFilter(SyncUtils.getSyncFilterBuilder())
|
aSession.fakeFilterService.verifySetSyncFilter(SyncUtils.getSyncFilterBuilder())
|
||||||
fakeSession.fakePushersService.verifyRefreshPushers()
|
aSession.fakePushersService.verifyRefreshPushers()
|
||||||
fakeWebRtcCallManager.verifyCheckForProtocolsSupportIfNeeded()
|
fakeWebRtcCallManager.verifyCheckForProtocolsSupportIfNeeded()
|
||||||
coVerify(inverse = true) { fakeUpdateMatrixClientInfoUseCase.execute(fakeSession) }
|
coVerify(inverse = true) {
|
||||||
|
fakeUpdateMatrixClientInfoUseCase.execute(aSession)
|
||||||
|
fakeUpdateNotificationSettingsAccountDataUseCase.execute(aSession)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -118,7 +129,9 @@ class ConfigureAndStartSessionUseCaseTest {
|
|||||||
every { fakeSession.coroutineScope } returns this
|
every { fakeSession.coroutineScope } returns this
|
||||||
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
|
fakeWebRtcCallManager.givenCheckForProtocolsSupportIfNeededSucceeds()
|
||||||
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
|
coJustRun { fakeUpdateMatrixClientInfoUseCase.execute(any()) }
|
||||||
|
coJustRun { fakeUpdateNotificationSettingsAccountDataUseCase.execute(any()) }
|
||||||
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = true)
|
fakeVectorPreferences.givenIsClientInfoRecordingEnabled(isEnabled = true)
|
||||||
|
fakeVectorPreferences.givenIsBackgroundSyncEnabled(isEnabled = true)
|
||||||
fakeEnableNotificationsSettingUpdater.givenOnSessionsStarted(fakeSession)
|
fakeEnableNotificationsSettingUpdater.givenOnSessionsStarted(fakeSession)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
@ -130,7 +143,10 @@ class ConfigureAndStartSessionUseCaseTest {
|
|||||||
fakeSession.fakeFilterService.verifySetSyncFilter(SyncUtils.getSyncFilterBuilder())
|
fakeSession.fakeFilterService.verifySetSyncFilter(SyncUtils.getSyncFilterBuilder())
|
||||||
fakeSession.fakePushersService.verifyRefreshPushers()
|
fakeSession.fakePushersService.verifyRefreshPushers()
|
||||||
fakeWebRtcCallManager.verifyCheckForProtocolsSupportIfNeeded()
|
fakeWebRtcCallManager.verifyCheckForProtocolsSupportIfNeeded()
|
||||||
coVerify { fakeUpdateMatrixClientInfoUseCase.execute(fakeSession) }
|
coVerify {
|
||||||
|
fakeUpdateMatrixClientInfoUseCase.execute(fakeSession)
|
||||||
|
fakeUpdateNotificationSettingsAccountDataUseCase.execute(fakeSession)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun givenASession(): FakeSession {
|
private fun givenASession(): FakeSession {
|
||||||
|
@ -17,31 +17,29 @@
|
|||||||
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 io.mockk.every
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
import org.amshove.kluent.shouldBeEqualTo
|
import org.amshove.kluent.shouldBeEqualTo
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
||||||
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes
|
|
||||||
import org.matrix.android.sdk.api.session.events.model.toContent
|
|
||||||
|
|
||||||
private const val A_DEVICE_ID = "device-id"
|
private const val A_DEVICE_ID = "device-id"
|
||||||
|
|
||||||
class CheckIfCanToggleNotificationsViaAccountDataUseCaseTest {
|
class CheckIfCanToggleNotificationsViaAccountDataUseCaseTest {
|
||||||
|
|
||||||
|
private val fakeGetNotificationSettingsAccountDataUseCase = mockk<GetNotificationSettingsAccountDataUseCase>()
|
||||||
private val fakeSession = FakeSession()
|
private val fakeSession = FakeSession()
|
||||||
|
|
||||||
private val checkIfCanToggleNotificationsViaAccountDataUseCase =
|
private val checkIfCanToggleNotificationsViaAccountDataUseCase =
|
||||||
CheckIfCanToggleNotificationsViaAccountDataUseCase()
|
CheckIfCanToggleNotificationsViaAccountDataUseCase(
|
||||||
|
getNotificationSettingsAccountDataUseCase = fakeGetNotificationSettingsAccountDataUseCase,
|
||||||
|
)
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given current session and an account data with a content for the device id when execute then result is true`() {
|
fun `given current session and an account data with a content for the device id when execute then result is true`() {
|
||||||
// Given
|
// Given
|
||||||
fakeSession
|
val content = LocalNotificationSettingsContent(isSilenced = true)
|
||||||
.accountDataService()
|
every { fakeGetNotificationSettingsAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns content
|
||||||
.givenGetUserAccountDataEventReturns(
|
|
||||||
type = UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + A_DEVICE_ID,
|
|
||||||
content = LocalNotificationSettingsContent(isSilenced = true).toContent(),
|
|
||||||
)
|
|
||||||
|
|
||||||
// When
|
// When
|
||||||
val result = checkIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
val result = checkIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
||||||
@ -53,12 +51,8 @@ class CheckIfCanToggleNotificationsViaAccountDataUseCaseTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `given current session and an account data with empty content for the device id when execute then result is false`() {
|
fun `given current session and an account data with empty content for the device id when execute then result is false`() {
|
||||||
// Given
|
// Given
|
||||||
fakeSession
|
val content = LocalNotificationSettingsContent(isSilenced = null)
|
||||||
.accountDataService()
|
every { fakeGetNotificationSettingsAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns content
|
||||||
.givenGetUserAccountDataEventReturns(
|
|
||||||
type = UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + A_DEVICE_ID,
|
|
||||||
content = mockk(),
|
|
||||||
)
|
|
||||||
|
|
||||||
// When
|
// When
|
||||||
val result = checkIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
val result = checkIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
||||||
@ -70,12 +64,8 @@ class CheckIfCanToggleNotificationsViaAccountDataUseCaseTest {
|
|||||||
@Test
|
@Test
|
||||||
fun `given current session and NO account data for the device id when execute then result is false`() {
|
fun `given current session and NO account data for the device id when execute then result is false`() {
|
||||||
// Given
|
// Given
|
||||||
fakeSession
|
val content = null
|
||||||
.accountDataService()
|
every { fakeGetNotificationSettingsAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns content
|
||||||
.givenGetUserAccountDataEventReturns(
|
|
||||||
type = UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + A_DEVICE_ID,
|
|
||||||
content = null,
|
|
||||||
)
|
|
||||||
|
|
||||||
// When
|
// When
|
||||||
val result = checkIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
val result = checkIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2022 New Vector Ltd
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package im.vector.app.features.settings.devices.v2.notification
|
|
||||||
|
|
||||||
import im.vector.app.test.fakes.FakeSession
|
|
||||||
import im.vector.app.test.fakes.FakeVectorPreferences
|
|
||||||
import io.mockk.coJustRun
|
|
||||||
import io.mockk.coVerify
|
|
||||||
import io.mockk.mockk
|
|
||||||
import io.mockk.verify
|
|
||||||
import kotlinx.coroutines.test.runTest
|
|
||||||
import org.junit.Test
|
|
||||||
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
|
||||||
|
|
||||||
class CreateNotificationSettingsAccountDataUseCaseTest {
|
|
||||||
|
|
||||||
private val fakeVectorPreferences = FakeVectorPreferences()
|
|
||||||
private val fakeSetNotificationSettingsAccountDataUseCase = mockk<SetNotificationSettingsAccountDataUseCase>()
|
|
||||||
|
|
||||||
private val createNotificationSettingsAccountDataUseCase = CreateNotificationSettingsAccountDataUseCase(
|
|
||||||
vectorPreferences = fakeVectorPreferences.instance,
|
|
||||||
setNotificationSettingsAccountDataUseCase = fakeSetNotificationSettingsAccountDataUseCase,
|
|
||||||
)
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `given a device id when execute then content with the current notification preference is set for the account data`() = runTest {
|
|
||||||
// Given
|
|
||||||
val aDeviceId = "device-id"
|
|
||||||
val session = FakeSession()
|
|
||||||
session.givenSessionId(aDeviceId)
|
|
||||||
coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any()) }
|
|
||||||
val areNotificationsEnabled = true
|
|
||||||
fakeVectorPreferences.givenAreNotificationEnabled(areNotificationsEnabled)
|
|
||||||
val expectedContent = LocalNotificationSettingsContent(
|
|
||||||
isSilenced = !areNotificationsEnabled
|
|
||||||
)
|
|
||||||
|
|
||||||
// When
|
|
||||||
createNotificationSettingsAccountDataUseCase.execute(session)
|
|
||||||
|
|
||||||
// Then
|
|
||||||
verify { fakeVectorPreferences.instance.areNotificationEnabledForDevice() }
|
|
||||||
coVerify { fakeSetNotificationSettingsAccountDataUseCase.execute(aDeviceId, expectedContent) }
|
|
||||||
}
|
|
||||||
}
|
|
@ -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.test.fakes.FakeSession
|
||||||
import io.mockk.coJustRun
|
import io.mockk.coJustRun
|
||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
@ -35,15 +36,17 @@ class DeleteNotificationSettingsAccountDataUseCaseTest {
|
|||||||
fun `given a device id when execute then empty content is set for the account data`() = runTest {
|
fun `given a device id when execute then empty content is set for the account data`() = runTest {
|
||||||
// Given
|
// Given
|
||||||
val aDeviceId = "device-id"
|
val aDeviceId = "device-id"
|
||||||
coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any()) }
|
val aSession = FakeSession()
|
||||||
|
aSession.givenSessionId(aDeviceId)
|
||||||
|
coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any(), any()) }
|
||||||
val expectedContent = LocalNotificationSettingsContent(
|
val expectedContent = LocalNotificationSettingsContent(
|
||||||
isSilenced = null
|
isSilenced = null
|
||||||
)
|
)
|
||||||
|
|
||||||
// When
|
// When
|
||||||
deleteNotificationSettingsAccountDataUseCase.execute(aDeviceId)
|
deleteNotificationSettingsAccountDataUseCase.execute(aSession)
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
coVerify { fakeSetNotificationSettingsAccountDataUseCase.execute(aDeviceId, expectedContent) }
|
coVerify { fakeSetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId, expectedContent) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.app.features.settings.devices.v2.notification
|
||||||
|
|
||||||
|
import im.vector.app.test.fakes.FakeSession
|
||||||
|
import org.amshove.kluent.shouldBeEqualTo
|
||||||
|
import org.junit.Test
|
||||||
|
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
||||||
|
import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes
|
||||||
|
import org.matrix.android.sdk.api.session.events.model.toContent
|
||||||
|
|
||||||
|
class GetNotificationSettingsAccountDataUseCaseTest {
|
||||||
|
|
||||||
|
private val getNotificationSettingsAccountDataUseCase = GetNotificationSettingsAccountDataUseCase()
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given a device id when execute then retrieve the account data event corresponding to this id if any`() {
|
||||||
|
// Given
|
||||||
|
val aDeviceId = "device-id"
|
||||||
|
val aSession = FakeSession()
|
||||||
|
val expectedContent = LocalNotificationSettingsContent()
|
||||||
|
aSession
|
||||||
|
.accountDataService()
|
||||||
|
.givenGetUserAccountDataEventReturns(
|
||||||
|
type = UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + aDeviceId,
|
||||||
|
content = expectedContent.toContent(),
|
||||||
|
)
|
||||||
|
|
||||||
|
// When
|
||||||
|
val result = getNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
result shouldBeEqualTo expectedContent
|
||||||
|
}
|
||||||
|
}
|
@ -53,8 +53,8 @@ class GetNotificationsStatusUseCaseTest {
|
|||||||
|
|
||||||
private val getNotificationsStatusUseCase =
|
private val getNotificationsStatusUseCase =
|
||||||
GetNotificationsStatusUseCase(
|
GetNotificationsStatusUseCase(
|
||||||
checkIfCanTogglePushNotificationsViaAccountDataUseCase = fakeCheckIfCanToggleNotificationsViaAccountDataUseCase,
|
checkIfCanToggleNotificationsViaAccountDataUseCase = fakeCheckIfCanToggleNotificationsViaAccountDataUseCase,
|
||||||
canTogglePushNotificationsViaPusherUseCase = fakeCanToggleNotificationsViaPusherUseCase,
|
canToggleNotificationsViaPusherUseCase = fakeCanToggleNotificationsViaPusherUseCase,
|
||||||
)
|
)
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
|
@ -16,7 +16,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.FakeActiveSessionHolder
|
import im.vector.app.test.fakes.FakeSession
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
import org.junit.Test
|
import org.junit.Test
|
||||||
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
||||||
@ -25,25 +25,21 @@ import org.matrix.android.sdk.api.session.events.model.toContent
|
|||||||
|
|
||||||
class SetNotificationSettingsAccountDataUseCaseTest {
|
class SetNotificationSettingsAccountDataUseCaseTest {
|
||||||
|
|
||||||
private val activeSessionHolder = FakeActiveSessionHolder()
|
private val setNotificationSettingsAccountDataUseCase = SetNotificationSettingsAccountDataUseCase()
|
||||||
|
|
||||||
private val setNotificationSettingsAccountDataUseCase = SetNotificationSettingsAccountDataUseCase(
|
|
||||||
activeSessionHolder = activeSessionHolder.instance,
|
|
||||||
)
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `given a content when execute then update local notification settings with this content`() = runTest {
|
fun `given a content when execute then update local notification settings with this content`() = runTest {
|
||||||
// Given
|
// Given
|
||||||
val sessionId = "a_session_id"
|
val sessionId = "a_session_id"
|
||||||
val localNotificationSettingsContent = LocalNotificationSettingsContent()
|
val localNotificationSettingsContent = LocalNotificationSettingsContent()
|
||||||
val fakeSession = activeSessionHolder.fakeSession
|
val fakeSession = FakeSession()
|
||||||
fakeSession.accountDataService().givenUpdateUserAccountDataEventSucceeds()
|
fakeSession.accountDataService().givenUpdateUserAccountDataEventSucceeds()
|
||||||
|
|
||||||
// When
|
// When
|
||||||
setNotificationSettingsAccountDataUseCase.execute(sessionId, localNotificationSettingsContent)
|
setNotificationSettingsAccountDataUseCase.execute(fakeSession, sessionId, localNotificationSettingsContent)
|
||||||
|
|
||||||
// Then
|
// Then
|
||||||
activeSessionHolder.fakeSession.accountDataService().verifyUpdateUserAccountDataEventSucceeds(
|
fakeSession.accountDataService().verifyUpdateUserAccountDataEventSucceeds(
|
||||||
UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + sessionId,
|
UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + sessionId,
|
||||||
localNotificationSettingsContent.toContent(),
|
localNotificationSettingsContent.toContent(),
|
||||||
)
|
)
|
||||||
|
@ -39,8 +39,8 @@ class ToggleNotificationUseCaseTest {
|
|||||||
private val toggleNotificationUseCase =
|
private val toggleNotificationUseCase =
|
||||||
ToggleNotificationUseCase(
|
ToggleNotificationUseCase(
|
||||||
activeSessionHolder = activeSessionHolder.instance,
|
activeSessionHolder = activeSessionHolder.instance,
|
||||||
checkIfCanTogglePushNotificationsViaPusherUseCase = fakeCheckIfCanToggleNotificationsViaPusherUseCase,
|
checkIfCanToggleNotificationsViaPusherUseCase = fakeCheckIfCanToggleNotificationsViaPusherUseCase,
|
||||||
checkIfCanTogglePushNotificationsViaAccountDataUseCase = fakeCheckIfCanToggleNotificationsViaAccountDataUseCase,
|
checkIfCanToggleNotificationsViaAccountDataUseCase = fakeCheckIfCanToggleNotificationsViaAccountDataUseCase,
|
||||||
setNotificationSettingsAccountDataUseCase = fakeSetNotificationSettingsAccountDataUseCase,
|
setNotificationSettingsAccountDataUseCase = fakeSetNotificationSettingsAccountDataUseCase,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -72,7 +72,7 @@ class ToggleNotificationUseCaseTest {
|
|||||||
val fakeSession = activeSessionHolder.fakeSession
|
val fakeSession = activeSessionHolder.fakeSession
|
||||||
every { fakeCheckIfCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns false
|
every { fakeCheckIfCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns false
|
||||||
every { fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, sessionId) } returns true
|
every { fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, sessionId) } returns true
|
||||||
coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any()) }
|
coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any(), any()) }
|
||||||
val expectedLocalNotificationSettingsContent = LocalNotificationSettingsContent(
|
val expectedLocalNotificationSettingsContent = LocalNotificationSettingsContent(
|
||||||
isSilenced = false
|
isSilenced = false
|
||||||
)
|
)
|
||||||
@ -82,7 +82,7 @@ class ToggleNotificationUseCaseTest {
|
|||||||
|
|
||||||
// Then
|
// Then
|
||||||
coVerify {
|
coVerify {
|
||||||
fakeSetNotificationSettingsAccountDataUseCase.execute(sessionId, expectedLocalNotificationSettingsContent)
|
fakeSetNotificationSettingsAccountDataUseCase.execute(fakeSession, sessionId, expectedLocalNotificationSettingsContent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2022 New Vector Ltd
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package im.vector.app.features.settings.devices.v2.notification
|
||||||
|
|
||||||
|
import im.vector.app.test.fakes.FakeSession
|
||||||
|
import im.vector.app.test.fakes.FakeVectorPreferences
|
||||||
|
import io.mockk.coJustRun
|
||||||
|
import io.mockk.coVerify
|
||||||
|
import io.mockk.every
|
||||||
|
import io.mockk.mockk
|
||||||
|
import io.mockk.verify
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
|
import org.junit.Test
|
||||||
|
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
|
||||||
|
|
||||||
|
class UpdateNotificationSettingsAccountDataUseCaseTest {
|
||||||
|
|
||||||
|
private val fakeVectorPreferences = FakeVectorPreferences()
|
||||||
|
private val fakeGetNotificationSettingsAccountDataUseCase = mockk<GetNotificationSettingsAccountDataUseCase>()
|
||||||
|
private val fakeSetNotificationSettingsAccountDataUseCase = mockk<SetNotificationSettingsAccountDataUseCase>()
|
||||||
|
|
||||||
|
private val updateNotificationSettingsAccountDataUseCase = UpdateNotificationSettingsAccountDataUseCase(
|
||||||
|
vectorPreferences = fakeVectorPreferences.instance,
|
||||||
|
getNotificationSettingsAccountDataUseCase = fakeGetNotificationSettingsAccountDataUseCase,
|
||||||
|
setNotificationSettingsAccountDataUseCase = fakeSetNotificationSettingsAccountDataUseCase,
|
||||||
|
)
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given a device id and a different local setting compared to remote when execute then content is updated`() = runTest {
|
||||||
|
// Given
|
||||||
|
val aDeviceId = "device-id"
|
||||||
|
val aSession = FakeSession()
|
||||||
|
aSession.givenSessionId(aDeviceId)
|
||||||
|
coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any(), any()) }
|
||||||
|
val areNotificationsEnabled = true
|
||||||
|
fakeVectorPreferences.givenAreNotificationEnabled(areNotificationsEnabled)
|
||||||
|
every { fakeGetNotificationSettingsAccountDataUseCase.execute(any(), any()) } returns
|
||||||
|
LocalNotificationSettingsContent(
|
||||||
|
isSilenced = null
|
||||||
|
)
|
||||||
|
val expectedContent = LocalNotificationSettingsContent(
|
||||||
|
isSilenced = !areNotificationsEnabled
|
||||||
|
)
|
||||||
|
|
||||||
|
// When
|
||||||
|
updateNotificationSettingsAccountDataUseCase.execute(aSession)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
verify {
|
||||||
|
fakeVectorPreferences.instance.areNotificationEnabledForDevice()
|
||||||
|
fakeGetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId)
|
||||||
|
}
|
||||||
|
coVerify { fakeSetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId, expectedContent) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `given a device id and a same local setting compared to remote when execute then content is not updated`() = runTest {
|
||||||
|
// Given
|
||||||
|
val aDeviceId = "device-id"
|
||||||
|
val aSession = FakeSession()
|
||||||
|
aSession.givenSessionId(aDeviceId)
|
||||||
|
coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any(), any()) }
|
||||||
|
val areNotificationsEnabled = true
|
||||||
|
fakeVectorPreferences.givenAreNotificationEnabled(areNotificationsEnabled)
|
||||||
|
every { fakeGetNotificationSettingsAccountDataUseCase.execute(any(), any()) } returns
|
||||||
|
LocalNotificationSettingsContent(
|
||||||
|
isSilenced = false
|
||||||
|
)
|
||||||
|
val expectedContent = LocalNotificationSettingsContent(
|
||||||
|
isSilenced = !areNotificationsEnabled
|
||||||
|
)
|
||||||
|
|
||||||
|
// When
|
||||||
|
updateNotificationSettingsAccountDataUseCase.execute(aSession)
|
||||||
|
|
||||||
|
// Then
|
||||||
|
verify {
|
||||||
|
fakeVectorPreferences.instance.areNotificationEnabledForDevice()
|
||||||
|
fakeGetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId)
|
||||||
|
}
|
||||||
|
coVerify(inverse = true) { fakeSetNotificationSettingsAccountDataUseCase.execute(aSession, aDeviceId, expectedContent) }
|
||||||
|
}
|
||||||
|
}
|
@ -30,7 +30,7 @@ import im.vector.app.test.fakes.FakeActiveSessionHolder
|
|||||||
import im.vector.app.test.fakes.FakeGetNotificationsStatusUseCase
|
import im.vector.app.test.fakes.FakeGetNotificationsStatusUseCase
|
||||||
import im.vector.app.test.fakes.FakePendingAuthHandler
|
import im.vector.app.test.fakes.FakePendingAuthHandler
|
||||||
import im.vector.app.test.fakes.FakeSignoutSessionsUseCase
|
import im.vector.app.test.fakes.FakeSignoutSessionsUseCase
|
||||||
import im.vector.app.test.fakes.FakeTogglePushNotificationUseCase
|
import im.vector.app.test.fakes.FakeToggleNotificationUseCase
|
||||||
import im.vector.app.test.fakes.FakeVectorPreferences
|
import im.vector.app.test.fakes.FakeVectorPreferences
|
||||||
import im.vector.app.test.fakes.FakeVerificationService
|
import im.vector.app.test.fakes.FakeVerificationService
|
||||||
import im.vector.app.test.test
|
import im.vector.app.test.test
|
||||||
@ -76,7 +76,7 @@ class SessionOverviewViewModelTest {
|
|||||||
private val interceptSignoutFlowResponseUseCase = mockk<InterceptSignoutFlowResponseUseCase>()
|
private val interceptSignoutFlowResponseUseCase = mockk<InterceptSignoutFlowResponseUseCase>()
|
||||||
private val fakePendingAuthHandler = FakePendingAuthHandler()
|
private val fakePendingAuthHandler = FakePendingAuthHandler()
|
||||||
private val refreshDevicesUseCase = mockk<RefreshDevicesUseCase>(relaxed = true)
|
private val refreshDevicesUseCase = mockk<RefreshDevicesUseCase>(relaxed = true)
|
||||||
private val togglePushNotificationUseCase = FakeTogglePushNotificationUseCase()
|
private val toggleNotificationUseCase = FakeToggleNotificationUseCase()
|
||||||
private val fakeGetNotificationsStatusUseCase = FakeGetNotificationsStatusUseCase()
|
private val fakeGetNotificationsStatusUseCase = FakeGetNotificationsStatusUseCase()
|
||||||
private val notificationsStatus = NotificationsStatus.ENABLED
|
private val notificationsStatus = NotificationsStatus.ENABLED
|
||||||
private val fakeVectorPreferences = FakeVectorPreferences()
|
private val fakeVectorPreferences = FakeVectorPreferences()
|
||||||
@ -91,7 +91,7 @@ class SessionOverviewViewModelTest {
|
|||||||
pendingAuthHandler = fakePendingAuthHandler.instance,
|
pendingAuthHandler = fakePendingAuthHandler.instance,
|
||||||
activeSessionHolder = fakeActiveSessionHolder.instance,
|
activeSessionHolder = fakeActiveSessionHolder.instance,
|
||||||
refreshDevicesUseCase = refreshDevicesUseCase,
|
refreshDevicesUseCase = refreshDevicesUseCase,
|
||||||
togglePushNotificationUseCase = togglePushNotificationUseCase.instance,
|
toggleNotificationUseCase = toggleNotificationUseCase.instance,
|
||||||
getNotificationsStatusUseCase = fakeGetNotificationsStatusUseCase.instance,
|
getNotificationsStatusUseCase = fakeGetNotificationsStatusUseCase.instance,
|
||||||
vectorPreferences = fakeVectorPreferences.instance,
|
vectorPreferences = fakeVectorPreferences.instance,
|
||||||
toggleIpAddressVisibilityUseCase = toggleIpAddressVisibilityUseCase,
|
toggleIpAddressVisibilityUseCase = toggleIpAddressVisibilityUseCase,
|
||||||
@ -436,7 +436,7 @@ class SessionOverviewViewModelTest {
|
|||||||
|
|
||||||
viewModel.handle(SessionOverviewAction.TogglePushNotifications(A_SESSION_ID_1, true))
|
viewModel.handle(SessionOverviewAction.TogglePushNotifications(A_SESSION_ID_1, true))
|
||||||
|
|
||||||
togglePushNotificationUseCase.verifyExecute(A_SESSION_ID_1, true)
|
toggleNotificationUseCase.verifyExecute(A_SESSION_ID_1, true)
|
||||||
viewModel.test().assertLatestState { state -> state.notificationsStatus == NotificationsStatus.ENABLED }.finish()
|
viewModel.test().assertLatestState { state -> state.notificationsStatus == NotificationsStatus.ENABLED }.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,11 +16,9 @@
|
|||||||
|
|
||||||
package im.vector.app.features.settings.notifications
|
package im.vector.app.features.settings.notifications
|
||||||
|
|
||||||
|
import im.vector.app.core.pushers.UnregisterUnifiedPushUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.notification.CheckIfCanToggleNotificationsViaPusherUseCase
|
import im.vector.app.features.settings.devices.v2.notification.CheckIfCanToggleNotificationsViaPusherUseCase
|
||||||
import im.vector.app.features.settings.devices.v2.notification.ToggleNotificationUseCase
|
import im.vector.app.features.settings.devices.v2.notification.ToggleNotificationUseCase
|
||||||
import im.vector.app.core.pushers.UnregisterUnifiedPushUseCase
|
|
||||||
import im.vector.app.features.settings.devices.v2.notification.CheckIfCanTogglePushNotificationsViaPusherUseCase
|
|
||||||
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
|
|
||||||
import im.vector.app.test.fakes.FakeActiveSessionHolder
|
import im.vector.app.test.fakes.FakeActiveSessionHolder
|
||||||
import im.vector.app.test.fakes.FakePushersManager
|
import im.vector.app.test.fakes.FakePushersManager
|
||||||
import io.mockk.coJustRun
|
import io.mockk.coJustRun
|
||||||
|
@ -21,7 +21,7 @@ import io.mockk.coJustRun
|
|||||||
import io.mockk.coVerify
|
import io.mockk.coVerify
|
||||||
import io.mockk.mockk
|
import io.mockk.mockk
|
||||||
|
|
||||||
class FakeTogglePushNotificationUseCase {
|
class FakeToggleNotificationUseCase {
|
||||||
|
|
||||||
val instance = mockk<ToggleNotificationUseCase> {
|
val instance = mockk<ToggleNotificationUseCase> {
|
||||||
coJustRun { execute(any(), any()) }
|
coJustRun { execute(any(), any()) }
|
@ -73,4 +73,8 @@ class FakeVectorPreferences {
|
|||||||
fun givenAreNotificationsEnabledForDevice(notificationsEnabled: Boolean) {
|
fun givenAreNotificationsEnabledForDevice(notificationsEnabled: Boolean) {
|
||||||
every { instance.areNotificationEnabledForDevice() } returns notificationsEnabled
|
every { instance.areNotificationEnabledForDevice() } returns notificationsEnabled
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun givenIsBackgroundSyncEnabled(isEnabled: Boolean) {
|
||||||
|
every { instance.isBackgroundSyncEnabled() } returns isEnabled
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user