From 38bd92fb1ed124fbd2c35f6972ccb2384c0daec2 Mon Sep 17 00:00:00 2001 From: Ahn Jiwan Date: Wed, 8 Nov 2023 23:36:43 +0900 Subject: [PATCH] =?UTF-8?q?:white=5Fcheck=5Fmark:=20test:=20=EA=B8=B0?= =?UTF-8?q?=EC=A4=80=20=EC=98=81=EC=96=91=EC=84=AD=EC=B7=A8=EB=9F=89=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20=EA=B2=80=EC=A6=9D=20=EC=99=84=EB=A3=8C=20(#60)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../diareat/diareat/food/service/FoodService.java | 4 +++- .../diareat/controller/FoodControllerTest.java | 12 +++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/diareat/diareat/food/service/FoodService.java b/src/main/java/com/diareat/diareat/food/service/FoodService.java index 824baed..9e9a315 100644 --- a/src/main/java/com/diareat/diareat/food/service/FoodService.java +++ b/src/main/java/com/diareat/diareat/food/service/FoodService.java @@ -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) { diff --git a/src/test/java/com/diareat/diareat/controller/FoodControllerTest.java b/src/test/java/com/diareat/diareat/controller/FoodControllerTest.java index c902b01..413d53f 100644 --- a/src/test/java/com/diareat/diareat/controller/FoodControllerTest.java +++ b/src/test/java/com/diareat/diareat/controller/FoodControllerTest.java @@ -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 expectedResponse = ApiResponse.success(responseNutritionSumByDateDto,ResponseCode.FOOD_READ_SUCCESS.getMessage()); when(foodService.getNutritionSumByDate(any(Long.class),any(LocalDate.class))).thenReturn(responseNutritionSumByDateDto); @@ -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())); } @@ -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 expectedResponse = ApiResponse.success(responseNutritionSumByDateDto, ResponseCode.FOOD_READ_SUCCESS.getMessage()); when(foodService.getNutritionSumByWeek(any(Long.class))).thenReturn(responseNutritionSumByDateDto); @@ -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())); } @@ -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 expectedResponse = ApiResponse.success(responseNutritionSumByDateDto, ResponseCode.FOOD_READ_SUCCESS.getMessage()); when(foodService.getNutritionSumByMonth(any(Long.class))).thenReturn(responseNutritionSumByDateDto); @@ -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())); }