Renaming a use case

This commit is contained in:
Maxime NATUREL 2022-12-05 17:40:38 +01:00
parent c12af5a800
commit 7b830d1c1a
4 changed files with 16 additions and 16 deletions

View File

@ -22,11 +22,11 @@ import org.matrix.android.sdk.api.session.Session
import javax.inject.Inject
class CanToggleNotificationsViaAccountDataUseCase @Inject constructor(
private val getNotificationSettingsAccountDataAsFlowUseCase: GetNotificationSettingsAccountDataAsFlowUseCase,
private val getNotificationSettingsAccountDataUpdatesUseCase: GetNotificationSettingsAccountDataUpdatesUseCase,
) {
fun execute(session: Session, deviceId: String): Flow<Boolean> {
return getNotificationSettingsAccountDataAsFlowUseCase.execute(session, deviceId)
return getNotificationSettingsAccountDataUpdatesUseCase.execute(session, deviceId)
.map { it?.isSilenced != null }
}
}

View File

@ -25,7 +25,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 GetNotificationSettingsAccountDataAsFlowUseCase @Inject constructor() {
class GetNotificationSettingsAccountDataUpdatesUseCase @Inject constructor() {
fun execute(session: Session, deviceId: String): Flow<LocalNotificationSettingsContent?> {
return session

View File

@ -29,10 +29,10 @@ import org.matrix.android.sdk.api.account.LocalNotificationSettingsContent
class CanToggleNotificationsViaAccountDataUseCaseTest {
private val fakeGetNotificationSettingsAccountDataAsFlowUseCase = mockk<GetNotificationSettingsAccountDataAsFlowUseCase>()
private val fakeGetNotificationSettingsAccountDataUpdatesUseCase = mockk<GetNotificationSettingsAccountDataUpdatesUseCase>()
private val canToggleNotificationsViaAccountDataUseCase = CanToggleNotificationsViaAccountDataUseCase(
getNotificationSettingsAccountDataAsFlowUseCase = fakeGetNotificationSettingsAccountDataAsFlowUseCase,
getNotificationSettingsAccountDataUpdatesUseCase = fakeGetNotificationSettingsAccountDataUpdatesUseCase,
)
@Test
@ -43,14 +43,14 @@ class CanToggleNotificationsViaAccountDataUseCaseTest {
val localNotificationSettingsContent = LocalNotificationSettingsContent(
isSilenced = true,
)
every { fakeGetNotificationSettingsAccountDataAsFlowUseCase.execute(any(), any()) } returns flowOf(localNotificationSettingsContent)
every { fakeGetNotificationSettingsAccountDataUpdatesUseCase.execute(any(), any()) } returns flowOf(localNotificationSettingsContent)
// When
val result = canToggleNotificationsViaAccountDataUseCase.execute(aSession, aDeviceId).firstOrNull()
// Then
result shouldBe true
verify { fakeGetNotificationSettingsAccountDataAsFlowUseCase.execute(aSession, aDeviceId) }
verify { fakeGetNotificationSettingsAccountDataUpdatesUseCase.execute(aSession, aDeviceId) }
}
@Test
@ -61,14 +61,14 @@ class CanToggleNotificationsViaAccountDataUseCaseTest {
val localNotificationSettingsContent = LocalNotificationSettingsContent(
isSilenced = null,
)
every { fakeGetNotificationSettingsAccountDataAsFlowUseCase.execute(any(), any()) } returns flowOf(localNotificationSettingsContent)
every { fakeGetNotificationSettingsAccountDataUpdatesUseCase.execute(any(), any()) } returns flowOf(localNotificationSettingsContent)
// When
val result = canToggleNotificationsViaAccountDataUseCase.execute(aSession, aDeviceId).firstOrNull()
// Then
result shouldBe false
verify { fakeGetNotificationSettingsAccountDataAsFlowUseCase.execute(aSession, aDeviceId) }
verify { fakeGetNotificationSettingsAccountDataUpdatesUseCase.execute(aSession, aDeviceId) }
}
@Test
@ -76,13 +76,13 @@ class CanToggleNotificationsViaAccountDataUseCaseTest {
// Given
val aSession = FakeSession()
val aDeviceId = "aDeviceId"
every { fakeGetNotificationSettingsAccountDataAsFlowUseCase.execute(any(), any()) } returns flowOf(null)
every { fakeGetNotificationSettingsAccountDataUpdatesUseCase.execute(any(), any()) } returns flowOf(null)
// When
val result = canToggleNotificationsViaAccountDataUseCase.execute(aSession, aDeviceId).firstOrNull()
// Then
result shouldBe false
verify { fakeGetNotificationSettingsAccountDataAsFlowUseCase.execute(aSession, aDeviceId) }
verify { fakeGetNotificationSettingsAccountDataUpdatesUseCase.execute(aSession, aDeviceId) }
}
}

View File

@ -30,10 +30,10 @@ 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 GetNotificationSettingsAccountDataAsFlowUseCaseTest {
class GetNotificationSettingsAccountDataUpdatesUseCaseTest {
private val fakeFlowLiveDataConversions = FakeFlowLiveDataConversions()
private val getNotificationSettingsAccountDataAsFlowUseCase = GetNotificationSettingsAccountDataAsFlowUseCase()
private val getNotificationSettingsAccountDataUpdatesUseCase = GetNotificationSettingsAccountDataUpdatesUseCase()
@Before
fun setUp() {
@ -60,7 +60,7 @@ class GetNotificationSettingsAccountDataAsFlowUseCaseTest {
.givenAsFlow()
// When
val result = getNotificationSettingsAccountDataAsFlowUseCase.execute(aSession, aDeviceId).firstOrNull()
val result = getNotificationSettingsAccountDataUpdatesUseCase.execute(aSession, aDeviceId).firstOrNull()
// Then
result shouldBeEqualTo expectedContent
@ -80,7 +80,7 @@ class GetNotificationSettingsAccountDataAsFlowUseCaseTest {
.givenAsFlow()
// When
val result = getNotificationSettingsAccountDataAsFlowUseCase.execute(aSession, aDeviceId).firstOrNull()
val result = getNotificationSettingsAccountDataUpdatesUseCase.execute(aSession, aDeviceId).firstOrNull()
// Then
result shouldBeEqualTo null
@ -101,7 +101,7 @@ class GetNotificationSettingsAccountDataAsFlowUseCaseTest {
.givenAsFlow()
// When
val result = getNotificationSettingsAccountDataAsFlowUseCase.execute(aSession, aDeviceId).firstOrNull()
val result = getNotificationSettingsAccountDataUpdatesUseCase.execute(aSession, aDeviceId).firstOrNull()
// Then
result shouldBeEqualTo expectedContent