Skip to content

Commit

Permalink
test: 회원 탈퇴 테스트 코드 작성 #117
Browse files Browse the repository at this point in the history
  • Loading branch information
chaewss committed Apr 21, 2024
1 parent cb161fd commit fd41a6a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/test/java/com/cvsgo/controller/UserControllerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,18 @@ void respond_409_when_update_user_but_nickname_conflicts() throws Exception {
.andDo(print());
}

@Test
@DisplayName("회원 삭제에 성공하면 200을 응답한다")
void respond_200_when_delete_user_succeed() throws Exception {
mockMvc.perform(delete("/api/user")
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(print())
.andDo(document(documentIdentifier,
getDocumentRequest(),
getDocumentResponse()));
}

@Test
@DisplayName("회원 팔로우 생성에 성공하면 HTTP 201을 응답한다")
void respond_201_when_create_user_follow_succeed() throws Exception {
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/cvsgo/repository/UserRepositoryTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.cvsgo.config.TestConfig;
import com.cvsgo.entity.Role;
import com.cvsgo.entity.User;
import jakarta.persistence.EntityManager;
import java.util.ArrayList;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -14,7 +15,9 @@
import java.util.Optional;
import org.springframework.context.annotation.Import;

import static org.assertj.core.api.Assertions.as;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Import(TestConfig.class)
@DataJpaTest
Expand All @@ -24,6 +27,9 @@ class UserRepositoryTest {
@Autowired
private UserRepository userRepository;

@Autowired
private EntityManager em;

User user;

@BeforeEach
Expand Down Expand Up @@ -65,4 +71,22 @@ void succeed_to_find_user_by_email() {
assertThat(foundUser).isPresent();
}

@Test
@DisplayName("사용자를 soft delete 한다")
void succeed_to_soft_delete_user() {
// given
User foundUser = userRepository.findById(user.getId()).orElseThrow();

// when
userRepository.delete(foundUser);
em.flush();
em.clear();

User deletedUser = userRepository.findById(user.getId()).orElseThrow();

// then
assertThat(deletedUser).isNotNull();
assertTrue(deletedUser.getIsDeleted());
}

}
14 changes: 14 additions & 0 deletions src/test/java/com/cvsgo/service/UserServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.then;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;

import com.cvsgo.dto.user.SignUpRequestDto;
import com.cvsgo.dto.user.UpdateUserRequestDto;
Expand All @@ -21,6 +22,7 @@
import com.cvsgo.exception.BadRequestException;
import com.cvsgo.exception.DuplicateException;
import com.cvsgo.exception.NotFoundException;
import com.cvsgo.repository.RefreshTokenRepository;
import com.cvsgo.repository.ReviewRepository;
import com.cvsgo.repository.TagRepository;
import com.cvsgo.repository.UserFollowRepository;
Expand Down Expand Up @@ -57,6 +59,9 @@ class UserServiceTest {
@Mock
private UserFollowRepository userFollowRepository;

@Mock
private RefreshTokenRepository refreshTokenRepository;

@Mock
private ReviewRepository reviewRepository;

Expand Down Expand Up @@ -226,6 +231,15 @@ void should_throw_DuplicateException_when_update_user_but_nickname_is_duplicate(
then(userRepository).should(times(1)).findByNickname(request.getNickname());
}

@Test
@DisplayName("회원을 정상적으로 논리 삭제한다")
void succeed_to_soft_delete_user() {
userService.deleteUser(user);

then(refreshTokenRepository).should(times(1)).deleteAllByUser(user);
then(userRepository).should(times(1)).delete(any());
}

@Test
@DisplayName("회원 팔로우를 정상적으로 생성한다")
void succeed_to_create_user_follow() {
Expand Down

0 comments on commit fd41a6a

Please sign in to comment.