diff --git a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/viewmodel/PushNotificationViewModel.kt b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/viewmodel/PushNotificationViewModel.kt index e866a268e..68419703f 100644 --- a/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/viewmodel/PushNotificationViewModel.kt +++ b/feature/setting/presentation/src/main/kotlin/com/afternote/feature/setting/presentation/viewmodel/PushNotificationViewModel.kt @@ -207,7 +207,7 @@ internal class PushNotificationViewModel private fun loadMarketingConsents() { viewModelScope.launch { Log.d(TAG, "loadMarketingConsents: start") - runCatching { userRepository.getMyMarketingConsents() } + runCatchingCancellable { userRepository.getMyMarketingConsents() } .onSuccess { consent -> Log.d(TAG, "loadMarketingConsents: success=$consent") dispatch(PushNotificationReducerEvent.MarketingLoaded(consent)) diff --git a/feature/setting/presentation/src/test/kotlin/com/afternote/feature/setting/presentation/viewmodel/MarketingConsentFailureTest.kt b/feature/setting/presentation/src/test/kotlin/com/afternote/feature/setting/presentation/viewmodel/MarketingConsentFailureTest.kt index 7ce5e4270..6323a5602 100644 --- a/feature/setting/presentation/src/test/kotlin/com/afternote/feature/setting/presentation/viewmodel/MarketingConsentFailureTest.kt +++ b/feature/setting/presentation/src/test/kotlin/com/afternote/feature/setting/presentation/viewmodel/MarketingConsentFailureTest.kt @@ -1,5 +1,7 @@ package com.afternote.feature.setting.presentation.viewmodel +import android.util.Log +import androidx.lifecycle.ViewModelStore import androidx.test.core.app.ApplicationProvider import com.afternote.core.common.reporting.ErrorReporter import com.afternote.core.model.user.UserMarketingConsent @@ -9,6 +11,7 @@ import com.afternote.feature.setting.presentation.viewmodel.PushNotificationInte import kotlinx.coroutines.CancellationException import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.awaitCancellation import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.launch import kotlinx.coroutines.test.StandardTestDispatcher @@ -25,6 +28,7 @@ import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config +import org.robolectric.shadows.ShadowLog @OptIn(ExperimentalCoroutinesApi::class) @RunWith(RobolectricTestRunner::class) @@ -42,6 +46,33 @@ class MarketingConsentFailureTest { Dispatchers.resetMain() } + @Test + fun `마케팅 동의 조회 중 화면 종료는 실패 로그나 진단을 남기지 않는다`() = + runTest(dispatcher) { + var loadStarted = false + val reporter = RecordingReporter() + val repository = + repository().apply { + onGetMyMarketingConsents = { + loadStarted = true + awaitCancellation() + } + } + val viewModel = viewModel(repository, reporter) + val store = ViewModelStore().apply { put("notifications", viewModel) } + runCurrent() + assertTrue(loadStarted) + val stateBeforeCancellation = viewModel.uiState.value + ShadowLog.clear() + + store.clear() + runCurrent() + + assertEquals(stateBeforeCancellation, viewModel.uiState.value) + assertTrue(reporter.stages.isEmpty()) + assertTrue(ShadowLog.getLogsForTag("PushNotificationVM").none { it.type >= Log.ERROR }) + } + @Test fun `각 동의 철회 실패는 값을 복원하고 안내와 진단을 남긴다`() = runTest(dispatcher) {