Skip to content

Commit

Permalink
fix: 난이도별 통계 api url 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyun0828 committed Nov 30, 2024
1 parent 24cb8b5 commit 6bf1168
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ApiResponse<List<StatisticsResponseDto.GetStatisticsDto>> getFilterStatis
return ApiResponse.of(SuccessStatus.GET_STATISTICS, statisticsCheckService.getUserStatistics(accessToken));
}

@GetMapping("/statistics")
@GetMapping("/statistics/levels")
@Operation(summary = "난이도 별 통계 데이터 불러오기 react -> spring", description = "통계 데이터 가져오기")
public ApiResponse<List<StatisticsResponseDto.GetStatisticsDto>> getFilterStatistics(
@RequestHeader("Authorization") final String authorizationHeader,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void saveStatistics() throws Exception {
@DisplayName("통계 데이터 가져오기")
@Test
@WithMockUser(value = "[email protected]", roles = {"USER"})
void getFilterStatistics() throws Exception {
void getStatistics() throws Exception {
// given
String accessToken = "mockAccessToken";
given(jwtService.createAccessToken("[email protected]")).willReturn(accessToken);
Expand Down Expand Up @@ -102,6 +102,41 @@ void getFilterStatistics() throws Exception {
.andExpect(content().json(expectedJson));
}

@DisplayName("난이도 별 통계 데이터 가져오기")
@Test
@WithMockUser(value = "[email protected]", roles = {"USER"})
void getStatisticsByLevel() throws Exception {
// given
String accessToken = "mockAccessToken";
Long level = 1L;
given(jwtService.createAccessToken("[email protected]")).willReturn(accessToken);

List<GetStatisticsDto> getStatisticsDtos = createGetStatisticsDtos();

// when
given(statisticsCheckService.getUserStatisticsByLevel(accessToken, level)).willReturn(getStatisticsDtos);

// then
String expectedJson = """
{
"isSuccess": true,
"code": "STATISTICS2001",
"message": "유저 통계 데이터 가져오기 성공",
"result":[{"day":"2024-11-11","gantourCount":1,"silentTime":5.0},{"day":"2024-11-12","gantourCount":2,"silentTime":7.2}]
}
""";

mockMvc.perform(get("/api/spring/statistics/levels")
.with(csrf())
.param("level", String.valueOf(level))
.header("Authorization", "Bearer " + accessToken)
.contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.isSuccess").value(true))
.andExpect(jsonPath("$.code").value("STATISTICS2001"))
.andExpect(jsonPath("$.message").value("유저 통계 데이터 가져오기 성공"))
.andExpect(content().json(expectedJson));
}

private List<GetStatisticsDto> createGetStatisticsDtos() {
return List.of(
GetStatisticsDto.builder()
Expand Down

0 comments on commit 6bf1168

Please sign in to comment.