Update use cases to enable/disable push notifications for the current session

This commit is contained in:
Maxime NATUREL 2022-11-16 16:38:46 +01:00
parent 9d684bc021
commit c56eb331db
2 changed files with 4 additions and 3 deletions

View File

@ -34,9 +34,8 @@ class DisableNotificationsForCurrentSessionUseCase @Inject constructor(
suspend fun execute() {
val session = activeSessionHolder.getSafeActiveSession() ?: return
val deviceId = session.sessionParams.deviceId ?: return
if (checkIfCanTogglePushNotificationsViaPusherUseCase.execute(session)) {
togglePushNotificationUseCase.execute(deviceId, enabled = false)
} else {
togglePushNotificationUseCase.execute(deviceId, enabled = false)
if (!checkIfCanTogglePushNotificationsViaPusherUseCase.execute(session)) {
unregisterUnifiedPushUseCase.execute(pushersManager)
}
}

View File

@ -67,6 +67,7 @@ class DisableNotificationsForCurrentSessionUseCaseTest {
val fakeSession = fakeActiveSessionHolder.fakeSession
fakeSession.givenSessionId(A_SESSION_ID)
every { fakeCheckIfCanTogglePushNotificationsViaPusherUseCase.execute(fakeSession) } returns false
coJustRun { fakeTogglePushNotificationUseCase.execute(A_SESSION_ID, any()) }
coJustRun { fakeUnregisterUnifiedPushUseCase.execute(any()) }
// When
@ -74,6 +75,7 @@ class DisableNotificationsForCurrentSessionUseCaseTest {
// Then
coVerify {
fakeTogglePushNotificationUseCase.execute(A_SESSION_ID, false)
fakeUnregisterUnifiedPushUseCase.execute(fakePushersManager.instance)
}
}