Repository navigation
fix(setting): 수신인 입력 검증 및 오류 처리 개선 (#577) #771
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7612fab
fix(setting): 수신인 입력 검증 및 오류 처리 개선 (#577)
koongmai f853790
fix(data): mapReceiverRequestFailure를 private로 좁히고 공개 계약으로 검증한다
koongmai 9aeb1e4
fix(setting): 수신자 서버 오류 원문 노출과 전화번호 필수성 불일치를 해소한다
koongmai c4d688b
fix(setting): 프로덕션 호출부가 사라진 isValidReceiverPhone을 제거한다
koongmai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
183 changes: 183 additions & 0 deletions
183
core/data/src/test/java/com/afternote/core/data/repoimpl/ReceiverRequestFailureTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,183 @@ | ||
| package com.afternote.core.data.repoimpl | ||
|
|
||
| import com.afternote.core.common.reporting.ErrorReporter | ||
| import com.afternote.core.domain.error.ReceiverRequestRejectedException | ||
| import com.afternote.core.domain.testing.FakeAuthRepository | ||
| import com.afternote.core.network.dto.DeletePushTokenRequestDto | ||
| import com.afternote.core.network.dto.PushTokenDto | ||
| import com.afternote.core.network.dto.ReceiverDetailDto | ||
| import com.afternote.core.network.dto.ReceiverListDto | ||
| import com.afternote.core.network.dto.RegisterPushTokenRequestDto | ||
| import com.afternote.core.network.dto.SocialAccountLinkRequestDto | ||
| import com.afternote.core.network.dto.UserConnectedAccountDto | ||
| import com.afternote.core.network.dto.UserCreateReceiverDto | ||
| import com.afternote.core.network.dto.UserCreateReceiverRequestDto | ||
| import com.afternote.core.network.dto.UserDto | ||
| import com.afternote.core.network.dto.UserPatchReceiverDto | ||
| import com.afternote.core.network.dto.UserPatchReceiverRequestDto | ||
| import com.afternote.core.network.dto.UserPushSettingDto | ||
| import com.afternote.core.network.dto.UserUpdateProfileRequestDto | ||
| import com.afternote.core.network.dto.UserUpdatePushSettingRequestDto | ||
| import com.afternote.core.network.dto.UserUpdateReceiverMessageRequestDto | ||
| import com.afternote.core.network.dto.delivery.ReceiverDeliveryConditionDto | ||
| import com.afternote.core.network.dto.delivery.ReceiverDeliveryConditionUpdateRequestDto | ||
| import com.afternote.core.network.model.ApiException | ||
| import com.afternote.core.network.model.BaseResponse | ||
| import com.afternote.core.network.service.UserApiService | ||
| import kotlinx.coroutines.runBlocking | ||
| import org.junit.Assert.assertEquals | ||
| import org.junit.Assert.assertSame | ||
| import org.junit.Assert.assertTrue | ||
| import org.junit.Test | ||
|
|
||
| /** | ||
| * `UserRepositoryImpl` 안의 `mapReceiverRequestFailure` 는 `private` 이라 이 파일에서 직접 호출할 수 | ||
| * 없다 — 그 helper 를 공유하는 공개 계약([UserRepositoryImpl.createReceiver])을 통해 같은 회귀를 고정한다. | ||
| */ | ||
| class ReceiverRequestFailureTest { | ||
| private fun repositoryThrowingOnCreate(apiError: ApiException) = | ||
| UserRepositoryImpl( | ||
| userApiService = CreateReceiverThrowingApiService(onCreateReceiver = { throw apiError }), | ||
| authRepository = FakeAuthRepository(loggedIn = false), | ||
| errorReporter = NoOpErrorReporter, | ||
| ) | ||
|
|
||
| private suspend fun createReceiver(repository: UserRepositoryImpl) = | ||
| repository.createReceiver( | ||
| name = "친구", | ||
| relation = "친구", | ||
| phone = null, | ||
| email = null, | ||
| message = null, | ||
| ) | ||
|
|
||
| @Test | ||
| fun `400 서버 메시지는 사용자 노출 도메인 오류로 바뀐다`() = | ||
| runBlocking { | ||
| val apiError = | ||
| ApiException( | ||
| status = 400, | ||
| code = 400, | ||
| serverMessage = "수신자 이메일은 필수입니다.", | ||
| fallbackMessage = "수신자 이메일은 필수입니다.", | ||
| ) | ||
| val repository = repositoryThrowingOnCreate(apiError) | ||
|
|
||
| val result = runCatching { createReceiver(repository) }.exceptionOrNull() | ||
|
|
||
| assertTrue(result is ReceiverRequestRejectedException) | ||
| val domainError = result as ReceiverRequestRejectedException | ||
| assertEquals("수신자 이메일은 필수입니다.", domainError.userMessage) | ||
| assertSame(apiError, domainError.cause) | ||
| } | ||
|
|
||
| @Test | ||
| fun `409 서버 메시지는 사용자 노출 도메인 오류로 바뀐다`() = | ||
| runBlocking { | ||
| val apiError = | ||
| ApiException( | ||
| status = 409, | ||
| code = 409, | ||
| serverMessage = "이미 등록된 수신자입니다.", | ||
| fallbackMessage = "이미 등록된 수신자입니다.", | ||
| ) | ||
| val repository = repositoryThrowingOnCreate(apiError) | ||
|
|
||
| val result = runCatching { createReceiver(repository) }.exceptionOrNull() | ||
|
|
||
| assertTrue(result is ReceiverRequestRejectedException) | ||
| } | ||
|
|
||
| @Test | ||
| fun `그 외 4xx 서버 메시지는 입력 오류로 변환하지 않는다`() = | ||
| runBlocking { | ||
| val apiError = | ||
| ApiException( | ||
| status = 404, | ||
| code = 404, | ||
| serverMessage = "존재하지 않는 엔드포인트입니다.", | ||
| fallbackMessage = "존재하지 않는 엔드포인트입니다.", | ||
| ) | ||
| val repository = repositoryThrowingOnCreate(apiError) | ||
|
|
||
| val result = runCatching { createReceiver(repository) }.exceptionOrNull() | ||
|
|
||
| assertSame(apiError, result) | ||
| } | ||
|
|
||
| @Test | ||
| fun `5xx 서버 메시지는 사용자 노출 오류로 바꾸지 않는다`() = | ||
| runBlocking { | ||
| val apiError = | ||
| ApiException( | ||
| status = 500, | ||
| code = 500, | ||
| serverMessage = "internal SQL details", | ||
| fallbackMessage = "internal SQL details", | ||
| ) | ||
| val repository = repositoryThrowingOnCreate(apiError) | ||
|
|
||
| val result = runCatching { createReceiver(repository) }.exceptionOrNull() | ||
|
|
||
| assertSame(apiError, result) | ||
| } | ||
| } | ||
|
|
||
| private object NoOpErrorReporter : ErrorReporter { | ||
| override fun writeFailure( | ||
| throwable: Throwable, | ||
| attributes: Map<String, String>, | ||
| ) = Unit | ||
| } | ||
|
|
||
| private class CreateReceiverThrowingApiService( | ||
| private val onCreateReceiver: suspend (UserCreateReceiverRequestDto) -> BaseResponse<UserCreateReceiverDto>, | ||
| ) : UserApiService { | ||
| override suspend fun getReceivers(): BaseResponse<List<ReceiverListDto>> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun createReceiver(request: UserCreateReceiverRequestDto): BaseResponse<UserCreateReceiverDto> = | ||
| onCreateReceiver(request) | ||
|
|
||
| override suspend fun getReceiverDetail(receiverId: Long): BaseResponse<ReceiverDetailDto> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun updateReceiver( | ||
| receiverId: Long, | ||
| request: UserPatchReceiverRequestDto, | ||
| ): BaseResponse<UserPatchReceiverDto> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun updateReceiverMessage( | ||
| receiverId: Long, | ||
| request: UserUpdateReceiverMessageRequestDto, | ||
| ): BaseResponse<Unit> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun getMyProfile(): BaseResponse<UserDto> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun updateMyProfile(request: UserUpdateProfileRequestDto): BaseResponse<UserDto> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun deleteAccount(): BaseResponse<Unit> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun registerPushToken(request: RegisterPushTokenRequestDto): BaseResponse<PushTokenDto> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun deletePushToken(request: DeletePushTokenRequestDto): BaseResponse<Unit> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun getMyPushSettings(): BaseResponse<UserPushSettingDto> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun updateMyPushSettings(request: UserUpdatePushSettingRequestDto): BaseResponse<UserPushSettingDto> = | ||
| TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun getConnectedAccounts(): BaseResponse<UserConnectedAccountDto> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun linkConnectedAccount( | ||
| provider: String, | ||
| request: SocialAccountLinkRequestDto, | ||
| ): BaseResponse<UserConnectedAccountDto> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun unlinkConnectedAccount(provider: String): BaseResponse<UserConnectedAccountDto> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun getReceiverDeliveryConditions(receiverId: Long): BaseResponse<ReceiverDeliveryConditionDto> = TODO("이 테스트 미사용") | ||
|
|
||
| override suspend fun updateReceiverDeliveryConditions( | ||
| receiverId: Long, | ||
| request: ReceiverDeliveryConditionUpdateRequestDto, | ||
| ): BaseResponse<ReceiverDeliveryConditionDto> = TODO("이 테스트 미사용") | ||
| } |
7 changes: 7 additions & 0 deletions
7
.../domain/src/main/java/com/afternote/core/domain/error/ReceiverRequestRejectedException.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package com.afternote.core.domain.error | ||
|
|
||
| /** 사용자가 입력을 수정해 해결할 수 있는 수신자 등록·수정 요청 오류. */ | ||
| class ReceiverRequestRejectedException( | ||
| val userMessage: String, | ||
| cause: Throwable, | ||
| ) : Exception(userMessage, cause) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.