-
Notifications
You must be signed in to change notification settings - Fork 2
✨ Feat: 닉네임 중복 확인 기능 구현 #148
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
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
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
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
49 changes: 49 additions & 0 deletions
49
src/test/java/com/dodo/backend/user/controller/UserControllerTest.java
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,49 @@ | ||
| package com.dodo.backend.user.controller; | ||
|
|
||
| import com.dodo.backend.user.dto.response.UserResponse.NicknameCheckResponse; | ||
| import com.dodo.backend.user.service.UserService; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.Mock; | ||
| import org.mockito.junit.jupiter.MockitoExtension; | ||
| import org.springframework.http.ResponseEntity; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
| import static org.mockito.BDDMockito.given; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| /** | ||
| * {@link UserController}의 HTTP 요청 처리 로직을 검증하는 테스트 클래스입니다. | ||
| */ | ||
| @ExtendWith(MockitoExtension.class) | ||
| class UserControllerTest { | ||
|
|
||
| @Mock | ||
| private UserService userService; | ||
|
|
||
| /** | ||
| * 닉네임 중복 확인 요청 시 200 상태 코드와 중복 확인 결과를 반환하는지 검증합니다. | ||
| */ | ||
| @Test | ||
| @DisplayName("닉네임 중복 확인 성공") | ||
| void checkNicknameDuplicationSuccessTest() { | ||
| //given | ||
| UserController userController = new UserController(userService); | ||
| String nickname = "도도"; | ||
| NicknameCheckResponse serviceResponse = NicknameCheckResponse.toDto(nickname, false); | ||
|
|
||
| given(userService.checkNicknameDuplication(nickname)).willReturn(serviceResponse); | ||
|
|
||
| //when | ||
| ResponseEntity<NicknameCheckResponse> response = userController.checkNicknameDuplication(nickname); | ||
|
|
||
| //then | ||
| assertThat(response.getStatusCode().value()).isEqualTo(200); | ||
| assertThat(response.getBody()).isNotNull(); | ||
| assertThat(response.getBody().getNickname()).isEqualTo(nickname); | ||
| assertThat(response.getBody().getDuplicated()).isFalse(); | ||
|
|
||
| verify(userService).checkNicknameDuplication(nickname); | ||
| } | ||
| } |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔍 닉네임 유효성 검증 추가 필요
현재
checkNicknameDuplication메서드에서는 입력받은nickname에 대한 유효성 검증(Null 및 공백 여부 등)이 누락되어 있습니다.UserController의 OpenAPI 문서(@ApiResponse)에는 **"400 닉네임 형식이 올바르지 않습니다."**라는 응답이 정의되어 있지만, 실제 코드에서는 검증 로직이 없어 빈 문자열("")이나 공백만으로 구성된 닉네임도 그대로 DB를 조회하게 됩니다.또한, 회원가입 시 적용되는 닉네임 형식 규칙(예: 길이 제한, 허용 문자 등)과 동일한 검증을 이 API에서도 수행해야 합니다. 그렇지 않으면 사용자가 중복 확인 시에는 "사용 가능"으로 안내받았으나, 실제 회원가입 단계에서 형식 오류로 가입이 실패하는 비일관적인 사용자 경험(UX)이 발생할 수 있습니다.
개선 사항:
nickname이null이거나 공백(isBlank())인 경우UserException(INVALID_REQUEST)을 발생시켜 안전하게 예외 처리합니다.