File tree Expand file tree Collapse file tree
main/kotlin/team/nongchun/hororog/domain/meal
test/kotlin/team/nongchun/hororog/domain/meal/controller Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -120,6 +120,6 @@ class MealController(
120120 )
121121 @PostMapping
122122 fun createAiMeal (
123- @RequestBody request : CreateAiMealRequest ,
123+ @Valid @ RequestBody request : CreateAiMealRequest ,
124124 ): ResponseEntity <Any > = ResponseEntity .ok(mapOf (" id" to createAiMealService.execute(request)))
125125}
Original file line number Diff line number Diff line change 11package team.nongchun.hororog.domain.meal.dto
22
33import com.fasterxml.jackson.annotation.JsonProperty
4+ import jakarta.validation.constraints.DecimalMin
5+ import jakarta.validation.constraints.NotBlank
46
57data class CreateAiMealRequest (
68 @JsonProperty(" diet_id" )
79 val dietId : Long ,
810 @JsonProperty(" menu_name" )
11+ @field:NotBlank
912 val menuName : String ,
13+ @field:DecimalMin("0.0")
1014 val kcal : Double ,
15+ @field:DecimalMin("0.0")
1116 val protein : Double ,
17+ @field:DecimalMin("0.0")
1218 val fat : Double ,
19+ @field:DecimalMin("0.0")
1320 val sodium : Double ,
1421)
Original file line number Diff line number Diff line change @@ -176,4 +176,52 @@ class MealControllerTest
176176 status { isForbidden() }
177177 }
178178 }
179+
180+ @Test
181+ fun `AI 급식 콜백의 메뉴명이 비어 있으면 400을 반환한다` () {
182+ val nutritionist = saveMember(Role .NUTRITIONIST , " nutritionist@hororog.team" )
183+
184+ mockMvc
185+ .post(" /meals" ) {
186+ header(HttpHeaders .AUTHORIZATION , " Bearer ${accessToken(nutritionist)} " )
187+ contentType = MediaType .APPLICATION_JSON
188+ content =
189+ """
190+ {
191+ "diet_id": 1,
192+ "menu_name": "",
193+ "kcal": 100.0,
194+ "protein": 10.0,
195+ "fat": 5.0,
196+ "sodium": 300.0
197+ }
198+ """ .trimIndent()
199+ }.andExpect {
200+ status { isBadRequest() }
201+ }
202+ }
203+
204+ @Test
205+ fun `AI 급식 콜백의 영양값이 음수이면 400을 반환한다` () {
206+ val nutritionist = saveMember(Role .NUTRITIONIST , " nutritionist@hororog.team" )
207+
208+ mockMvc
209+ .post(" /meals" ) {
210+ header(HttpHeaders .AUTHORIZATION , " Bearer ${accessToken(nutritionist)} " )
211+ contentType = MediaType .APPLICATION_JSON
212+ content =
213+ """
214+ {
215+ "diet_id": 1,
216+ "menu_name": "현미밥",
217+ "kcal": -1.0,
218+ "protein": 10.0,
219+ "fat": 5.0,
220+ "sodium": 300.0
221+ }
222+ """ .trimIndent()
223+ }.andExpect {
224+ status { isBadRequest() }
225+ }
226+ }
179227 }
You can’t perform that action at this time.
0 commit comments