Skip to content

Commit

Permalink
🐛 Fix EmailVerificationViewModel error
Browse files Browse the repository at this point in the history
dquote>
dquote>
dquote> Co-authored-by: YeonJeong Kim <[email protected]>
dquote> Co-authored-by: Minyeong Lee <[email protected]>
  • Loading branch information
89645321 committed Dec 9, 2023
1 parent df96f30 commit 23f3ec7
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.example.speechbuddy.ui.models.EmailVerificationError
import com.example.speechbuddy.ui.models.EmailVerificationErrorType
import com.example.speechbuddy.ui.models.EmailVerificationUiState
import com.example.speechbuddy.utils.ResponseCode
import com.example.speechbuddy.utils.ResponseHandler
import com.example.speechbuddy.utils.Status
import com.example.speechbuddy.utils.isValidCode
import com.example.speechbuddy.utils.isValidEmail
Expand All @@ -29,6 +30,7 @@ import javax.inject.Inject
@HiltViewModel
class EmailVerificationViewModel @Inject internal constructor(
private val repository: AuthRepository,
private val responseHandler: ResponseHandler,
private val sessionManager: SessionManager
) : ViewModel() {

Expand Down Expand Up @@ -112,7 +114,7 @@ class EmailVerificationViewModel @Inject internal constructor(
} else {
val navigationSendCode = NavigationSendCode()
navigationSendCode.setSource(source.value!!)
navigationSendCode.sendCode(this, repository)
navigationSendCode.sendCode(this, repository, responseHandler)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.speechbuddy.viewmodel.strategy

import com.example.speechbuddy.repository.AuthRepository
import com.example.speechbuddy.utils.ResponseHandler
import com.example.speechbuddy.viewmodel.EmailVerificationViewModel

class NavigationSendCode {
Expand All @@ -16,7 +17,7 @@ class NavigationSendCode {
}
}

fun sendCode(viewModel: EmailVerificationViewModel, repository: AuthRepository) {
sendCodeStrategy.sendCode(viewModel, repository)
fun sendCode(viewModel: EmailVerificationViewModel, repository: AuthRepository, responseHandler: ResponseHandler) {
sendCodeStrategy.sendCode(viewModel, repository, responseHandler)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.example.speechbuddy.viewmodel.EmailVerificationViewModel
import kotlinx.coroutines.launch

class SendCodeForResetPasswordStrategy: SendCodeStrategy {
override fun sendCode(viewModel: EmailVerificationViewModel, repository: AuthRepository) {
override fun sendCode(viewModel: EmailVerificationViewModel, repository: AuthRepository, responseHandler: ResponseHandler) {
viewModel.changeLoadingState()
viewModel.viewModelScope.launch {
repository.sendCodeForResetPassword(
Expand All @@ -25,7 +25,6 @@ class SendCodeForResetPasswordStrategy: SendCodeStrategy {
}

ResponseCode.BAD_REQUEST.value -> {
val responseHandler = ResponseHandler()
val errorMessageId =
when (responseHandler.parseErrorResponse(result.errorBody()!!).key) {
"email" -> R.string.wrong_email
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.example.speechbuddy.viewmodel.EmailVerificationViewModel
import kotlinx.coroutines.launch

class SendCodeForSignupStrategy: SendCodeStrategy {
override fun sendCode(viewModel: EmailVerificationViewModel, repository: AuthRepository) {
override fun sendCode(viewModel: EmailVerificationViewModel, repository: AuthRepository, responseHandler: ResponseHandler) {
viewModel.changeLoadingState()
viewModel.viewModelScope.launch {
repository.sendCodeForSignup(
Expand All @@ -25,7 +25,6 @@ class SendCodeForSignupStrategy: SendCodeStrategy {
}

ResponseCode.BAD_REQUEST.value -> {
val responseHandler = ResponseHandler()
val errorMessageId =
when (responseHandler.parseErrorResponse(result.errorBody()!!).key) {
"email" -> R.string.wrong_email
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package com.example.speechbuddy.viewmodel.strategy

import com.example.speechbuddy.repository.AuthRepository
import com.example.speechbuddy.utils.ResponseHandler
import com.example.speechbuddy.viewmodel.EmailVerificationViewModel

interface SendCodeStrategy {
fun sendCode(viewModel: EmailVerificationViewModel, repository: AuthRepository)
fun sendCode(viewModel: EmailVerificationViewModel, repository: AuthRepository, responseHandler: ResponseHandler)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.newSingleThreadContext
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.test.resetMain
import kotlinx.coroutines.test.setMain
import okhttp3.ResponseBody.Companion.toResponseBody
Expand Down Expand Up @@ -60,7 +61,7 @@ class EmailVerificationViewModelTest {
fun setup() {
Dispatchers.setMain(mainThreadSurrogate)
viewModel = EmailVerificationViewModel(
authRepository, sessionManager
authRepository, responseHandler, sessionManager
)
}

Expand Down

0 comments on commit 23f3ec7

Please sign in to comment.