Skip to content

Commit

Permalink
✅ test: 기준 영양섭취량 추가로 인한 테스트 코드 수정 및 검증 완료 (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
synoti21 committed Nov 8, 2023
1 parent c91a645 commit 38bd92f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,9 @@ private ResponseNutritionSumByDateDto calculateNutritionSumAndRatio(Long userId,
double ratioProtein = Math.round((((double) totalProtein / (double) targetUser.getBaseNutrition().getProtein()) * 100.0) * 10.0) / 10.0;
double ratioFat = Math.round((((double) totalFat / (double) targetUser.getBaseNutrition().getFat()) * 100.0) * 10.0) / 10.0;

return ResponseNutritionSumByDateDto.of(userId, checkDate, nutritionSumType, totalKcal, totalCarbohydrate, totalProtein, totalFat, ratioKcal, ratioCarbohydrate, ratioProtein, ratioFat);
return ResponseNutritionSumByDateDto.of(userId, checkDate, nutritionSumType, totalKcal,
totalCarbohydrate, totalProtein, totalFat, ratioKcal,
ratioCarbohydrate, ratioProtein, ratioFat, targetUser.getBaseNutrition());
}

private void validateUser(Long userId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ void testGetNutritionSumByDate() throws Exception{
//Given
LocalDate date = LocalDate.now();
ResponseNutritionSumByDateDto responseNutritionSumByDateDto = ResponseNutritionSumByDateDto.of(testUserId,date,1
,500,100,50,50,0.2,0.3,0.4,0.5);
,500,100,50,50,0.2,0.3,0.4,0.5,
BaseNutrition.createNutrition(500,100,50,50));
ApiResponse<ResponseNutritionSumByDateDto> expectedResponse = ApiResponse.success(responseNutritionSumByDateDto,ResponseCode.FOOD_READ_SUCCESS.getMessage());
when(foodService.getNutritionSumByDate(any(Long.class),any(LocalDate.class))).thenReturn(responseNutritionSumByDateDto);

Expand All @@ -279,6 +280,7 @@ void testGetNutritionSumByDate() throws Exception{
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioCarbohydrate").value(expectedResponse.getData().getRatioCarbohydrate()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioProtein").value(expectedResponse.getData().getRatioProtein()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioFat").value(expectedResponse.getData().getRatioFat()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.baseNutrition.carbohydrate").value(expectedResponse.getData().getBaseNutrition().getCarbohydrate()))
.andExpect(MockMvcResultMatchers.jsonPath("$.msg").value(expectedResponse.getMsg()));
}

Expand All @@ -290,7 +292,8 @@ void testGetNutritionSumByWeek() throws Exception {
//Given
LocalDate date = LocalDate.now();
ResponseNutritionSumByDateDto responseNutritionSumByDateDto = ResponseNutritionSumByDateDto.of(testUserId, date, 7
, 500, 100, 50, 50, 0.2, 0.3, 0.4, 0.5);
, 500, 100, 50, 50, 0.2, 0.3, 0.4, 0.5,
BaseNutrition.createNutrition(500, 100, 50, 50));
ApiResponse<ResponseNutritionSumByDateDto> expectedResponse = ApiResponse.success(responseNutritionSumByDateDto, ResponseCode.FOOD_READ_SUCCESS.getMessage());
when(foodService.getNutritionSumByWeek(any(Long.class))).thenReturn(responseNutritionSumByDateDto);

Expand All @@ -312,6 +315,7 @@ void testGetNutritionSumByWeek() throws Exception {
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioCarbohydrate").value(expectedResponse.getData().getRatioCarbohydrate()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioProtein").value(expectedResponse.getData().getRatioProtein()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioFat").value(expectedResponse.getData().getRatioFat()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.baseNutrition.carbohydrate").value(expectedResponse.getData().getBaseNutrition().getCarbohydrate()))
.andExpect(MockMvcResultMatchers.jsonPath("$.msg").value(expectedResponse.getMsg()));
}

Expand All @@ -323,7 +327,8 @@ void testGetNutritionSumByMonth() throws Exception {
//Given
LocalDate date = LocalDate.now();
ResponseNutritionSumByDateDto responseNutritionSumByDateDto = ResponseNutritionSumByDateDto.of(testUserId, date, 30
, 500, 100, 50, 50, 0.2, 0.3, 0.4, 0.5);
, 500, 100, 50, 50, 0.2, 0.3, 0.4, 0.5,
BaseNutrition.createNutrition(500, 100, 50, 50));
ApiResponse<ResponseNutritionSumByDateDto> expectedResponse = ApiResponse.success(responseNutritionSumByDateDto, ResponseCode.FOOD_READ_SUCCESS.getMessage());
when(foodService.getNutritionSumByMonth(any(Long.class))).thenReturn(responseNutritionSumByDateDto);

Expand All @@ -345,6 +350,7 @@ void testGetNutritionSumByMonth() throws Exception {
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioCarbohydrate").value(expectedResponse.getData().getRatioCarbohydrate()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioProtein").value(expectedResponse.getData().getRatioProtein()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.ratioFat").value(expectedResponse.getData().getRatioFat()))
.andExpect(MockMvcResultMatchers.jsonPath("$.data.baseNutrition.carbohydrate").value(expectedResponse.getData().getBaseNutrition().getCarbohydrate()))
.andExpect(MockMvcResultMatchers.jsonPath("$.msg").value(expectedResponse.getMsg()));
}

Expand Down

0 comments on commit 38bd92f

Please sign in to comment.