Renaming some use cases to be consistent

This commit is contained in:
Maxime NATUREL 2022-11-17 11:04:21 +01:00
parent 14b21dc039
commit 7c51174d7e
16 changed files with 85 additions and 84 deletions

View file

@ -24,7 +24,7 @@ import org.matrix.android.sdk.api.session.Session
import org.matrix.android.sdk.flow.unwrap
import javax.inject.Inject
class CanTogglePushNotificationsViaPusherUseCase @Inject constructor() {
class CanToggleNotificationsViaPusherUseCase @Inject constructor() {
fun execute(session: Session): Flow<Boolean> {
return session

View file

@ -22,7 +22,7 @@ import org.matrix.android.sdk.api.session.accountdata.UserAccountDataTypes
import org.matrix.android.sdk.api.session.events.model.toModel
import javax.inject.Inject
class CheckIfCanTogglePushNotificationsViaAccountDataUseCase @Inject constructor() {
class CheckIfCanToggleNotificationsViaAccountDataUseCase @Inject constructor() {
fun execute(session: Session, deviceId: String): Boolean {
return session

View file

@ -19,7 +19,7 @@ package im.vector.app.features.settings.devices.v2.notification
import org.matrix.android.sdk.api.session.Session
import javax.inject.Inject
class CheckIfCanTogglePushNotificationsViaPusherUseCase @Inject constructor() {
class CheckIfCanToggleNotificationsViaPusherUseCase @Inject constructor() {
fun execute(session: Session): Boolean {
return session

View file

@ -30,13 +30,13 @@ import org.matrix.android.sdk.flow.unwrap
import javax.inject.Inject
class GetNotificationsStatusUseCase @Inject constructor(
private val canTogglePushNotificationsViaPusherUseCase: CanTogglePushNotificationsViaPusherUseCase,
private val checkIfCanTogglePushNotificationsViaAccountDataUseCase: CheckIfCanTogglePushNotificationsViaAccountDataUseCase,
private val canToggleNotificationsViaPusherUseCase: CanToggleNotificationsViaPusherUseCase,
private val checkIfCanToggleNotificationsViaAccountDataUseCase: CheckIfCanToggleNotificationsViaAccountDataUseCase,
) {
fun execute(session: Session, deviceId: String): Flow<NotificationsStatus> {
return when {
checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(session, deviceId) -> {
checkIfCanToggleNotificationsViaAccountDataUseCase.execute(session, deviceId) -> {
session.flow()
.liveUserAccountData(UserAccountDataTypes.TYPE_LOCAL_NOTIFICATION_SETTINGS + deviceId)
.unwrap()
@ -44,7 +44,7 @@ class GetNotificationsStatusUseCase @Inject constructor(
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED }
.distinctUntilChanged()
}
else -> canTogglePushNotificationsViaPusherUseCase.execute(session)
else -> canToggleNotificationsViaPusherUseCase.execute(session)
.flatMapLatest { canToggle ->
if (canToggle) {
session.flow()

View file

@ -20,25 +20,24 @@ import im.vector.app.core.di.ActiveSessionHolder
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
import javax.inject.Inject
// TODO rename into ToggleNotificationsUseCase
class TogglePushNotificationUseCase @Inject constructor(
class ToggleNotificationUseCase @Inject constructor(
private val activeSessionHolder: ActiveSessionHolder,
private val checkIfCanTogglePushNotificationsViaPusherUseCase: CheckIfCanTogglePushNotificationsViaPusherUseCase,
private val checkIfCanTogglePushNotificationsViaAccountDataUseCase: CheckIfCanTogglePushNotificationsViaAccountDataUseCase,
private val checkIfCanToggleNotificationsViaPusherUseCase: CheckIfCanToggleNotificationsViaPusherUseCase,
private val checkIfCanToggleNotificationsViaAccountDataUseCase: CheckIfCanToggleNotificationsViaAccountDataUseCase,
private val setNotificationSettingsAccountDataUseCase: SetNotificationSettingsAccountDataUseCase,
) {
suspend fun execute(deviceId: String, enabled: Boolean) {
val session = activeSessionHolder.getSafeActiveSession() ?: return
if (checkIfCanTogglePushNotificationsViaPusherUseCase.execute(session)) {
if (checkIfCanToggleNotificationsViaPusherUseCase.execute(session)) {
val devicePusher = session.pushersService().getPushers().firstOrNull { it.deviceId == deviceId }
devicePusher?.let { pusher ->
session.pushersService().togglePusher(pusher, enabled)
}
}
if (checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(session, deviceId)) {
if (checkIfCanToggleNotificationsViaAccountDataUseCase.execute(session, deviceId)) {
val newNotificationSettingsContent = LocalNotificationSettingsContent(isSilenced = !enabled)
setNotificationSettingsAccountDataUseCase.execute(deviceId, newNotificationSettingsContent)
}

View file

@ -31,7 +31,7 @@ import im.vector.app.features.settings.devices.v2.RefreshDevicesUseCase
import im.vector.app.features.settings.devices.v2.ToggleIpAddressVisibilityUseCase
import im.vector.app.features.settings.devices.v2.VectorSessionsListViewModel
import im.vector.app.features.settings.devices.v2.notification.GetNotificationsStatusUseCase
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
import im.vector.app.features.settings.devices.v2.notification.ToggleNotificationUseCase
import im.vector.app.features.settings.devices.v2.signout.InterceptSignoutFlowResponseUseCase
import im.vector.app.features.settings.devices.v2.signout.SignoutSessionsReAuthNeeded
import im.vector.app.features.settings.devices.v2.signout.SignoutSessionsUseCase
@ -54,7 +54,7 @@ class SessionOverviewViewModel @AssistedInject constructor(
private val interceptSignoutFlowResponseUseCase: InterceptSignoutFlowResponseUseCase,
private val pendingAuthHandler: PendingAuthHandler,
private val activeSessionHolder: ActiveSessionHolder,
private val togglePushNotificationUseCase: TogglePushNotificationUseCase,
private val toggleNotificationUseCase: ToggleNotificationUseCase,
private val getNotificationsStatusUseCase: GetNotificationsStatusUseCase,
refreshDevicesUseCase: RefreshDevicesUseCase,
private val vectorPreferences: VectorPreferences,
@ -228,7 +228,7 @@ class SessionOverviewViewModel @AssistedInject constructor(
private fun handleTogglePusherAction(action: SessionOverviewAction.TogglePushNotifications) {
viewModelScope.launch {
togglePushNotificationUseCase.execute(action.deviceId, action.enabled)
toggleNotificationUseCase.execute(action.deviceId, action.enabled)
}
}
}

View file

@ -19,23 +19,23 @@ package im.vector.app.features.settings.notifications
import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.pushers.PushersManager
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.features.settings.devices.v2.notification.CheckIfCanToggleNotificationsViaPusherUseCase
import im.vector.app.features.settings.devices.v2.notification.ToggleNotificationUseCase
import javax.inject.Inject
class DisableNotificationsForCurrentSessionUseCase @Inject constructor(
private val activeSessionHolder: ActiveSessionHolder,
private val pushersManager: PushersManager,
private val checkIfCanTogglePushNotificationsViaPusherUseCase: CheckIfCanTogglePushNotificationsViaPusherUseCase,
private val togglePushNotificationUseCase: TogglePushNotificationUseCase,
private val checkIfCanToggleNotificationsViaPusherUseCase: CheckIfCanToggleNotificationsViaPusherUseCase,
private val toggleNotificationUseCase: ToggleNotificationUseCase,
private val unregisterUnifiedPushUseCase: UnregisterUnifiedPushUseCase,
) {
suspend fun execute() {
val session = activeSessionHolder.getSafeActiveSession() ?: return
val deviceId = session.sessionParams.deviceId ?: return
togglePushNotificationUseCase.execute(deviceId, enabled = false)
if (!checkIfCanTogglePushNotificationsViaPusherUseCase.execute(session)) {
toggleNotificationUseCase.execute(deviceId, enabled = false)
if (!checkIfCanToggleNotificationsViaPusherUseCase.execute(session)) {
unregisterUnifiedPushUseCase.execute(pushersManager)
}
}

View file

@ -20,13 +20,13 @@ import im.vector.app.core.di.ActiveSessionHolder
import im.vector.app.core.pushers.EnsureFcmTokenIsRetrievedUseCase
import im.vector.app.core.pushers.PushersManager
import im.vector.app.core.pushers.RegisterUnifiedPushUseCase
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
import im.vector.app.features.settings.devices.v2.notification.ToggleNotificationUseCase
import javax.inject.Inject
class EnableNotificationsForCurrentSessionUseCase @Inject constructor(
private val activeSessionHolder: ActiveSessionHolder,
private val pushersManager: PushersManager,
private val togglePushNotificationUseCase: TogglePushNotificationUseCase,
private val toggleNotificationUseCase: ToggleNotificationUseCase,
private val registerUnifiedPushUseCase: RegisterUnifiedPushUseCase,
private val ensureFcmTokenIsRetrievedUseCase: EnsureFcmTokenIsRetrievedUseCase,
) {
@ -52,7 +52,7 @@ class EnableNotificationsForCurrentSessionUseCase @Inject constructor(
val session = activeSessionHolder.getSafeActiveSession() ?: return EnableNotificationsResult.Failure
val deviceId = session.sessionParams.deviceId ?: return EnableNotificationsResult.Failure
togglePushNotificationUseCase.execute(deviceId, enabled = true)
toggleNotificationUseCase.execute(deviceId, enabled = true)
return EnableNotificationsResult.Success
}

View file

@ -30,13 +30,13 @@ import org.junit.Test
private val A_HOMESERVER_CAPABILITIES = aHomeServerCapabilities(canRemotelyTogglePushNotificationsOfDevices = true)
class CanTogglePushNotificationsViaPusherUseCaseTest {
class CanToggleNotificationsViaPusherUseCaseTest {
private val fakeSession = FakeSession()
private val fakeFlowLiveDataConversions = FakeFlowLiveDataConversions()
private val canTogglePushNotificationsViaPusherUseCase =
CanTogglePushNotificationsViaPusherUseCase()
private val canToggleNotificationsViaPusherUseCase =
CanToggleNotificationsViaPusherUseCase()
@Before
fun setUp() {
@ -57,7 +57,7 @@ class CanTogglePushNotificationsViaPusherUseCaseTest {
.givenAsFlow()
// When
val result = canTogglePushNotificationsViaPusherUseCase.execute(fakeSession).firstOrNull()
val result = canToggleNotificationsViaPusherUseCase.execute(fakeSession).firstOrNull()
// Then
result shouldBeEqualTo A_HOMESERVER_CAPABILITIES.canRemotelyTogglePushNotificationsOfDevices

View file

@ -26,12 +26,12 @@ import org.matrix.android.sdk.api.session.events.model.toContent
private const val A_DEVICE_ID = "device-id"
class CheckIfCanTogglePushNotificationsViaAccountDataUseCaseTest {
class CheckIfCanToggleNotificationsViaAccountDataUseCaseTest {
private val fakeSession = FakeSession()
private val checkIfCanTogglePushNotificationsViaAccountDataUseCase =
CheckIfCanTogglePushNotificationsViaAccountDataUseCase()
private val checkIfCanToggleNotificationsViaAccountDataUseCase =
CheckIfCanToggleNotificationsViaAccountDataUseCase()
@Test
fun `given current session and an account data with a content for the device id when execute then result is true`() {
@ -44,7 +44,7 @@ class CheckIfCanTogglePushNotificationsViaAccountDataUseCaseTest {
)
// When
val result = checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
val result = checkIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
// Then
result shouldBeEqualTo true
@ -61,7 +61,7 @@ class CheckIfCanTogglePushNotificationsViaAccountDataUseCaseTest {
)
// When
val result = checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
val result = checkIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
// Then
result shouldBeEqualTo false
@ -78,7 +78,7 @@ class CheckIfCanTogglePushNotificationsViaAccountDataUseCaseTest {
)
// When
val result = checkIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
val result = checkIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
// Then
result shouldBeEqualTo false

View file

@ -23,12 +23,12 @@ import org.junit.Test
private val A_HOMESERVER_CAPABILITIES = aHomeServerCapabilities(canRemotelyTogglePushNotificationsOfDevices = true)
class CheckIfCanTogglePushNotificationsViaPusherUseCaseTest {
class CheckIfCanToggleNotificationsViaPusherUseCaseTest {
private val fakeSession = FakeSession()
private val checkIfCanTogglePushNotificationsViaPusherUseCase =
CheckIfCanTogglePushNotificationsViaPusherUseCase()
private val checkIfCanToggleNotificationsViaPusherUseCase =
CheckIfCanToggleNotificationsViaPusherUseCase()
@Test
fun `given current session when execute then toggle capability is returned`() {
@ -38,7 +38,7 @@ class CheckIfCanTogglePushNotificationsViaPusherUseCaseTest {
.givenCapabilities(A_HOMESERVER_CAPABILITIES)
// When
val result = checkIfCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession)
val result = checkIfCanToggleNotificationsViaPusherUseCase.execute(fakeSession)
// Then
result shouldBeEqualTo A_HOMESERVER_CAPABILITIES.canRemotelyTogglePushNotificationsOfDevices

View file

@ -46,15 +46,15 @@ class GetNotificationsStatusUseCaseTest {
val instantTaskExecutorRule = InstantTaskExecutorRule()
private val fakeSession = FakeSession()
private val fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase =
mockk<CheckIfCanTogglePushNotificationsViaAccountDataUseCase>()
private val fakeCanTogglePushNotificationsViaPusherUseCase =
mockk<CanTogglePushNotificationsViaPusherUseCase>()
private val fakeCheckIfCanToggleNotificationsViaAccountDataUseCase =
mockk<CheckIfCanToggleNotificationsViaAccountDataUseCase>()
private val fakeCanToggleNotificationsViaPusherUseCase =
mockk<CanToggleNotificationsViaPusherUseCase>()
private val getNotificationsStatusUseCase =
GetNotificationsStatusUseCase(
checkIfCanTogglePushNotificationsViaAccountDataUseCase = fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase,
canTogglePushNotificationsViaPusherUseCase = fakeCanTogglePushNotificationsViaPusherUseCase,
checkIfCanTogglePushNotificationsViaAccountDataUseCase = fakeCheckIfCanToggleNotificationsViaAccountDataUseCase,
canTogglePushNotificationsViaPusherUseCase = fakeCanToggleNotificationsViaPusherUseCase,
)
@Before
@ -70,8 +70,8 @@ class GetNotificationsStatusUseCaseTest {
@Test
fun `given current session and toggle is not supported when execute then resulting flow contains NOT_SUPPORTED value`() = runTest {
// Given
every { fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns false
every { fakeCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns flowOf(false)
every { fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns false
every { fakeCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns flowOf(false)
// When
val result = getNotificationsStatusUseCase.execute(fakeSession, A_DEVICE_ID)
@ -80,8 +80,8 @@ class GetNotificationsStatusUseCaseTest {
result.firstOrNull() shouldBeEqualTo NotificationsStatus.NOT_SUPPORTED
verifyOrder {
// we should first check account data
fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
fakeCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession)
fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID)
fakeCanToggleNotificationsViaPusherUseCase.execute(fakeSession)
}
}
@ -95,8 +95,8 @@ class GetNotificationsStatusUseCaseTest {
)
)
fakeSession.pushersService().givenPushersLive(pushers)
every { fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns false
every { fakeCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns flowOf(true)
every { fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns false
every { fakeCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns flowOf(true)
// When
val result = getNotificationsStatusUseCase.execute(fakeSession, A_DEVICE_ID)
@ -116,8 +116,8 @@ class GetNotificationsStatusUseCaseTest {
isSilenced = false
).toContent(),
)
every { fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns true
every { fakeCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns flowOf(false)
every { fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, A_DEVICE_ID) } returns true
every { fakeCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns flowOf(false)
// When
val result = getNotificationsStatusUseCase.execute(fakeSession, A_DEVICE_ID)

View file

@ -26,21 +26,21 @@ import kotlinx.coroutines.test.runTest
import org.junit.Test
import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
class TogglePushNotificationUseCaseTest {
class ToggleNotificationUseCaseTest {
private val activeSessionHolder = FakeActiveSessionHolder()
private val fakeCheckIfCanTogglePushNotificationsViaPusherUseCase =
mockk<CheckIfCanTogglePushNotificationsViaPusherUseCase>()
private val fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase =
mockk<CheckIfCanTogglePushNotificationsViaAccountDataUseCase>()
private val fakeCheckIfCanToggleNotificationsViaPusherUseCase =
mockk<CheckIfCanToggleNotificationsViaPusherUseCase>()
private val fakeCheckIfCanToggleNotificationsViaAccountDataUseCase =
mockk<CheckIfCanToggleNotificationsViaAccountDataUseCase>()
private val fakeSetNotificationSettingsAccountDataUseCase =
mockk<SetNotificationSettingsAccountDataUseCase>()
private val togglePushNotificationUseCase =
TogglePushNotificationUseCase(
private val toggleNotificationUseCase =
ToggleNotificationUseCase(
activeSessionHolder = activeSessionHolder.instance,
checkIfCanTogglePushNotificationsViaPusherUseCase = fakeCheckIfCanTogglePushNotificationsViaPusherUseCase,
checkIfCanTogglePushNotificationsViaAccountDataUseCase = fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase,
checkIfCanTogglePushNotificationsViaPusherUseCase = fakeCheckIfCanToggleNotificationsViaPusherUseCase,
checkIfCanTogglePushNotificationsViaAccountDataUseCase = fakeCheckIfCanToggleNotificationsViaAccountDataUseCase,
setNotificationSettingsAccountDataUseCase = fakeSetNotificationSettingsAccountDataUseCase,
)
@ -55,11 +55,11 @@ class TogglePushNotificationUseCaseTest {
val fakeSession = activeSessionHolder.fakeSession
fakeSession.pushersService().givenPushersLive(pushers)
fakeSession.pushersService().givenGetPushers(pushers)
every { fakeCheckIfCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns true
every { fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, sessionId) } returns false
every { fakeCheckIfCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns true
every { fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, sessionId) } returns false
// When
togglePushNotificationUseCase.execute(sessionId, true)
toggleNotificationUseCase.execute(sessionId, true)
// Then
activeSessionHolder.fakeSession.pushersService().verifyTogglePusherCalled(pushers.first(), true)
@ -70,15 +70,15 @@ class TogglePushNotificationUseCaseTest {
// Given
val sessionId = "a_session_id"
val fakeSession = activeSessionHolder.fakeSession
every { fakeCheckIfCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns false
every { fakeCheckIfCanTogglePushNotificationsViaAccountDataUseCase.execute(fakeSession, sessionId) } returns true
every { fakeCheckIfCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns false
every { fakeCheckIfCanToggleNotificationsViaAccountDataUseCase.execute(fakeSession, sessionId) } returns true
coJustRun { fakeSetNotificationSettingsAccountDataUseCase.execute(any(), any()) }
val expectedLocalNotificationSettingsContent = LocalNotificationSettingsContent(
isSilenced = false
)
// When
togglePushNotificationUseCase.execute(sessionId, true)
toggleNotificationUseCase.execute(sessionId, true)
// Then
coVerify {

View file

@ -16,6 +16,8 @@
package im.vector.app.features.settings.notifications
import im.vector.app.features.settings.devices.v2.notification.CheckIfCanToggleNotificationsViaPusherUseCase
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
@ -34,15 +36,15 @@ class DisableNotificationsForCurrentSessionUseCaseTest {
private val fakeActiveSessionHolder = FakeActiveSessionHolder()
private val fakePushersManager = FakePushersManager()
private val fakeCheckIfCanTogglePushNotificationsViaPusherUseCase = mockk<CheckIfCanTogglePushNotificationsViaPusherUseCase>()
private val fakeTogglePushNotificationUseCase = mockk<TogglePushNotificationUseCase>()
private val fakeCheckIfCanToggleNotificationsViaPusherUseCase = mockk<CheckIfCanToggleNotificationsViaPusherUseCase>()
private val fakeToggleNotificationUseCase = mockk<ToggleNotificationUseCase>()
private val fakeUnregisterUnifiedPushUseCase = mockk<UnregisterUnifiedPushUseCase>()
private val disableNotificationsForCurrentSessionUseCase = DisableNotificationsForCurrentSessionUseCase(
activeSessionHolder = fakeActiveSessionHolder.instance,
pushersManager = fakePushersManager.instance,
checkIfCanTogglePushNotificationsViaPusherUseCase = fakeCheckIfCanTogglePushNotificationsViaPusherUseCase,
togglePushNotificationUseCase = fakeTogglePushNotificationUseCase,
checkIfCanToggleNotificationsViaPusherUseCase = fakeCheckIfCanToggleNotificationsViaPusherUseCase,
toggleNotificationUseCase = fakeToggleNotificationUseCase,
unregisterUnifiedPushUseCase = fakeUnregisterUnifiedPushUseCase,
)
@ -51,14 +53,14 @@ class DisableNotificationsForCurrentSessionUseCaseTest {
// Given
val fakeSession = fakeActiveSessionHolder.fakeSession
fakeSession.givenSessionId(A_SESSION_ID)
every { fakeCheckIfCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns true
coJustRun { fakeTogglePushNotificationUseCase.execute(A_SESSION_ID, any()) }
every { fakeCheckIfCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns true
coJustRun { fakeToggleNotificationUseCase.execute(A_SESSION_ID, any()) }
// When
disableNotificationsForCurrentSessionUseCase.execute()
// Then
coVerify { fakeTogglePushNotificationUseCase.execute(A_SESSION_ID, false) }
coVerify { fakeToggleNotificationUseCase.execute(A_SESSION_ID, false) }
}
@Test
@ -66,8 +68,8 @@ class DisableNotificationsForCurrentSessionUseCaseTest {
// Given
val fakeSession = fakeActiveSessionHolder.fakeSession
fakeSession.givenSessionId(A_SESSION_ID)
every { fakeCheckIfCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns false
coJustRun { fakeTogglePushNotificationUseCase.execute(A_SESSION_ID, any()) }
every { fakeCheckIfCanToggleNotificationsViaPusherUseCase.execute(fakeSession) } returns false
coJustRun { fakeToggleNotificationUseCase.execute(A_SESSION_ID, any()) }
coJustRun { fakeUnregisterUnifiedPushUseCase.execute(any()) }
// When
@ -75,7 +77,7 @@ class DisableNotificationsForCurrentSessionUseCaseTest {
// Then
coVerify {
fakeTogglePushNotificationUseCase.execute(A_SESSION_ID, false)
fakeToggleNotificationUseCase.execute(A_SESSION_ID, false)
fakeUnregisterUnifiedPushUseCase.execute(fakePushersManager.instance)
}
}

View file

@ -18,7 +18,7 @@ package im.vector.app.features.settings.notifications
import im.vector.app.core.pushers.EnsureFcmTokenIsRetrievedUseCase
import im.vector.app.core.pushers.RegisterUnifiedPushUseCase
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
import im.vector.app.features.settings.devices.v2.notification.ToggleNotificationUseCase
import im.vector.app.test.fakes.FakeActiveSessionHolder
import im.vector.app.test.fakes.FakePushersManager
import io.mockk.coJustRun
@ -36,14 +36,14 @@ class EnableNotificationsForCurrentSessionUseCaseTest {
private val fakeActiveSessionHolder = FakeActiveSessionHolder()
private val fakePushersManager = FakePushersManager()
private val fakeTogglePushNotificationUseCase = mockk<TogglePushNotificationUseCase>()
private val fakeToggleNotificationUseCase = mockk<ToggleNotificationUseCase>()
private val fakeRegisterUnifiedPushUseCase = mockk<RegisterUnifiedPushUseCase>()
private val fakeEnsureFcmTokenIsRetrievedUseCase = mockk<EnsureFcmTokenIsRetrievedUseCase>()
private val enableNotificationsForCurrentSessionUseCase = EnableNotificationsForCurrentSessionUseCase(
activeSessionHolder = fakeActiveSessionHolder.instance,
pushersManager = fakePushersManager.instance,
togglePushNotificationUseCase = fakeTogglePushNotificationUseCase,
toggleNotificationUseCase = fakeToggleNotificationUseCase,
registerUnifiedPushUseCase = fakeRegisterUnifiedPushUseCase,
ensureFcmTokenIsRetrievedUseCase = fakeEnsureFcmTokenIsRetrievedUseCase,
)
@ -57,7 +57,7 @@ class EnableNotificationsForCurrentSessionUseCaseTest {
fakePushersManager.givenGetPusherForCurrentSessionReturns(null)
every { fakeRegisterUnifiedPushUseCase.execute(any()) } returns RegisterUnifiedPushUseCase.RegisterUnifiedPushResult.Success
justRun { fakeEnsureFcmTokenIsRetrievedUseCase.execute(any(), any()) }
coJustRun { fakeTogglePushNotificationUseCase.execute(A_SESSION_ID, any()) }
coJustRun { fakeToggleNotificationUseCase.execute(A_SESSION_ID, any()) }
// When
val result = enableNotificationsForCurrentSessionUseCase.execute(aDistributor)

View file

@ -16,14 +16,14 @@
package im.vector.app.test.fakes
import im.vector.app.features.settings.devices.v2.notification.TogglePushNotificationUseCase
import im.vector.app.features.settings.devices.v2.notification.ToggleNotificationUseCase
import io.mockk.coJustRun
import io.mockk.coVerify
import io.mockk.mockk
class FakeTogglePushNotificationUseCase {
val instance = mockk<TogglePushNotificationUseCase> {
val instance = mockk<ToggleNotificationUseCase> {
coJustRun { execute(any(), any()) }
}