11package com .back .domain .cocktail .controller ;
22
3+ import com .back .domain .cocktail .dto .CocktailSearchRequestDto ;
34import com .back .domain .cocktail .entity .Cocktail ;
45import com .back .domain .cocktail .enums .AlcoholBaseType ;
56import com .back .domain .cocktail .enums .AlcoholStrength ;
67import com .back .domain .cocktail .enums .CocktailType ;
78import com .back .domain .cocktail .repository .CocktailRepository ;
89import com .back .domain .user .service .UserService ;
910import com .back .global .rq .Rq ;
11+ import com .back .global .standard .util .Ut ;
1012import jakarta .servlet .http .HttpServletRequest ;
1113import jakarta .servlet .http .HttpServletResponse ;
1214import org .junit .jupiter .api .DisplayName ;
2729import java .time .LocalDateTime ;
2830
2931import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .get ;
32+ import static org .springframework .test .web .servlet .request .MockMvcRequestBuilders .post ;
3033import static org .springframework .test .web .servlet .result .MockMvcResultHandlers .print ;
3134import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .jsonPath ;
3235import static org .springframework .test .web .servlet .result .MockMvcResultMatchers .status ;
@@ -138,6 +141,47 @@ void t4() throws Exception {
138141 .andExpect (jsonPath ("$.data" ).isArray ());
139142 }
140143
144+ @ Test
145+ @ DisplayName ("칵테일 검색 및 필터링" )
146+ void t5 () throws Exception {
147+ // given: DB에 칵테일 저장
148+ Cocktail savedCocktail = cocktailRepository .save (
149+ Cocktail .builder ()
150+ .cocktailName ("모히토" )
151+ .alcoholStrength (AlcoholStrength .WEAK )
152+ .cocktailType (CocktailType .SHORT )
153+ .alcoholBaseType (AlcoholBaseType .RUM )
154+ .cocktailImgUrl ("https://example.com/image.jpg" )
155+ .cocktailStory ("상쾌한 라임과 민트" )
156+ .ingredient ("라임, 민트, 럼, 설탕, 탄산수" )
157+ .recipe ("라임과 민트를 섞고 럼을 넣고 탄산수로 완성" )
158+ .createdAt (LocalDateTime .now ())
159+ .updatedAt (LocalDateTime .now ())
160+ .build ()
161+ );
162+
163+ // 검색 조건 (키워드: "모히토")
164+ CocktailSearchRequestDto requestDto = new CocktailSearchRequestDto ();
165+ requestDto .setKeyword ("모히토" );
166+
167+ // when: POST 요청
168+ ResultActions resultActions = mvc .perform (
169+ post ("/cocktails/search" )
170+ .contentType (MediaType .APPLICATION_JSON )
171+ .content (Ut .json .toString (requestDto ))
172+ ).andDo (print ());
173+
174+ // then: 상태코드, JSON 구조 검증
175+ resultActions
176+ .andExpect (status ().isOk ())
177+ .andExpect (jsonPath ("$.code" ).value (200 ))
178+ .andExpect (jsonPath ("$.message" ).value ("success" ))
179+ .andExpect (jsonPath ("$.data[0].cocktailName" ).value ("모히토" ))
180+ .andExpect (jsonPath ("$.data[0].alcoholStrength" ).value ("WEAK" ))
181+ .andExpect (jsonPath ("$.data[0].cocktailType" ).value ("SHORT" ))
182+ .andExpect (jsonPath ("$.data[0].alcoholBaseType" ).value ("RUM" ));
183+ }
184+
141185 @ TestConfiguration
142186 static class TestConfig {
143187 @ Bean
@@ -149,5 +193,4 @@ public Rq rq() {
149193 return new Rq (req , resp , userService );
150194 }
151195 }
152-
153196}
0 commit comments