Skip to content

Commit

Permalink
✅ [Test] 매너 정보 조회 API 분리로 인한 테스트 케이스 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Eunjin3395 committed Jan 17, 2025
1 parent 7214194 commit c1e77c3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public ApiResponse<MannerRatingResponse> getNegativeMannerRatingInfo(
@Parameter(name = "memberId", description = "대상 회원의 id 입니다.")
@GetMapping("/level/{memberId}")
public ApiResponse<MannerResponse> getMannerLevelInfo(@PathVariable(name = "memberId") Long memberId) {
return ApiResponse.ok(mannerFacadeService.getMannerInfo(memberId));
return ApiResponse.ok(mannerFacadeService.getMannerLevelInfo(memberId));
}

@Operation(summary = "특정 회원의 매너 키워드 정보 조회 API", description = "특정 회원의 매너 키워드 정보를 조회하는 API 입니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ public MannerRatingResponse getMannerRating(Member member, Long targetMemberId,
}

/**
* 해당 회원의 매너 정보 조회 facade 메소드
* 해당 회원의 매너 레벨 정보 조회 facade 메소드
*
* @param memberId 회원 id
* @return MannerResponse
*/
public MannerResponse getMannerInfo(Long memberId) {
public MannerResponse getMannerLevelInfo(Long memberId) {
Member member = memberService.findMemberById(memberId);

// 매너 레벨 조회
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.gamegoo.gamegoo_v2.social.manner.dto.request.MannerInsertRequest;
import com.gamegoo.gamegoo_v2.social.manner.dto.request.MannerUpdateRequest;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerInsertResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerKeywordListResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerRatingResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerUpdateResponse;
Expand Down Expand Up @@ -353,21 +354,37 @@ void getNegativeMannerRatingInfoSucceeds() throws Exception {
.andExpect(jsonPath("$.data.mannerKeywordIdList").isArray());
}

@DisplayName("특정 회원의 매너 정보 조회")
@DisplayName("특정 회원의 매너 레벨 정보 조회")
@Test
void getMannerInfoSucceeds() throws Exception {
void getMannerLevelInfoSucceeds() throws Exception {
// given
MannerResponse response = MannerResponse.of(1, 50.0, 2, List.of());
MannerResponse response = MannerResponse.of(1, 50.0, 2);

given(mannerFacadeService.getMannerInfo(TARGET_MEMBER_ID)).willReturn(response);
given(mannerFacadeService.getMannerLevelInfo(TARGET_MEMBER_ID)).willReturn(response);

// when // then
mockMvc.perform(get(API_URL_PREFIX + "/{memberId}", TARGET_MEMBER_ID))
mockMvc.perform(get(API_URL_PREFIX + "/level/{memberId}", TARGET_MEMBER_ID))
.andExpect(status().isOk())
.andExpect(jsonPath("$.message").value("OK"))
.andExpect(jsonPath("$.data.mannerLevel").value(1))
.andExpect(jsonPath("$.data.mannerRank").value(50.0))
.andExpect(jsonPath("$.data.mannerRatingCount").value(2))
.andExpect(jsonPath("$.data.mannerRatingCount").value(2));
}

@DisplayName("특정 회원의 매너 키워드 정보 조회")
@Test
void getMannerKeywordInfoSucceeds() throws Exception {
// given
MannerKeywordListResponse response = MannerKeywordListResponse.builder()
.mannerKeywords(List.of())
.build();

given(mannerFacadeService.getMannerKeywordInfo(TARGET_MEMBER_ID)).willReturn(response);

// when // then
mockMvc.perform(get(API_URL_PREFIX + "/keyword/{memberId}", TARGET_MEMBER_ID))
.andExpect(status().isOk())
.andExpect(jsonPath("$.message").value("OK"))
.andExpect(jsonPath("$.data.mannerKeywords").isArray());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.gamegoo.gamegoo_v2.social.manner.dto.request.MannerInsertRequest;
import com.gamegoo.gamegoo_v2.social.manner.dto.request.MannerUpdateRequest;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerInsertResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerKeywordListResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerRatingResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerResponse;
import com.gamegoo.gamegoo_v2.social.manner.dto.response.MannerUpdateResponse;
Expand Down Expand Up @@ -443,6 +444,7 @@ void insertNegativeMannerRatingSucceedsWhenMannerLevelDown() {
eq(NotificationTypeTitle.MANNER_LEVEL_DOWN), any(Member.class), eq(1));
});
}

}

@Nested
Expand Down Expand Up @@ -806,6 +808,7 @@ void updateMannerRatingSucceedsWhenNegativeKeyword() {
verify(notificationService, times(0)).createMannerLevelNotification(any(), any(Member.class), any());
});
}

}

