Fixing wrong notification status when no registered pusher for the session

This commit is contained in:
Maxime NATUREL 2022-12-02 10:03:37 +01:00
parent b78de15228
commit e09b9a2ce0
2 changed files with 21 additions and 1 deletions

View File

@ -51,7 +51,13 @@ class GetNotificationsStatusUseCase @Inject constructor(
.livePushers() .livePushers()
.map { it.filter { pusher -> pusher.deviceId == deviceId } } .map { it.filter { pusher -> pusher.deviceId == deviceId } }
.map { it.takeIf { it.isNotEmpty() }?.any { pusher -> pusher.enabled } } .map { it.takeIf { it.isNotEmpty() }?.any { pusher -> pusher.enabled } }
.map { if (it == true) NotificationsStatus.ENABLED else NotificationsStatus.DISABLED } .map {
when (it) {
true -> NotificationsStatus.ENABLED
false -> NotificationsStatus.DISABLED
else -> NotificationsStatus.NOT_SUPPORTED
}
}
.distinctUntilChanged() .distinctUntilChanged()
} else { } else {
flowOf(NotificationsStatus.NOT_SUPPORTED) flowOf(NotificationsStatus.NOT_SUPPORTED)

View File

@ -105,6 +105,20 @@ class GetNotificationsStatusUseCaseTest {
result.firstOrNull() shouldBeEqualTo NotificationsStatus.ENABLED result.firstOrNull() shouldBeEqualTo NotificationsStatus.ENABLED
} }
@Test
fun `given toggle via pusher is supported and no registered pusher when execute then resulting flow contains NOT_SUPPORTED value`() = runTest {
// Given
fakeSession.pushersService().givenPushersLive(emptyList())
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)
// Then
result.firstOrNull() shouldBeEqualTo NotificationsStatus.NOT_SUPPORTED
}
@Test @Test
fun `given current session and toggle via account data is supported when execute then resulting flow contains status based on settings value`() = runTest { fun `given current session and toggle via account data is supported when execute then resulting flow contains status based on settings value`() = runTest {
// Given // Given