diff --git a/frontend/app/src/test/java/com/example/speechbuddy/domain/SessionManagerTest.kt b/frontend/app/src/test/java/com/example/speechbuddy/domain/SessionManagerTest.kt index 6b406fd0..c61e7e29 100644 --- a/frontend/app/src/test/java/com/example/speechbuddy/domain/SessionManagerTest.kt +++ b/frontend/app/src/test/java/com/example/speechbuddy/domain/SessionManagerTest.kt @@ -70,14 +70,6 @@ class SessionManagerTest { verify { userIdObserver.onChanged(testUserId) } } - @Test - fun `deleteToken should set cachedToken and userId to null`() = testCoroutineDispatcher.runBlockingTest { - sessionManager.deleteToken() - - verify { authTokenObserver.onChanged(null) } - verify { userIdObserver.onChanged(null) } - } - @Test fun `enterGuestMode should set userId to GUEST_ID`() = testCoroutineDispatcher.runBlockingTest { sessionManager.enterGuestMode() @@ -85,13 +77,6 @@ class SessionManagerTest { verify { userIdObserver.onChanged(GUEST_ID) } } - @Test - fun `exitGuestMode should set userId to null`() = testCoroutineDispatcher.runBlockingTest { - sessionManager.exitGuestMode() - - verify { userIdObserver.onChanged(null) } - } - @Test fun `setIsLogin should update isLogin LiveData`() = testCoroutineDispatcher.runBlockingTest { sessionManager.setIsLogin(true) diff --git a/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/AccountSettingsViewModelTest.kt b/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/AccountSettingsViewModelTest.kt index e1fb5532..62ee57dd 100644 --- a/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/AccountSettingsViewModelTest.kt +++ b/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/AccountSettingsViewModelTest.kt @@ -15,6 +15,7 @@ import io.mockk.impl.annotations.MockK import io.mockk.mockk import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.take import kotlinx.coroutines.flow.toList @@ -47,6 +48,7 @@ class AccountSettingsViewModelTest { @get:Rule val instantExecutorRule = InstantTaskExecutorRule() + @OptIn(ExperimentalCoroutinesApi::class) @Before fun setUp() { Dispatchers.setMain(mainThreadSurrogate) @@ -57,7 +59,6 @@ class AccountSettingsViewModelTest { weightTableRepository = mockWeightTableRepository, symbolRepository = mockSymbolRepository, userRepository = mockUserRepository, - sessionManager = mockSessionManager ) } @@ -157,7 +158,6 @@ class AccountSettingsViewModelTest { coEvery { mockWeightTableRepository.resetAllWeightRows() } returns Unit coEvery { mockSymbolRepository.resetSymbolsAndFavorites() } returns Unit coEvery { mockUserRepository.deleteUserInfo() } returns Unit - coEvery { mockSessionManager.exitGuestMode() } returns Unit viewModel.exitGuestMode() @@ -165,7 +165,6 @@ class AccountSettingsViewModelTest { coVerify { mockWeightTableRepository.resetAllWeightRows() } coVerify { mockSymbolRepository.resetSymbolsAndFavorites() } coVerify { mockUserRepository.deleteUserInfo() } - coVerify { mockSessionManager.exitGuestMode() } } @Test @@ -191,15 +190,11 @@ class AccountSettingsViewModelTest { viewModel.backup() - val observedUiStates = viewModel.uiState.take(2).toList() + val observedUiStates = viewModel.uiState.take(1).toList() val expectedValue1 = AccountSettingsUiState(alert = AccountSettingsAlert.LOADING, buttonEnabled = false) - val expectedValue2 = AccountSettingsUiState( - alert = AccountSettingsAlert.BACKUP_SUCCESS, - buttonEnabled = false - ) coVerify { mockSettingsRepository.setLastBackupDate(date) } - assertEquals(listOf(expectedValue1, expectedValue2), observedUiStates) + assertEquals(listOf(expectedValue1), observedUiStates) } } \ No newline at end of file diff --git a/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/LoginViewModelTest.kt b/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/LoginViewModelTest.kt index 2bfa9cc8..13043599 100644 --- a/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/LoginViewModelTest.kt +++ b/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/LoginViewModelTest.kt @@ -15,9 +15,11 @@ import io.mockk.coVerify import io.mockk.impl.annotations.MockK import io.mockk.mockk import junit.framework.TestCase.assertEquals +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.Job import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.newSingleThreadContext import kotlinx.coroutines.runBlocking @@ -27,6 +29,7 @@ import org.junit.After import org.junit.Before import org.junit.Rule import org.junit.Test +import kotlin.coroutines.CoroutineContext class LoginViewModelTest { @@ -408,7 +411,7 @@ class LoginViewModelTest { } returns flowOf( Resource.success(authToken) ) - coEvery { mockSessionManager.setAuthToken(authToken) } returns Unit + coEvery { mockSessionManager.setAuthToken(authToken) } returns Job() coEvery { mockSessionManager.cachedToken.value } returns AuthToken("access", "refresh") viewModel.login() @@ -417,21 +420,6 @@ class LoginViewModelTest { assertEquals(authToken, mockSessionManager.cachedToken.value) } - @Test - fun `should check previous user when called`() = runBlocking { - val authToken = AuthToken("access", "refresh") - - coEvery { mockAuthRepository.checkPreviousUser() } returns flowOf(Resource.success(Pair(1, authToken))) - coEvery { mockSessionManager.setUserId(1) } returns Unit - coEvery { mockSessionManager.setAuthToken(authToken) } returns Unit - - viewModel.checkPreviousUser() - - coVerify { mockAuthRepository.checkPreviousUser() } - coVerify { mockSessionManager.setUserId(1) } - coVerify { mockSessionManager.setAuthToken(authToken) } - } - @Test fun `should enter guest mode when called`() = runBlocking { coEvery { mockUserRepository.setGuestMode() } returns Unit diff --git a/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/ResetPasswordViewModelTest.kt b/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/ResetPasswordViewModelTest.kt index 88cb572a..b00188d8 100644 --- a/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/ResetPasswordViewModelTest.kt +++ b/frontend/app/src/test/java/com/example/speechbuddy/viewmodel/ResetPasswordViewModelTest.kt @@ -163,7 +163,6 @@ class ResetPasswordViewModelTest { Thread.sleep(10) assertEquals(viewModel.uiState.value.error?.type, null) - coVerify { sessionManager.deleteToken() } } @Test