From 59a1e4d39e0dd6a28a7c79162121b908b047a52c Mon Sep 17 00:00:00 2001 From: kyY00n Date: Tue, 18 Jul 2023 13:58:21 +0900 Subject: [PATCH] =?UTF-8?q?=EC=8B=9D=ED=92=88=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20API=20=EC=9D=91=EB=8B=B5=20=ED=98=95?= =?UTF-8?q?=EC=8B=9D=20=EC=88=98=EC=A0=95=20(#33)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: json 프로퍼티명 수정 * test: 직렬화 여부 확인 --- .../zipgo/controller/dto/GetPetFoodsResponse.java | 3 ++- .../zipgo/acceptance/PetFoodAcceptanceTest.java | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/zipgo/controller/dto/GetPetFoodsResponse.java b/backend/src/main/java/zipgo/controller/dto/GetPetFoodsResponse.java index e33086ac2..eb63d64d3 100644 --- a/backend/src/main/java/zipgo/controller/dto/GetPetFoodsResponse.java +++ b/backend/src/main/java/zipgo/controller/dto/GetPetFoodsResponse.java @@ -1,9 +1,10 @@ package zipgo.controller.dto; +import com.fasterxml.jackson.annotation.JsonProperty; import java.util.List; import zipgo.domain.PetFood; -public record GetPetFoodsResponse(List petFoods) { +public record GetPetFoodsResponse(@JsonProperty(value = "foodList") List petFoods) { public static GetPetFoodsResponse from(List petFoods) { List petFoodResponses = petFoods.stream() diff --git a/backend/src/test/java/zipgo/acceptance/PetFoodAcceptanceTest.java b/backend/src/test/java/zipgo/acceptance/PetFoodAcceptanceTest.java index f7d7fe616..1daa9c515 100644 --- a/backend/src/test/java/zipgo/acceptance/PetFoodAcceptanceTest.java +++ b/backend/src/test/java/zipgo/acceptance/PetFoodAcceptanceTest.java @@ -6,8 +6,10 @@ import io.restassured.http.ContentType; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; +import java.util.List; import org.junit.jupiter.api.Test; import zipgo.controller.dto.GetPetFoodsResponse; +import zipgo.controller.dto.PetFoodResponse; public class PetFoodAcceptanceTest extends AcceptanceTest { @@ -23,6 +25,19 @@ public class PetFoodAcceptanceTest extends AcceptanceTest { assertThat(data.petFoods()).isNotEmpty(); } + @Test + void petFoods를_foodList로_직렬화한다() { + //given + ExtractableResponse response = given().contentType(ContentType.JSON) + .when().get("/pet-foods") + .then().extract(); + + //when + //then + List foodList = response.jsonPath().getList("foodList", PetFoodResponse.class); + assertThat(foodList).isNotEmpty(); + } + @Test void 키워드가_다이어트인_식품_조회_API() { ExtractableResponse response = given().contentType(ContentType.JSON)