Skip to content

Commit

Permalink
✅ feat: 날짜별 영양소 합 테스트 코드 작성 (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
synoti21 committed Oct 4, 2023
1 parent 81c437a commit bd5c2b9
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion src/test/java/com/diareat/diareat/service/FoodServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ void testSaveAndGetFavoriteFood() {
//when
Long favoriteFoodId = foodService.saveFavoriteFood(CreateFavoriteFoodDto.of(foodId, userId, "testFood", testBaseNutrition));

List<ResponseFavoriteFoodDto> responseFavoriteFoodDtoList = foodService.getFavoriteFoodByUserId(userId);
List<ResponseFavoriteFoodDto> responseFavoriteFoodDtoList = foodService.getFavoriteFoodList(userId);

assertNotNull(responseFavoriteFoodDtoList);
assertEquals("testFood",responseFavoriteFoodDtoList.get(0).getName());
Expand Down Expand Up @@ -157,4 +157,28 @@ void testDeleteFavoriteFood() {

assertNull(favoriteFoodRepository.findById(favoriteFoodId).orElse(null));
}

@Test
void testNutritionSumByDate(){
//given
BaseNutrition testFoodNutrition = BaseNutrition.createNutrition(100,150,200,250);
Long userId = userService.saveUser(CreateUserDto.of("testUser", "testPassword",1, 180, 80, 18));
Long foodId = foodService.saveFood(CreateFoodDto.of(userId,"testFood", testFoodNutrition));
Food food = foodRepository.getReferenceById(foodId);

//when
ResponseNutritionSumByDateDto responseNutritionSumByDateDto = foodService.getNutritionSumByDate(userId,food.getDate());

assertNotNull(responseNutritionSumByDateDto);
assertEquals(100, responseNutritionSumByDateDto.getTotalKcal());
assertEquals(150, responseNutritionSumByDateDto.getTotalCarbohydrate());
assertEquals(200, responseNutritionSumByDateDto.getTotalProtein());
assertEquals(250, responseNutritionSumByDateDto.getTotalFat());

assertEquals(Math.round((100*1.0)/(2000*1.0))*10.0, responseNutritionSumByDateDto.getRatioKcal());
assertEquals(Math.round((150*1.0)/(300*1.0))*10.0, responseNutritionSumByDateDto.getRatioCarbohydrate());
assertEquals(Math.round((200*1.0)/(80*1.0))*10.0, responseNutritionSumByDateDto.getRatioProtein());
assertEquals(Math.round((250*1.0)/(80*1.0))*10.0, responseNutritionSumByDateDto.getRatioFat());

}
}

0 comments on commit bd5c2b9

Please sign in to comment.