-
Notifications
You must be signed in to change notification settings - Fork 9
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
kokomong2
wants to merge
2
commits into
dev
from
474-bug-pchange-히스토리-조회-시-game-시간-기준이-아닌-게임-점수-입력-시간-조회
The head ref may contain hidden characters: "474-bug-pchange-\uD788\uC2A4\uD1A0\uB9AC-\uC870\uD68C-\uC2DC-game-\uC2DC\uAC04-\uAE30\uC900\uC774-\uC544\uB2CC-\uAC8C\uC784-\uC810\uC218-\uC785\uB825-\uC2DC\uAC04-\uC870\uD68C"
Closed
Changes from all commits
Commits
Show all changes
2 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
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
92 changes: 92 additions & 0 deletions
92
gg-pingpong-api/src/test/java/gg/pingpong/api/user/user/service/UserServiceTest.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,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()); | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.
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.
pchange 가져오는 쿼리가 fetch join 으로 안되어있던데, 추가 쿼리 발생안하나요?
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.
확인 결과 추가 쿼리가 많이 발생하여 해당 쿼리문에서 Game을 fetch join으로 수정할까하는데 괜찮을까요?
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.
넵 하는게 좋을것 같습니다!