-
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.
[#52] test: UserService findByUsername 테스트 추가
- Loading branch information
1 parent
5dc4863
commit 437a7e9
Showing
1 changed file
with
31 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -181,8 +181,7 @@ void findByIdSuccessTest() { | |
User result = userService.findById(userId); | ||
|
||
// then | ||
assertThat(result).isNotNull(); | ||
assertThat(result.email()).isEqualTo(user.email()); | ||
assertThat(result).isEqualTo(user); | ||
} | ||
|
||
@Test | ||
|
@@ -212,6 +211,36 @@ void findByNoUserIdFailTest() { | |
.withMessageMatching(ErrorCode.USER_NOT_FOUND.getMessage()); | ||
} | ||
|
||
@Test | ||
@DisplayName("username를 가지고 유저를 조회할 때 해당 유저가 존재하면 해당 유저를 반환한다.") | ||
void findByUsernameSuccessTest() { | ||
|
||
// setup & given | ||
Username username = Username.of("uesrname"); | ||
User user = User.Builder().email(Email.of("[email protected]")).profile(username, null, null).build(); | ||
when(userRepository.findByProfileUsername(username)).thenReturn(ofNullable(user)); | ||
|
||
// when | ||
User result = userService.findByUsername(username); | ||
|
||
// then | ||
assertThat(result).isEqualTo(user); | ||
} | ||
|
||
@Test | ||
@DisplayName("없는 유저의 username를 가지고 유저를 조회할 때 Exception이 반환되어야 한다.") | ||
void findByNoUserUsesrnameFailTest() { | ||
|
||
// setup & given | ||
Username username = Username.of("username"); | ||
when(userRepository.findByProfileUsername(username)).thenReturn(empty()); | ||
|
||
// when & then | ||
assertThatExceptionOfType(BusinessException.class) | ||
.isThrownBy(() -> userService.findByUsername(username)) | ||
.withMessageMatching(ErrorCode.USER_NOT_FOUND.getMessage()); | ||
} | ||
|
||
@Test | ||
@DisplayName("없는 유저의 id를 가지고 update 요청 시 exception이 발생되어야 한다.") | ||
void updateFailByNotFoundUserTest() { | ||
|