Skip to content
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

refactor: response에 경기 오너 토큰 추가 #444

Merged
merged 4 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public record LeagueDetailsResponse(
@Schema(description = "경기 아이디", requiredMode = Schema.RequiredMode.REQUIRED)
Long leagueId,

@Schema(description = "경기 주인 토큰", requiredMode = RequiredMode.REQUIRED)
@Schema(description = "경기 오너 토큰", requiredMode = RequiredMode.REQUIRED)
String leagueOwnerToken,

@Schema(description = "경기 이름", requiredMode = Schema.RequiredMode.REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
package org.badminton.api.interfaces.member.dto;

import org.badminton.domain.domain.member.entity.Member;

import io.swagger.v3.oas.annotations.media.Schema;
import org.badminton.domain.domain.member.entity.Member;

@Schema(description = "로그인 세션 확인 Dto")
public record SimpleMemberResponse(

@Schema(description = "회원 이름", example = "이선우")
String name,
@Schema(description = "회원 이름", example = "이선우")
String name,

@Schema(description = "oAuth 로그인 이메일", example = "qosle@naver.com")
String email,
@Schema(description = "회원 토큰", example = "member_token_1")
String memberToken,

@Schema(description = "oAuth 제공 ID", example = "1070449979547641023123")
Member.MemberTier memberTier,
@Schema(description = "oAuth 로그인 이메일", example = "qosle@naver.com")
String email,

@Schema(description = "회원 역할", example = "AUTHORIZATION_USER")
String authorization,
@Schema(description = "oAuth 제공 ID", example = "1070449979547641023123")
Member.MemberTier memberTier,

@Schema(description = "oAuth 제공 이미지", example = "1070449979547641023123")
String profileImage
@Schema(description = "회원 역할", example = "AUTHORIZATION_USER")
String authorization,

@Schema(description = "oAuth 제공 이미지", example = "1070449979547641023123")
String profileImage
) {

}


Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.badminton.api.application.member;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

import org.badminton.api.interfaces.match.dto.MatchResultResponse;
import org.badminton.domain.common.enums.MatchStatus;
import org.badminton.domain.common.enums.MatchType;
Expand Down Expand Up @@ -34,141 +36,142 @@

class MemberFacadeTest {

@Mock
private MemberService memberService;

@Mock
private LeagueRecordService leagueRecordService;
@Mock
private MemberService memberService;

@Mock
private ClubMemberService clubMemberService;
@Mock
private LeagueRecordService leagueRecordService;

@Mock
private MatchResultService matchResultService;
@Mock
private ClubMemberService clubMemberService;

@InjectMocks
private MemberFacade memberFacade;
@Mock
private MatchResultService matchResultService;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}
@InjectMocks
private MemberFacade memberFacade;

@Test
@DisplayName("회원 마이페이지 조회 API 테스트")
void getMemberMyPageInfoTest() {
String memberToken = "testToken";
@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}

List<ClubMemberMyPageInfo> clubMemberMyPageInfos = new ArrayList<>();
when(clubMemberService.getClubMembers(memberToken)).thenReturn(clubMemberMyPageInfos);
@Test
@DisplayName("회원 마이페이지 조회 API 테스트")
void getMemberMyPageInfoTest() {
String memberToken = "testToken";

LeagueRecord leagueRecord = mock(LeagueRecord.class);
when(leagueRecordService.getLeagueRecord(memberToken)).thenReturn(leagueRecord);
List<ClubMemberMyPageInfo> clubMemberMyPageInfos = new ArrayList<>();
when(clubMemberService.getClubMembers(memberToken)).thenReturn(clubMemberMyPageInfos);

LeagueRecordInfo leagueRecordInfo = LeagueRecordInfo.from(leagueRecord);
MemberMyPageInfo expectedInfo = new MemberMyPageInfo("testToken", "김철수", "abcd@naver.com", "www.naver.com",
Member.MemberTier.BRONZE, 3, 2, 1, 6, null);
when(memberService.getMemberInfo(memberToken, leagueRecordInfo, clubMemberMyPageInfos)).thenReturn(
expectedInfo);
LeagueRecord leagueRecord = mock(LeagueRecord.class);
when(leagueRecordService.getLeagueRecord(memberToken)).thenReturn(leagueRecord);

MemberMyPageInfo result = memberFacade.getMemberMyPageInfo(memberToken);
LeagueRecordInfo leagueRecordInfo = LeagueRecordInfo.from(leagueRecord);
MemberMyPageInfo expectedInfo = new MemberMyPageInfo("testToken", "김철수", "abcd@naver.com", "www.naver.com",
Member.MemberTier.BRONZE, 3, 2, 1, 6, null);
when(memberService.getMemberInfo(memberToken, leagueRecordInfo, clubMemberMyPageInfos)).thenReturn(
expectedInfo);

assertNotNull(result);
assertEquals(expectedInfo, result);
MemberMyPageInfo result = memberFacade.getMemberMyPageInfo(memberToken);

verify(clubMemberService).getClubMembers(memberToken);
verify(leagueRecordService).getLeagueRecord(memberToken);
verify(memberService).getMemberInfo(memberToken, leagueRecordInfo, clubMemberMyPageInfos);
}
assertNotNull(result);
assertEquals(expectedInfo, result);

@Test
@DisplayName("회원 정보 간단 조회 API 테스트")
void getSimpleMemberTest() {
String memberToken = "testToken";
SimpleMemberInfo expectedInfo = new SimpleMemberInfo(null, "김철수", "abcd@naver.com", Member.MemberTier.BRONZE,
"www.naver.com");
verify(clubMemberService).getClubMembers(memberToken);
verify(leagueRecordService).getLeagueRecord(memberToken);
verify(memberService).getMemberInfo(memberToken, leagueRecordInfo, clubMemberMyPageInfos);
}

when(memberService.getSimpleMember(memberToken)).thenReturn(expectedInfo);
@Test
@DisplayName("회원 정보 간단 조회 API 테스트")
void getSimpleMemberTest() {
String memberToken = "testToken";
SimpleMemberInfo expectedInfo = new SimpleMemberInfo(null, "member_token_1", "김철수", "abcd@naver.com",
Member.MemberTier.BRONZE,
"www.naver.com");

SimpleMemberInfo result = memberFacade.getSimpleMember(memberToken);
when(memberService.getSimpleMember(memberToken)).thenReturn(expectedInfo);

assertNotNull(result);
assertEquals(expectedInfo, result);
SimpleMemberInfo result = memberFacade.getSimpleMember(memberToken);

verify(memberService).getSimpleMember(memberToken);
}
assertNotNull(result);
assertEquals(expectedInfo, result);

@Test
@DisplayName("회원 정보 업데이트 API 테스트")
void updateProfileTest() {
String memberToken = "testToken";
String imageUrl = "image_url";
String name = "name";
MemberUpdateInfo expectedInfo = new MemberUpdateInfo("testToken", null, "김철수", "abc@naver.com", "providerId",
"profileImage");
verify(memberService).getSimpleMember(memberToken);
}

when(memberService.updateProfile(memberToken, imageUrl, name)).thenReturn(expectedInfo);
@Test
@DisplayName("회원 정보 업데이트 API 테스트")
void updateProfileTest() {
String memberToken = "testToken";
String imageUrl = "image_url";
String name = "name";
MemberUpdateInfo expectedInfo = new MemberUpdateInfo("testToken", null, "김철수", "abc@naver.com", "providerId",
"profileImage");

MemberUpdateInfo result = memberFacade.updateProfile(memberToken, imageUrl, name);
when(memberService.updateProfile(memberToken, imageUrl, name)).thenReturn(expectedInfo);

assertNotNull(result);
assertEquals(expectedInfo, result);
MemberUpdateInfo result = memberFacade.updateProfile(memberToken, imageUrl, name);

verify(memberService).updateProfile(memberToken, imageUrl, name);
}
assertNotNull(result);
assertEquals(expectedInfo, result);

@Test
@DisplayName("회원이 가입되어 있는 동호회 조회 API 테스트")
void getMyClubsTest() {
String memberToken = "testToken";
List<ClubCardInfo> expectedClubs = new ArrayList<>();
verify(memberService).updateProfile(memberToken, imageUrl, name);
}

when(clubMemberService.getClubsByMemberToken(memberToken)).thenReturn(expectedClubs);
@Test
@DisplayName("회원이 가입되어 있는 동호회 조회 API 테스트")
void getMyClubsTest() {
String memberToken = "testToken";
List<ClubCardInfo> expectedClubs = new ArrayList<>();

List<ClubCardInfo> result = memberFacade.getMyClubs(memberToken);
when(clubMemberService.getClubsByMemberToken(memberToken)).thenReturn(expectedClubs);

assertNotNull(result);
assertEquals(expectedClubs, result);
List<ClubCardInfo> result = memberFacade.getMyClubs(memberToken);

verify(clubMemberService).getClubsByMemberToken(memberToken);
}
assertNotNull(result);
assertEquals(expectedClubs, result);

@Test
@DisplayName("회원 매치 전적 조회 API 테스트")
void getMemberMatchResultsTest() {
String memberToken = "testToken";
int page = 0;
int size = 10;
verify(clubMemberService).getClubsByMemberToken(memberToken);
}

// Mock ClubMemberMyPageInfo
ClubMemberMyPageInfo clubMember = mock(ClubMemberMyPageInfo.class);
when(clubMember.clubMemberId()).thenReturn(1L); // 반환 타입은 Long
when(clubMemberService.getClubMembers(memberToken)).thenReturn(
List.of(clubMember)); // 반환 타입은 List<ClubMemberMyPageInfo>
@Test
@DisplayName("회원 매치 전적 조회 API 테스트")
void getMemberMatchResultsTest() {
String memberToken = "testToken";
int page = 0;
int size = 10;

// Mock MatchResultInfo
MatchResultInfo matchResult = mock(MatchResultInfo.class);
when(matchResult.matchId()).thenReturn(1L);
when(matchResult.leagueId()).thenReturn(10L);
when(matchResult.matchType()).thenReturn(MatchType.SINGLES);
when(matchResult.singlesMatch()).thenReturn(mock(SinglesMatchResultInfo.class));
when(matchResult.matchStatus()).thenReturn(MatchStatus.FINISHED);
when(matchResult.leagueAt()).thenReturn(LocalDateTime.now());

// MatchResultService의 동작 설정
when(matchResultService.getAllMatchResultsByClubMember(1L)).thenReturn(List.of(matchResult));
// Mock ClubMemberMyPageInfo
ClubMemberMyPageInfo clubMember = mock(ClubMemberMyPageInfo.class);
when(clubMember.clubMemberId()).thenReturn(1L); // 반환 타입은 Long
when(clubMemberService.getClubMembers(memberToken)).thenReturn(
List.of(clubMember)); // 반환 타입은 List<ClubMemberMyPageInfo>

// Mock MatchResultInfo
MatchResultInfo matchResult = mock(MatchResultInfo.class);
when(matchResult.matchId()).thenReturn(1L);
when(matchResult.leagueId()).thenReturn(10L);
when(matchResult.matchType()).thenReturn(MatchType.SINGLES);
when(matchResult.singlesMatch()).thenReturn(mock(SinglesMatchResultInfo.class));
when(matchResult.matchStatus()).thenReturn(MatchStatus.FINISHED);
when(matchResult.leagueAt()).thenReturn(LocalDateTime.now());

// MatchResultService의 동작 설정
when(matchResultService.getAllMatchResultsByClubMember(1L)).thenReturn(List.of(matchResult));

// Perform the test
Page<MatchResultResponse> result = memberFacade.getMemberMatchResults(memberToken, page, size);
// Perform the test
Page<MatchResultResponse> result = memberFacade.getMemberMatchResults(memberToken, page, size);

// Assertions
assertNotNull(result);
assertEquals(1, result.getContent().size());
assertEquals(matchResult.matchId(), result.getContent().get(0).matchId());

// Verify 호출 확인
verify(clubMemberService).getClubMembers(memberToken);
verify(matchResultService).getAllMatchResultsByClubMember(1L);
}
// Assertions
assertNotNull(result);
assertEquals(1, result.getContent().size());
assertEquals(matchResult.matchId(), result.getContent().get(0).matchId());

// Verify 호출 확인
verify(clubMemberService).getClubMembers(memberToken);
verify(matchResultService).getAllMatchResultsByClubMember(1L);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@

public record SimpleMemberInfo(

String authorization,
String authorization,

String name,
String memberToken,

String email,
String name,

Member.MemberTier memberTier,
String email,

String profileImage
Member.MemberTier memberTier,

String profileImage
) {
public static SimpleMemberInfo from(Member member) {
return new SimpleMemberInfo(member.getAuthorization(), member.getName(),
member.getEmail(), member.getTier(), member.getProfileImage());
}
public static SimpleMemberInfo from(Member member) {
return new SimpleMemberInfo(member.getAuthorization(), member.getMemberToken(), member.getName(),
member.getEmail(), member.getTier(), member.getProfileImage());
}

}
Loading