-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] member test #64
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
backend/src/test/java/com/twtw/backend/domain/member/repository/MemberRepositoryTest.java
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package com.twtw.backend.domain.member.repository; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.twtw.backend.domain.member.entity.Member; | ||
import com.twtw.backend.fixture.member.MemberEntityFixture; | ||
import com.twtw.backend.support.repository.RepositoryTest; | ||
|
||
import jakarta.persistence.EntityManager; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.UUID; | ||
|
||
@DisplayName("MemberRepository의") | ||
public class MemberRepositoryTest extends RepositoryTest { | ||
|
||
@Autowired private MemberRepository memberRepository; | ||
|
||
@Autowired private EntityManager em; | ||
|
||
@Test | ||
@DisplayName("PK를 통한 저장/조회가 성공하는가?") | ||
void saveAndFindId() { | ||
// given | ||
final Member member = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity()); | ||
|
||
// when | ||
final UUID expected = member.getId(); | ||
final Member result = memberRepository.findById(expected).orElseThrow(); | ||
|
||
// then | ||
assertThat(result.getId()).isEqualTo(member.getId()); | ||
} | ||
|
||
@Test | ||
@DisplayName("soft delete가 수행되는가?") | ||
void softDelete() { | ||
// given | ||
final Member member = MemberEntityFixture.FIRST_MEMBER.toEntity(); | ||
final UUID memberId = memberRepository.save(member).getId(); | ||
|
||
// when | ||
memberRepository.deleteById(memberId); | ||
em.flush(); | ||
em.clear(); | ||
|
||
// then | ||
assertThat(memberRepository.findById(memberId)).isEmpty(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
backend/src/test/java/com/twtw/backend/domain/member/service/MemberServiceTest.java
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 |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.twtw.backend.domain.member.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import com.twtw.backend.domain.member.dto.response.DuplicateNicknameResponse; | ||
import com.twtw.backend.domain.member.dto.response.MemberResponse; | ||
import com.twtw.backend.domain.member.entity.Member; | ||
import com.twtw.backend.domain.member.repository.MemberRepository; | ||
import com.twtw.backend.fixture.member.MemberEntityFixture; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
@DisplayName("MemberService의") | ||
public class MemberServiceTest { | ||
@Autowired private MemberService memberService; | ||
@Autowired private MemberRepository memberRepository; | ||
|
||
@Test | ||
@DisplayName("닉네임 중복 체크가 제대로 동작하는가") | ||
void checkNickname() { | ||
// given | ||
final Member member = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity()); | ||
// when | ||
DuplicateNicknameResponse response = memberService.duplicateNickname(member.getNickname()); | ||
// then | ||
assertTrue(response.getIsPresent()); | ||
} | ||
|
||
@Test | ||
@DisplayName("UUID를 통해 Member 조회가 되는가") | ||
void getMemberById() { | ||
// given | ||
final Member member = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity()); | ||
|
||
// when | ||
Member response = memberService.getMemberById(member.getId()); | ||
|
||
// then | ||
assertThat(response.getId()).isEqualTo(member.getId()); | ||
} | ||
|
||
@Test | ||
@DisplayName("Member가 MemberResponse로 변환이 되는가") | ||
void getResponseByMember() { | ||
// given | ||
final Member member = memberRepository.save(MemberEntityFixture.FIRST_MEMBER.toEntity()); | ||
|
||
// when | ||
MemberResponse memberResponse = memberService.getResponseByMember(member); | ||
|
||
// then | ||
assertThat(memberResponse.getId()).isEqualTo(member.getId()); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assertThat(~~).isTrue(); 와 같은 API도 있는데 이건 assertj 꺼라서 통일성을 주려면 이게 더 좋을 것 같아!