diff --git a/backend/src/main/java/shook/shook/song/domain/killingpart/repository/KillingPartCommentRepository.java b/backend/src/main/java/shook/shook/song/domain/killingpart/repository/KillingPartCommentRepository.java index 4e9d883db..4a7f5064b 100644 --- a/backend/src/main/java/shook/shook/song/domain/killingpart/repository/KillingPartCommentRepository.java +++ b/backend/src/main/java/shook/shook/song/domain/killingpart/repository/KillingPartCommentRepository.java @@ -1,5 +1,6 @@ package shook.shook.song.domain.killingpart.repository; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; import shook.shook.member.domain.Member; @@ -9,4 +10,6 @@ public interface KillingPartCommentRepository extends JpaRepository { void deleteAllByMember(final Member member); + + List findAllByMember(final Member member); } diff --git a/backend/src/test/java/shook/shook/member/application/MemberServiceTest.java b/backend/src/test/java/shook/shook/member/application/MemberServiceTest.java index 359e520a7..acaae59e8 100644 --- a/backend/src/test/java/shook/shook/member/application/MemberServiceTest.java +++ b/backend/src/test/java/shook/shook/member/application/MemberServiceTest.java @@ -1,12 +1,14 @@ package shook.shook.member.application; +import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import org.assertj.core.api.AssertionsForClassTypes; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.jdbc.Sql; import shook.shook.auth.exception.AuthorizationException; import shook.shook.auth.ui.Authority; import shook.shook.auth.ui.argumentresolver.MemberInfo; @@ -14,8 +16,15 @@ import shook.shook.member.domain.Nickname; import shook.shook.member.domain.repository.MemberRepository; import shook.shook.member.exception.MemberException; +import shook.shook.song.domain.killingpart.KillingPart; +import shook.shook.song.domain.killingpart.KillingPartComment; +import shook.shook.song.domain.killingpart.KillingPartLike; +import shook.shook.song.domain.killingpart.repository.KillingPartCommentRepository; +import shook.shook.song.domain.killingpart.repository.KillingPartLikeRepository; +import shook.shook.song.domain.killingpart.repository.KillingPartRepository; import shook.shook.support.UsingJpaTest; +@Sql("classpath:/killingpart/initialize_killing_part_song.sql") class MemberServiceTest extends UsingJpaTest { private static Member savedMember; @@ -23,11 +32,20 @@ class MemberServiceTest extends UsingJpaTest { @Autowired private MemberRepository memberRepository; + @Autowired + private KillingPartRepository killingPartRepository; + + @Autowired + private KillingPartCommentRepository partCommentRepository; + + @Autowired + private KillingPartLikeRepository likeRepository; + private MemberService memberService; @BeforeEach void setUp() { - memberService = new MemberService(memberRepository); + memberService = new MemberService(memberRepository, partCommentRepository, likeRepository); savedMember = memberRepository.save(new Member("woowa@wooteco.com", "shook")); } @@ -43,8 +61,8 @@ void register() { //then final String nickname = email.split("@")[0]; - assertThat(result.getEmail()).isEqualTo(email); - assertThat(result.getNickname()).isEqualTo(nickname); + AssertionsForClassTypes.assertThat(result.getEmail()).isEqualTo(email); + AssertionsForClassTypes.assertThat(result.getNickname()).isEqualTo(nickname); } @DisplayName("중복된 이메일로 회원을 등록되는 경우 예외를 던진다.") @@ -67,9 +85,10 @@ void findByEmail() { final Member result = memberService.findByEmail(savedMember.getEmail()).get(); //then - assertThat(result.getId()).isEqualTo(savedMember.getId()); - assertThat(result.getEmail()).isEqualTo(savedMember.getEmail()); - assertThat(result.getNickname()).isEqualTo(savedMember.getNickname()); + AssertionsForClassTypes.assertThat(result.getId()).isEqualTo(savedMember.getId()); + AssertionsForClassTypes.assertThat(result.getEmail()).isEqualTo(savedMember.getEmail()); + AssertionsForClassTypes.assertThat(result.getNickname()) + .isEqualTo(savedMember.getNickname()); } @DisplayName("회원을 id와 nickname으로 조회한다.") @@ -82,7 +101,8 @@ void success_findByIdAndNickname() { new Nickname(savedMember.getNickname())); //then - assertThat(result).usingRecursiveComparison().isEqualTo(savedMember); + AssertionsForClassTypes.assertThat(result).usingRecursiveComparison() + .isEqualTo(savedMember); } @DisplayName("회원을 id와 nickname으로 조회할 때 회원의 닉네임이 잘못되면 예외를 던진다.") @@ -121,19 +141,24 @@ void fail_findByIdAndNickname_wrong_memberId_and_nickname() { .isInstanceOf(MemberException.MemberNotExistException.class); } - @DisplayName("회원 id로 회원을 삭제한다.") + @DisplayName("회원 id로 회원을 삭제시 회원의 댓글을 모두 삭제하고 회원의 좋아요는 삭제 상태로 변환한다.") @Test void success_delete() { // given final Long targetId = savedMember.getId(); - final Long requestId = targetId; + final KillingPart killingPart = killingPartRepository.findById(1L).get(); + likeRepository.save(new KillingPartLike(killingPart, savedMember)); + partCommentRepository.save(KillingPartComment.forSave(killingPart, "hi", savedMember)); + + saveAndClearEntityManager(); // when - memberService.deleteById(targetId, new MemberInfo(requestId, Authority.MEMBER)); + memberService.deleteById(targetId, new MemberInfo(targetId, Authority.MEMBER)); // then - assertThat(memberRepository.findById(targetId)) - .isEmpty(); + assertThat(likeRepository.findAllByMemberAndIsDeleted(savedMember, false)).isEmpty(); + assertThat(partCommentRepository.findAllByMember(savedMember)).isEmpty(); + assertThat(memberRepository.findById(targetId)).isEmpty(); } @DisplayName("회원 id로 회원을 삭제할 때, 존재하지 않는 id 라면 예외가 발생한다.") diff --git a/backend/src/test/java/shook/shook/song/domain/killingpart/repository/KillingPartCommentRepositoryTest.java b/backend/src/test/java/shook/shook/song/domain/killingpart/repository/KillingPartCommentRepositoryTest.java index fdf6dbe94..1eeb4c30f 100644 --- a/backend/src/test/java/shook/shook/song/domain/killingpart/repository/KillingPartCommentRepositoryTest.java +++ b/backend/src/test/java/shook/shook/song/domain/killingpart/repository/KillingPartCommentRepositoryTest.java @@ -69,9 +69,9 @@ void createdAt() { assertThat(partComment.getCreatedAt()).isBetween(prev, after); } - @DisplayName("KillingPartComment 를 저장할 때의 시간 정보로 createAt이 자동 생성된다.") + @DisplayName("멤버가 작성한 모든 파트 댓글을 삭제한다.") @Test - void deleteAllByMemberId() { + void deleteAllByMember() { //given killingPartRepository.deleteAll(); final KillingPartComment partComment1 = KillingPartComment.forSave(SAVED_KILLING_PART, @@ -82,7 +82,7 @@ void deleteAllByMemberId() { killingPartCommentRepository.save(partComment2); //when - killingPartCommentRepository.deleteAllByMember_Id(MEMBER.getId()); + killingPartCommentRepository.deleteAllByMember(MEMBER); //then final List all = killingPartRepository.findAll();