Skip to content

Commit

Permalink
[#52] test: follow, unfollow 성공 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyoungchoi95 committed Sep 20, 2021
1 parent 6ad2e36 commit 8f4c401
Showing 1 changed file with 43 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

import com.study.realworld.global.exception.BusinessException;
Expand Down Expand Up @@ -73,7 +75,7 @@ void loginUserNotFoundTest() {
@DisplayName("현재 검색하고자하는 username가 존재하지 않는 유저라면 Exception이 발생해야 한다.")
void followUsernameNotFoundTest() {

// setup & when
// setup & given
Long loginId = 1L;
Username followingUsername = Username.of("followuser");
when(userRepository.findById(loginId)).thenReturn(Optional.of(loginUser));
Expand All @@ -84,6 +86,25 @@ void followUsernameNotFoundTest() {
.isThrownBy(() -> profileService.followUser(loginId, followingUsername))
.withMessageMatching(ErrorCode.USER_NOT_FOUND.getMessage());
}

@Test
@DisplayName("follow한 결과를 반환할 수 있다.")
void followSuccessTest() {

// setup & given
Long loginId = 1L;
Username followingUsername = Username.of("followuser");
when(userRepository.findById(loginId)).thenReturn(Optional.of(loginUser));
when(userRepository.findByProfileUsername(followingUsername)).thenReturn(Optional.of(followUser));

// when
ProfileModel result = profileService.followUser(loginId, followingUsername);

// then
assertThat(result.getProfile()).isEqualTo(loginUser.profile());
assertTrue(result.isFollow());
}

}

@Nested
Expand All @@ -109,7 +130,7 @@ void loginUserNotFoundTest() {
@DisplayName("현재 검색하고자하는 username가 존재하지 않는 유저라면 Exception이 발생해야 한다.")
void followUsernameNotFoundTest() {

// setup & when
// setup & given
Long loginId = 1L;
Username followingUsername = Username.of("followuser");
when(userRepository.findById(loginId)).thenReturn(Optional.of(loginUser));
Expand All @@ -120,6 +141,26 @@ void followUsernameNotFoundTest() {
.isThrownBy(() -> profileService.unfollowUser(loginId, followingUsername))
.withMessageMatching(ErrorCode.USER_NOT_FOUND.getMessage());
}

@Test
@DisplayName("unfollow한 결과를 반환할 수 있다.")
void unfollowSuccessTest() {

// setup & given
Long loginId = 1L;
Username followingUsername = Username.of("followuser");
when(userRepository.findById(loginId)).thenReturn(Optional.of(loginUser));
when(userRepository.findByProfileUsername(followingUsername)).thenReturn(Optional.of(followUser));
loginUser.followingUser(followUser);

// when
ProfileModel result = profileService.unfollowUser(loginId, followingUsername);

// then
assertThat(result.getProfile()).isEqualTo(loginUser.profile());
assertFalse(result.isFollow());
}

}

@Test
Expand Down

0 comments on commit 8f4c401

Please sign in to comment.