-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
이메일 찾기 API 구현
- Loading branch information
Showing
10 changed files
with
151 additions
and
17 deletions.
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
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
16 changes: 16 additions & 0 deletions
16
src/main/java/com/ajou/hertz/domain/user/dto/response/UserEmailResponse.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,16 @@ | ||
package com.ajou.hertz.domain.user.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
public class UserEmailResponse { | ||
|
||
@Schema(description = "이메일", example = "[email protected]") | ||
private String email; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/ajou/hertz/domain/user/exception/UserNotFoundByPhoneException.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,10 @@ | ||
package com.ajou.hertz.domain.user.exception; | ||
|
||
import com.ajou.hertz.common.exception.NotFoundException; | ||
import com.ajou.hertz.common.exception.constant.CustomExceptionType; | ||
|
||
public class UserNotFoundByPhoneException extends NotFoundException { | ||
public UserNotFoundByPhoneException(String phone) { | ||
super(CustomExceptionType.USER_NOT_FOUND_BY_PHONE, phone); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
import com.ajou.hertz.domain.user.entity.User; | ||
import com.ajou.hertz.domain.user.exception.UserNotFoundByEmailException; | ||
import com.ajou.hertz.domain.user.exception.UserNotFoundByIdException; | ||
import com.ajou.hertz.domain.user.exception.UserNotFoundByPhoneException; | ||
import com.ajou.hertz.domain.user.repository.UserRepository; | ||
import com.ajou.hertz.domain.user.service.UserQueryService; | ||
|
||
|
@@ -34,6 +35,25 @@ class UserQueryServiceTest { | |
@Mock | ||
private UserRepository userRepository; | ||
|
||
@Test | ||
void 카카오_유저_ID가_주어지고_주어진_카카오_유저_ID로_유저를_조회하면_조회된_유저_정보가_담긴_Optional_DTO가_반환된다() throws Exception { | ||
// given | ||
String kakaoUid = "12345"; | ||
User expectedResult = createUser(1L, "[email protected]", kakaoUid, "01012345678"); | ||
given(userRepository.findByKakaoUid(kakaoUid)).willReturn(Optional.of(expectedResult)); | ||
|
||
// when | ||
Optional<UserDto> actualResult = sut.findDtoByKakaoUid(kakaoUid); | ||
|
||
// then | ||
then(userRepository).should().findByKakaoUid(kakaoUid); | ||
verifyEveryMocksShouldHaveNoMoreInteractions(); | ||
assertThat(actualResult).isNotEmpty(); | ||
assertThat(actualResult.get()) | ||
.hasFieldOrPropertyWithValue("id", expectedResult.getId()) | ||
.hasFieldOrPropertyWithValue("kakaoUid", expectedResult.getKakaoUid()); | ||
} | ||
|
||
@Test | ||
void 유저_id가_주어지고_주어진_id로_유저를_조회하면_조회된_유저_정보가_반환된다() throws Exception { | ||
// given | ||
|
@@ -70,7 +90,7 @@ class UserQueryServiceTest { | |
void 이메일이_주어지고_주어진_이메일로_유저를_조회하면_조회된_유저_정보가_반환된다() throws Exception { | ||
// given | ||
String email = "[email protected]"; | ||
User expectedResult = createUser(1L, email, "1234"); | ||
User expectedResult = createUser(1L, email, "1234", "01012345678"); | ||
given(userRepository.findByEmail(email)).willReturn(Optional.of(expectedResult)); | ||
|
||
// when | ||
|
@@ -100,22 +120,36 @@ class UserQueryServiceTest { | |
} | ||
|
||
@Test | ||
void 카카오_유저_ID가_주어지고_주어진_카카오_유저_ID로_유저를_조회하면_조회된_Optional_유저_정보가_반환된다() throws Exception { | ||
void 전화번호가_주어지고_주어진_전화번호로_유저를_조회하면_조회된_유저_정보가_반환된다() throws Exception { | ||
// given | ||
String kakaoUid = "12345"; | ||
User expectedResult = createUser(1L, "[email protected]", kakaoUid); | ||
given(userRepository.findByKakaoUid(kakaoUid)).willReturn(Optional.of(expectedResult)); | ||
String phone = "01012345678"; | ||
User expectedResult = createUser(1L, "[email protected]", "1234", phone); | ||
given(userRepository.findByPhone(phone)).willReturn(Optional.of(expectedResult)); | ||
|
||
// when | ||
Optional<UserDto> actualResult = sut.findDtoByKakaoUid(kakaoUid); | ||
UserDto actualResult = sut.getDtoByPhone(phone); | ||
|
||
// then | ||
then(userRepository).should().findByKakaoUid(kakaoUid); | ||
then(userRepository).should().findByPhone(phone); | ||
verifyEveryMocksShouldHaveNoMoreInteractions(); | ||
assertThat(actualResult).isNotEmpty(); | ||
assertThat(actualResult.get()) | ||
assertThat(actualResult) | ||
.hasFieldOrPropertyWithValue("id", expectedResult.getId()) | ||
.hasFieldOrPropertyWithValue("kakaoUid", expectedResult.getKakaoUid()); | ||
.hasFieldOrPropertyWithValue("phone", expectedResult.getPhone()); | ||
} | ||
|
||
@Test | ||
void 전화번호가_주어지고_주어진_전화번호로_유저를_조회한다_만약_일치하는_유저가_없다면_예외가_발생한다() { | ||
// given | ||
String phone = "01012345678"; | ||
given(userRepository.findByPhone(phone)).willReturn(Optional.empty()); | ||
|
||
// when | ||
Throwable t = catchThrowable(() -> sut.getDtoByPhone(phone)); | ||
|
||
// then | ||
then(userRepository).should().findByPhone(phone); | ||
verifyEveryMocksShouldHaveNoMoreInteractions(); | ||
assertThat(t).isInstanceOf(UserNotFoundByPhoneException.class); | ||
} | ||
|
||
@Test | ||
|
@@ -170,7 +204,7 @@ private void verifyEveryMocksShouldHaveNoMoreInteractions() { | |
then(userRepository).shouldHaveNoMoreInteractions(); | ||
} | ||
|
||
private User createUser(Long id, String email, String kakaoUid) throws Exception { | ||
private User createUser(Long id, String email, String kakaoUid, String phone) throws Exception { | ||
Constructor<User> userConstructor = User.class.getDeclaredConstructor( | ||
Long.class, Set.class, String.class, String.class, String.class, | ||
String.class, LocalDate.class, Gender.class, String.class, String.class | ||
|
@@ -185,12 +219,12 @@ private User createUser(Long id, String email, String kakaoUid) throws Exception | |
"https://user-default-profile-image-url", | ||
LocalDate.of(2024, 1, 1), | ||
Gender.ETC, | ||
"01012345678", | ||
phone, | ||
null | ||
); | ||
} | ||
|
||
private User createUser(Long id) throws Exception { | ||
return createUser(id, "[email protected]", "12345"); | ||
return createUser(id, "[email protected]", "12345", "01012345678"); | ||
} | ||
} |