Skip to content

Commit

Permalink
✅ test: parameter 변경에 따른 테스트 코드 수정 (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
synoti21 committed Nov 16, 2023
1 parent d269a24 commit 6d6e59d
Showing 1 changed file with 31 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.cglib.core.Local;
import org.springframework.http.MediaType;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
Expand Down Expand Up @@ -270,7 +271,7 @@ void testDeleteFavoriteFood() throws Exception {
@WithMockUser("test")
void testGetNutritionSumByDate() throws Exception{
//Given
LocalDate date = LocalDate.now();
LocalDate date = LocalDate.of(2021,10,10);
ResponseNutritionSumByDateDto responseNutritionSumByDateDto = ResponseNutritionSumByDateDto.of(testUserId,date,1
,500,100,50,50,0.2,0.3,0.4,0.5,
BaseNutrition.createNutrition(500,100,50,50));
Expand Down Expand Up @@ -308,7 +309,7 @@ void testGetNutritionSumByDate() throws Exception{
@WithMockUser("test")
void testGetNutritionSumByWeek() throws Exception {
//Given
LocalDate date = LocalDate.now();
LocalDate date = LocalDate.of(2021, 10, 10);
ResponseNutritionSumByDateDto responseNutritionSumByDateDto = ResponseNutritionSumByDateDto.of(testUserId, date, 7
, 500, 100, 50, 50, 0.2, 0.3, 0.4, 0.5,
BaseNutrition.createNutrition(500, 100, 50, 50));
Expand All @@ -318,7 +319,10 @@ void testGetNutritionSumByWeek() throws Exception {

//When
mockMvc.perform(MockMvcRequestBuilders
.get("/api/food/{userId}/nutrition/recentWeek", testUserId))
.get("/api/food/{userId}/nutrition/recentWeek", testUserId)
.param("yy", String.valueOf(date.getYear()))
.param("mm", String.valueOf(date.getMonthValue()))
.param("dd", String.valueOf(date.getDayOfMonth())))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.header.code").value(expectedResponse.getHeader().getCode()))
.andExpect(MockMvcResultMatchers.jsonPath("$.header.message").value(expectedResponse.getHeader().getMessage()))
Expand All @@ -343,7 +347,7 @@ void testGetNutritionSumByWeek() throws Exception {
@WithMockUser("test")
void testGetNutritionSumByMonth() throws Exception {
//Given
LocalDate date = LocalDate.now();
LocalDate date = LocalDate.of(2021, 10, 10);
ResponseNutritionSumByDateDto responseNutritionSumByDateDto = ResponseNutritionSumByDateDto.of(testUserId, date, 30
, 500, 100, 50, 50, 0.2, 0.3, 0.4, 0.5,
BaseNutrition.createNutrition(500, 100, 50, 50));
Expand All @@ -353,7 +357,10 @@ void testGetNutritionSumByMonth() throws Exception {

//When
mockMvc.perform(MockMvcRequestBuilders
.get("/api/food/{userId}/nutrition/recentMonth", testUserId))
.get("/api/food/{userId}/nutrition/recentMonth", testUserId )
.param("yy", String.valueOf(date.getYear()))
.param("mm", String.valueOf(date.getMonthValue()))
.param("dd", String.valueOf(date.getDayOfMonth())))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.header.code").value(expectedResponse.getHeader().getCode()))
.andExpect(MockMvcResultMatchers.jsonPath("$.header.message").value(expectedResponse.getHeader().getMessage()))
Expand All @@ -378,12 +385,13 @@ void testGetNutritionSumByMonth() throws Exception {
@WithMockUser("test")
void testGetScoreOfUserWithBestAndWorstFoods() throws Exception{
//Given
ResponseSimpleFoodDto food1 = ResponseSimpleFoodDto.of("test1", 100, 100, 100, 100, LocalDate.now());
ResponseSimpleFoodDto food2 = ResponseSimpleFoodDto.of("test", 100, 100, 100, 100, LocalDate.now());
ResponseSimpleFoodDto food3 = ResponseSimpleFoodDto.of("test", 100, 100, 100, 100, LocalDate.now());
ResponseSimpleFoodDto food4 = ResponseSimpleFoodDto.of("test4", 100, 100, 100, 100, LocalDate.now());
ResponseSimpleFoodDto food5 = ResponseSimpleFoodDto.of("test", 100, 100, 100, 100, LocalDate.now());
ResponseSimpleFoodDto food6 = ResponseSimpleFoodDto.of("test", 100, 100, 100, 100, LocalDate.now());
LocalDate date = LocalDate.of(2021, 10, 10);
ResponseSimpleFoodDto food1 = ResponseSimpleFoodDto.of("test1", 100, 100, 100, 100, date);
ResponseSimpleFoodDto food2 = ResponseSimpleFoodDto.of("test", 100, 100, 100, 100, date);
ResponseSimpleFoodDto food3 = ResponseSimpleFoodDto.of("test", 100, 100, 100, 100, date);
ResponseSimpleFoodDto food4 = ResponseSimpleFoodDto.of("test4", 100, 100, 100, 100, date);
ResponseSimpleFoodDto food5 = ResponseSimpleFoodDto.of("test", 100, 100, 100, 100, date);
ResponseSimpleFoodDto food6 = ResponseSimpleFoodDto.of("test", 100, 100, 100, 100, date);

ResponseScoreBestWorstDto responseScoreBestWorstDto = ResponseScoreBestWorstDto.of(testUserId, 100, 80
, 60, 240, List.of(food1, food2,food3), List.of(food4, food5, food6));
Expand All @@ -393,7 +401,10 @@ void testGetScoreOfUserWithBestAndWorstFoods() throws Exception{

//When
mockMvc.perform(MockMvcRequestBuilders
.get("/api/food/{userId}/score", testUserId))
.get("/api/food/{userId}/score", testUserId, date.getYear(), date.getMonthValue(), date.getDayOfMonth())
.param("yy", String.valueOf(date.getYear()))
.param("mm", String.valueOf(date.getMonthValue()))
.param("dd", String.valueOf(date.getDayOfMonth())))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.header.code").value(expectedResponse.getHeader().getCode()))
.andExpect(MockMvcResultMatchers.jsonPath("$.header.message").value(expectedResponse.getHeader().getMessage()))
Expand Down Expand Up @@ -422,7 +433,10 @@ void testGetAnalysisOfUser() throws Exception {

//When
mockMvc.perform(MockMvcRequestBuilders
.get("/api/food/{userId}/analysis", testUserId))
.get("/api/food/{userId}/analysis", testUserId)
.param("yy", String.valueOf(2021))
.param("mm", String.valueOf(10))
.param("dd", String.valueOf(10)))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.header.code").value(expectedResponse.getHeader().getCode()))
.andExpect(MockMvcResultMatchers.jsonPath("$.header.message").value(expectedResponse.getHeader().getMessage()))
Expand Down Expand Up @@ -454,7 +468,10 @@ void testGetUserRankByWeek() throws Exception{

//When
mockMvc.perform(MockMvcRequestBuilders
.get("/api/food/{userId}/rank", testUserId))
.get("/api/food/{userId}/rank", testUserId)
.param("yy", String.valueOf(2021))
.param("mm", String.valueOf(10))
.param("dd", String.valueOf(10)))
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(MockMvcResultMatchers.jsonPath("$.header.code").value(expectedResponse.getHeader().getCode()))
.andExpect(MockMvcResultMatchers.jsonPath("$.header.message").value(expectedResponse.getHeader().getMessage()))
Expand Down

0 comments on commit 6d6e59d

Please sign in to comment.