-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TEST] friend service repository 테스트
- Loading branch information
Showing
8 changed files
with
230 additions
and
24 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
105 changes: 105 additions & 0 deletions
105
backend/src/test/java/com/twtw/backend/domain/friend/repository/FriendRepositoryTest.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,105 @@ | ||
package com.twtw.backend.domain.friend.repository; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.twtw.backend.domain.friend.entity.Friend; | ||
import com.twtw.backend.domain.friend.entity.FriendStatus; | ||
import com.twtw.backend.domain.member.entity.AuthType; | ||
import com.twtw.backend.domain.member.entity.Member; | ||
import com.twtw.backend.domain.member.entity.OAuth2Info; | ||
import com.twtw.backend.domain.member.repository.MemberRepository; | ||
import com.twtw.backend.support.repository.RepositoryTest; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
@DisplayName("FriendRepository에") | ||
class FriendRepositoryTest extends RepositoryTest { | ||
|
||
@Autowired private FriendRepository friendRepository; | ||
@Autowired private MemberRepository memberRepository; | ||
|
||
@Test | ||
@DisplayName("저장이 수행되는가") | ||
void save() { | ||
// given | ||
final Member from = memberRepository.save(new Member("1", "123", new OAuth2Info("321", AuthType.APPLE))); | ||
final Member to = memberRepository.save(new Member("2", "1234", new OAuth2Info("123", AuthType.KAKAO))); | ||
final Friend friend = new Friend(from, to); | ||
|
||
// when | ||
final UUID friendId = friendRepository.save(friend).getId(); | ||
|
||
// then | ||
assertThat(friendId).isNotNull(); | ||
} | ||
|
||
@Test | ||
@DisplayName("두 멤버 pk로 조회가 수행되는가") | ||
void findByTwoMemberId() { | ||
// given | ||
final Member from = memberRepository.save(new Member("1", "123", new OAuth2Info("321", AuthType.APPLE))); | ||
final Member to = memberRepository.save(new Member("2", "1234", new OAuth2Info("123", AuthType.KAKAO))); | ||
final Friend friend = new Friend(from, to); | ||
final Friend expected = friendRepository.save(friend); | ||
|
||
// when | ||
final Friend result = friendRepository.findByTwoMemberId(from.getId(), to.getId()).orElseThrow(); | ||
|
||
// then | ||
assertThat(result.getId()).isEqualTo(expected.getId()); | ||
} | ||
|
||
@Test | ||
@DisplayName("멤버를 통한 조회가 수행되는가") | ||
void findByMember() { | ||
// given | ||
final Member from = memberRepository.save(new Member("1", "123", new OAuth2Info("321", AuthType.APPLE))); | ||
final Member to = memberRepository.save(new Member("2", "1234", new OAuth2Info("123", AuthType.KAKAO))); | ||
final Friend friend = new Friend(from, to); | ||
final Friend expected = friendRepository.save(friend); | ||
expected.updateStatus(FriendStatus.ACCEPTED); | ||
|
||
// when | ||
final List<Friend> result = friendRepository.findByMember(from); | ||
|
||
// then | ||
assertThat(result).hasSize(1); | ||
} | ||
|
||
@Test | ||
@DisplayName("멤버와 친구 상태를 통한 조회가 수행되는가") | ||
void findByMemberAndFriendStatus() { | ||
// given | ||
final Member from = memberRepository.save(new Member("1", "123", new OAuth2Info("321", AuthType.APPLE))); | ||
final Member to = memberRepository.save(new Member("2", "1234", new OAuth2Info("123", AuthType.KAKAO))); | ||
final Friend friend = new Friend(from, to); | ||
friendRepository.save(friend); | ||
|
||
// when | ||
final List<Friend> result = friendRepository.findByMemberAndFriendStatus(from, friend.getFriendStatus()); | ||
|
||
// then | ||
assertThat(result).hasSize(1); | ||
} | ||
|
||
@Test | ||
@DisplayName("멤버와 닉네임을 통한 검색이 수행되는가") | ||
void findByMemberAndMemberNickname() { | ||
// given | ||
final Member from = memberRepository.save(new Member("1", "123", new OAuth2Info("321", AuthType.APPLE))); | ||
final String friendNickname = "2"; | ||
final Member to = memberRepository.save(new Member(friendNickname, "1234", new OAuth2Info("123", AuthType.KAKAO))); | ||
final Friend friend = new Friend(from, to); | ||
final Friend expected = friendRepository.save(friend); | ||
expected.updateStatus(FriendStatus.ACCEPTED); | ||
|
||
// when | ||
final List<Friend> result = friendRepository.findByMemberAndMemberNickname(from, friendNickname); | ||
|
||
// then | ||
assertThat(result).hasSize(1); | ||
} | ||
} |
101 changes: 101 additions & 0 deletions
101
backend/src/test/java/com/twtw/backend/domain/friend/service/FriendServiceTest.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,101 @@ | ||
package com.twtw.backend.domain.friend.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.twtw.backend.domain.friend.dto.request.FriendRequest; | ||
import com.twtw.backend.domain.friend.dto.request.FriendUpdateRequest; | ||
import com.twtw.backend.domain.friend.dto.response.FriendResponse; | ||
import com.twtw.backend.domain.friend.entity.Friend; | ||
import com.twtw.backend.domain.friend.entity.FriendStatus; | ||
import com.twtw.backend.domain.friend.repository.FriendRepository; | ||
import com.twtw.backend.domain.member.entity.AuthType; | ||
import com.twtw.backend.domain.member.entity.Member; | ||
import com.twtw.backend.domain.member.entity.OAuth2Info; | ||
import com.twtw.backend.support.service.LoginTest; | ||
import java.util.List; | ||
import java.util.UUID; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
@DisplayName("FriendService의") | ||
class FriendServiceTest extends LoginTest { | ||
|
||
@Autowired private FriendService friendService; | ||
@Autowired private FriendRepository friendRepository; | ||
|
||
@Test | ||
@DisplayName("요청 추가가 수행되는가") | ||
void addRequest() { | ||
// given | ||
final UUID id = memberRepository.save(new Member("1", "12", new OAuth2Info("123", AuthType.APPLE))).getId(); | ||
|
||
// when | ||
friendService.addRequest(new FriendRequest(id)); | ||
|
||
// then | ||
final List<Friend> result = friendRepository.findByMemberAndFriendStatus(loginUser, FriendStatus.REQUESTED); | ||
assertThat(result).hasSize(1); | ||
} | ||
|
||
@Test | ||
@DisplayName("상태 업데이트가 수행되는가") | ||
void updateStatus() { | ||
// given | ||
final Member toMember = memberRepository.save(new Member("1", "12", new OAuth2Info("123", AuthType.APPLE))); | ||
final Friend friend = friendRepository.save(new Friend(loginUser, toMember)); | ||
|
||
// when | ||
final FriendStatus status = FriendStatus.ACCEPTED; | ||
friendService.updateStatus(new FriendUpdateRequest(toMember.getId(), status)); | ||
|
||
// then | ||
final Friend result = friendRepository.findById(friend.getId()).orElseThrow(); | ||
assertThat(result.getFriendStatus()).isEqualTo(status); | ||
} | ||
|
||
@Test | ||
@DisplayName("친구 목록 조회가 수행되는가") | ||
void getFriends() { | ||
// given | ||
final Member toMember = memberRepository.save(new Member("1", "12", new OAuth2Info("123", AuthType.APPLE))); | ||
friendRepository.save(new Friend(loginUser, toMember)); | ||
friendService.updateStatus(new FriendUpdateRequest(toMember.getId(), FriendStatus.ACCEPTED)); | ||
|
||
// when | ||
final List<FriendResponse> result = friendService.getFriends(); | ||
|
||
// then | ||
assertThat(result).hasSize(1); | ||
} | ||
|
||
@Test | ||
@DisplayName("상태를 통한 친구 조회가 수행되는가") | ||
void getFriendsByStatus() { | ||
// given | ||
final Member toMember = memberRepository.save(new Member("1", "12", new OAuth2Info("123", AuthType.APPLE))); | ||
friendRepository.save(new Friend(loginUser, toMember)); | ||
|
||
// when | ||
final List<FriendResponse> result = friendService.getFriendsByStatus(FriendStatus.REQUESTED); | ||
|
||
// then | ||
assertThat(result).hasSize(1); | ||
} | ||
|
||
@Test | ||
@DisplayName("닉네임을 통한 친구 조회가 수행되는가") | ||
void getFriendByNickname() { | ||
// given | ||
final String nickname = "1"; | ||
final Member toMember = memberRepository.save(new Member(nickname, "12", new OAuth2Info("123", AuthType.APPLE))); | ||
final Friend expected = friendRepository.save(new Friend(loginUser, toMember)); | ||
expected.updateStatus(FriendStatus.ACCEPTED); | ||
|
||
// when | ||
final List<FriendResponse> result = friendService.getFriendByNickname(nickname); | ||
|
||
// then | ||
assertThat(result).hasSize(1); | ||
} | ||
} |
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
14 changes: 11 additions & 3 deletions
14
backend/src/test/java/com/twtw/backend/support/repository/EnableDataJpa.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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
package com.twtw.backend.support.repository; | ||
|
||
import com.twtw.backend.support.database.DatabaseTest; | ||
|
||
import com.twtw.backend.config.database.QuerydslConfig; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
@DataJpaTest | ||
@DatabaseTest | ||
@ActiveProfiles("test") | ||
@Target(ElementType.TYPE) | ||
@Import(QuerydslConfig.class) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) | ||
public @interface EnableDataJpa {} |
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