-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: 카카오 로그인 유저 이메일 수정 불가 + 테스트 코드 #113
Merged
Merged
Changes from all commits
Commits
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 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
2 changes: 2 additions & 0 deletions
2
src/main/java/com/HHive/hhive/domain/user/dto/UpdateUserProfileRequestDTO.java
This file contains 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 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 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 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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/HHive/hhive/global/exception/user/KakaoUserEmailModificationException.java
This file contains 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,11 @@ | ||
package com.HHive.hhive.global.exception.user; | ||
|
||
import com.HHive.hhive.global.exception.common.CustomException; | ||
import com.HHive.hhive.global.exception.common.ErrorCode; | ||
|
||
public class KakaoUserEmailModificationException extends CustomException { | ||
|
||
public KakaoUserEmailModificationException() { | ||
super(ErrorCode.KAKAO_USER_EMAIL_MODIFICATION_EXCEPTION); | ||
} | ||
} |
This file contains 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 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 |
---|---|---|
|
@@ -32,8 +32,10 @@ void kakaoIdUpdate() { | |
@DisplayName("프로필 업데이트") | ||
void updateProfile() { | ||
// given | ||
User user = new User("testUser", "testPassword", "[email protected]", "testDescription"); | ||
UpdateUserProfileRequestDTO requestDTO = new UpdateUserProfileRequestDTO(); | ||
User user = new User( | ||
"testUser", "testPassword", "[email protected]", "testDescription"); | ||
UpdateUserProfileRequestDTO requestDTO = new UpdateUserProfileRequestDTO( | ||
"[email protected]", "updateDescription"); | ||
|
||
// when | ||
user.updateProfile(requestDTO); | ||
|
@@ -47,7 +49,8 @@ void updateProfile() { | |
@DisplayName("계정 삭제 업데이트") | ||
void updateDeletedAt() { | ||
// given | ||
User user = new User("testUser", "testPassword", "[email protected]", "testDescription"); | ||
User user = new User( | ||
"testUser", "testPassword", "[email protected]", "testDescription"); | ||
assertFalse(user.is_deleted()); | ||
|
||
// when | ||
|
@@ -67,7 +70,8 @@ class SetUserInfoTest { | |
@DisplayName("비밀번호 설정") | ||
void setPassword() { | ||
// given | ||
User user = new User("testUser", "testPassword", "[email protected]", "testDescription"); | ||
User user = new User( | ||
"testUser", "testPassword", "[email protected]", "testDescription"); | ||
String newPassword = "newPassword"; | ||
|
||
// when | ||
|
@@ -81,7 +85,8 @@ void setPassword() { | |
@DisplayName("major 카테고리 설정") | ||
void setMajorCategory() { | ||
// given | ||
User user = new User("testUser", "testPassword", "[email protected]", "testDescription"); | ||
User user = new User( | ||
"testUser", "testPassword", "[email protected]", "testDescription"); | ||
MajorCategory majorCategory = MajorCategory.GAME; | ||
|
||
// when | ||
|
@@ -95,7 +100,8 @@ void setMajorCategory() { | |
@DisplayName("sub 카테고리 설정") | ||
void setSubCategory() { | ||
// given | ||
User user = new User("testUser", "testPassword", "[email protected]", "testDescription"); | ||
User user = new User( | ||
"testUser", "testPassword", "[email protected]", "testDescription"); | ||
SubCategory subCategory = SubCategory.LOL; | ||
|
||
// when | ||
|
61 changes: 61 additions & 0 deletions
61
src/test/java/com/HHive/hhive/domain/user/service/UserServiceTest.java
This file contains 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,61 @@ | ||
package com.HHive.hhive.domain.user.service; | ||
|
||
import com.HHive.hhive.domain.user.dto.UpdateUserProfileRequestDTO; | ||
import com.HHive.hhive.domain.user.entity.User; | ||
import com.HHive.hhive.domain.user.repository.UserRepository; | ||
import com.HHive.hhive.global.exception.user.KakaoUserEmailModificationException; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.when; | ||
|
||
@SpringBootTest | ||
class UserServiceTest { | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@MockBean | ||
private UserRepository userRepository; | ||
|
||
@Nested | ||
@DisplayName("프로필 수정") | ||
class updateProfileTest { | ||
|
||
@Test | ||
@DisplayName("카카오 로그인 유저의 이메일 수정") | ||
void updateProfileByKakaoUserFailsWhenEmailIsChanged() { | ||
|
||
// given | ||
// 카카오 로그인한 사용자를 생성 | ||
User kakaoUser = new User("username", "password", "[email protected]", "description"); | ||
kakaoUser.kakaoIdUpdate(12345L); // 카카오 로그인한 사용자라고 가정하기 위해 카카오 ID를 설정 | ||
kakaoUser.setId(1L); // 사용자 ID 설정 | ||
|
||
// 이메일을 변경하는 요청을 생성 | ||
UpdateUserProfileRequestDTO requestDTO = new UpdateUserProfileRequestDTO("[email protected]", "new description"); | ||
|
||
// userRepository에서 동일한 Id와 카카오 Id를 가진 사용자를 반환하도록 설정 | ||
when(userRepository.findById(1L)).thenReturn(Optional.of(kakaoUser)); // findById() 메서드를 가장 | ||
when(userRepository.findByKakaoId(kakaoUser.getKakaoId())).thenReturn(Optional.of(kakaoUser)); // findByKakaoId() 메서드를 가장 | ||
|
||
// 로그인한 사용자를 생성 | ||
User loginUser = new User("username", "password", "[email protected]", "description"); | ||
loginUser.kakaoIdUpdate(12345L); // 카카오 로그인한 사용자라고 가정하기 위해 카카오 ID를 설정 | ||
loginUser.setId(1L); // 사용자 ID 설정 | ||
|
||
// then | ||
// 이메일 수정을 시도하면 KakaoUserEmailModificationException 예외가 발생해야 함 | ||
assertThrows(KakaoUserEmailModificationException.class, () -> { | ||
userService.updateProfile(1L, requestDTO, loginUser); // 가장된 ID 사용 | ||
}); | ||
} | ||
} | ||
} |
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.
세터를 쓴 이유를 잘 설명할 수 있어야할 것 같네요.
빌더로는 PK 세팅이 안되었나요? 이런 질문이 들어올 수 있을 것 같아요