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

🐛 [Fix] pchange 히스토리 조회 시 game 시간 기준이 아닌 게임 점수 입력 시간 조회 수정 #731

Closed
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 @@ -14,6 +14,6 @@ public class UserHistoryData {

public UserHistoryData(PChange pChange) {
this.ppp = pChange.getPppResult();
this.date = pChange.getCreatedAt();
this.date = pChange.getGame().getStartTime();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pchange 가져오는 쿼리가 fetch join 으로 안되어있던데, 추가 쿼리 발생안하나요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

확인 결과 추가 쿼리가 많이 발생하여 해당 쿼리문에서 Game을 fetch join으로 수정할까하는데 괜찮을까요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 하는게 좋을것 같습니다!

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
package gg.pingpong.api.user.user.service;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;

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

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import gg.data.game.Game;
import gg.data.game.PChange;
import gg.data.game.type.Mode;
import gg.data.game.type.StatusType;
import gg.data.season.Season;
import gg.data.user.User;
import gg.data.user.type.RacketType;
import gg.data.user.type.RoleType;
import gg.data.user.type.SnsType;
import gg.pingpong.api.user.season.service.SeasonFindService;
import gg.pingpong.api.user.user.controller.response.UserHistoryResponseDto;
import gg.pingpong.api.utils.ReflectionUtilsForUnitTest;
import gg.repo.game.PChangeRepository;
import gg.utils.annotation.UnitTest;

@UnitTest
class UserServiceTest {

@Mock
SeasonFindService seasonFindService;

@Mock
PChangeRepository pChangeRepository;

@InjectMocks
UserService userService;

@Nested
@DisplayName("getUserHistory 테스트 - User 의 PChange 변화 내역을 조회 한다.")
class GetUserHistoryTest {

Season season;
List<PChange> pChanges;
@BeforeEach
void setUp() {
season = new Season();
ReflectionUtilsForUnitTest.setFieldWithReflection(season, "id", 1L);
pChanges = new ArrayList<>();
for (int i = 0; i < 5; i++) {
Game game = new Game(season, StatusType.END, Mode.RANK,
LocalDateTime.now().minusDays(i), LocalDateTime.now().minusDays(i).plusMinutes(15));
User user = new User("testId" + i, "testEmail" + i, "imageUri",
RacketType.DUAL, RoleType.ADMIN, 0, SnsType.SLACK, 111L);
PChange pChange = new PChange(game, user, 1111, true);
ReflectionUtilsForUnitTest.setFieldWithReflection(pChange, "id", (long) i);
pChanges.add(pChange);
}
when(pChangeRepository.findPChangesHistory(anyString(), anyLong())).thenReturn(pChanges);
}

@Test
@DisplayName("success - seasonId가 0일 때")
void seasonId_zero() {
when(seasonFindService.findCurrentSeason(any())).thenReturn(season);
UserHistoryResponseDto userHistory = userService.getUserHistory("testId", 0L);
assertEquals(5, userHistory.getHistorics().size());
Collections.reverse(pChanges);
for (int i = 0; i < 5; i++) {
assertEquals(pChanges.get(i).getGame().getStartTime(), userHistory.getHistorics().get(i).getDate());
}
}

@Test
@DisplayName("success - seasonId가 0이 아닐 때")
void seasonId_not_zero() {
when(seasonFindService.findSeasonById(anyLong())).thenReturn(season);
UserHistoryResponseDto userHistory = userService.getUserHistory("testId", 1L);
assertEquals(5, userHistory.getHistorics().size());
Collections.reverse(pChanges);
for (int i = 0; i < 5; i++) {
assertEquals(pChanges.get(i).getGame().getStartTime(), userHistory.getHistorics().get(i).getDate());
}
}
}
}
Loading