-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e7b45a2
commit 630d3f8
Showing
3 changed files
with
44 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,51 @@ | ||
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; | ||
import shook.shook.member.domain.Member; | ||
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; | ||
|
||
@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("[email protected]", "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 라면 예외가 발생한다.") | ||
|
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