@Nested
Expand Down Expand Up @@ -884,17 +887,18 @@ void getMannerRatingSucceedsWhenNegativeNotExist() {
assertThat(response.getMannerRatingId()).isNull();
assertThat(response.getMannerKeywordIdList()).isEmpty();
}

}

@Nested
@DisplayName("회원 매너 정보 조회")
class GetMannerInfoTest {
@DisplayName("회원 매너 레벨 정보 조회")
class GetMannerLevelInfoTest {

@DisplayName("실패: 대상 회원을 찾을 수 없는 경우 예외가 발생한다.")
@Test
void getMannerInfo_shouldThrownWhenMemberNotFound() {
// when // then
assertThatThrownBy(() -> mannerFacadeService.getMannerInfo(1000L))
assertThatThrownBy(() -> mannerFacadeService.getMannerLevelInfo(1000L))
.isInstanceOf(MemberException.class)
.hasMessage(ErrorCode.MEMBER_NOT_FOUND.getMessage());
}
Expand All @@ -903,16 +907,12 @@ void getMannerInfo_shouldThrownWhenMemberNotFound() {
@Test
void getMannerInfoSucceedsWhenNoMannerRating() {
// when
MannerResponse response = mannerFacadeService.getMannerInfo(member.getId());
MannerResponse response = mannerFacadeService.getMannerLevelInfo(member.getId());

// then
assertThat(response.getMannerLevel()).isEqualTo(1);
assertThat(response.getMannerRank()).isNull();
assertThat(response.getMannerRatingCount()).isEqualTo(0);
assertThat(response.getMannerKeywords())
.isNotNull()
.hasSize(12)
.allSatisfy(mannerKeywordResponse -> assertThat(mannerKeywordResponse.getCount()).isEqualTo(0));
}

@DisplayName("성공: 받은 매너 평가가 있는 경우")
Expand All @@ -932,13 +932,63 @@ void getMannerInfoSucceeds() {
memberRepository.save(member);

// when
MannerResponse response = mannerFacadeService.getMannerInfo(member.getId());
MannerResponse response = mannerFacadeService.getMannerLevelInfo(member.getId());

// then
assertThat(response.getMannerLevel()).isEqualTo(1);
assertThat(response.getMannerRank()).isEqualTo(50.0);
assertThat(response.getMannerRatingCount()).isEqualTo(2);
}

}

@Nested
@DisplayName("회원 매너 키워드 정보 조회")
class GetMannerKeywordInfoTest {

@DisplayName("실패: 대상 회원을 찾을 수 없는 경우 예외가 발생한다.")
@Test
void getMannerKeywordInfo_shouldThrownWhenMemberNotFound() {
// when // then
assertThatThrownBy(() -> mannerFacadeService.getMannerKeywordInfo(1000L))
.isInstanceOf(MemberException.class)
.hasMessage(ErrorCode.MEMBER_NOT_FOUND.getMessage());
}

@DisplayName("성공: 받은 매너 평가가 없는 경우")
@Test
void getMannerKeywordInfoSucceedsWhenNoMannerRating() {
// when
MannerKeywordListResponse response = mannerFacadeService.getMannerKeywordInfo(member.getId());

// then
assertThat(response.getMannerKeywords())
.isNotNull()
.hasSize(12)
.allSatisfy(mannerKeywordResponse ->
assertThat(mannerKeywordResponse.getCount()).isEqualTo(0));
}

@DisplayName("성공: 받은 매너 평가가 있는 경우")
@Test
void getMannerKeywordInfoSucceeds() {
// given
Member targetMember1 = createMember("[email protected]", "targetMember1");
Member targetMember2 = createMember("[email protected]", "targetMember2");
Member targetMember3 = createMember("[email protected]", "targetMember3");

createMannerRating(List.of(1L, 2L, 3L, 4L, 5L, 6L), targetMember1, member, true);
createMannerRating(List.of(1L, 2L, 3L), targetMember2, member, true);
createMannerRating(List.of(7L, 8L), targetMember3, member, false);

member.updateMannerScore(5);
member.updateMannerRank(50.0);
memberRepository.save(member);

// when
MannerKeywordListResponse response = mannerFacadeService.getMannerKeywordInfo(member.getId());

// then
Map<Long, Integer> assertMap = new HashMap<>();
assertMap.put(1L, 2);
assertMap.put(2L, 2);
Expand Down

0 comments on commit c1e77c3

Please sign in to comment.