Skip to content

Commit

Permalink
식품 목록 조회 API 응답 형식 수정 (#33)
Browse files Browse the repository at this point in the history
* refactor: json 프로퍼티명 수정

* test: 직렬화 여부 확인
  • Loading branch information
kyY00n authored Jul 18, 2023
1 parent 46284aa commit 59a1e4d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<PetFoodResponse> petFoods) {
public record GetPetFoodsResponse(@JsonProperty(value = "foodList") List<PetFoodResponse> petFoods) {

public static GetPetFoodsResponse from(List<PetFood> petFoods) {
List<PetFoodResponse> petFoodResponses = petFoods.stream()
Expand Down
15 changes: 15 additions & 0 deletions backend/src/test/java/zipgo/acceptance/PetFoodAcceptanceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -23,6 +25,19 @@ public class PetFoodAcceptanceTest extends AcceptanceTest {
assertThat(data.petFoods()).isNotEmpty();
}

@Test
void petFoods_foodList_직렬화한다() {
//given
ExtractableResponse<Response> response = given().contentType(ContentType.JSON)
.when().get("/pet-foods")
.then().extract();

//when
//then
List<PetFoodResponse> foodList = response.jsonPath().getList("foodList", PetFoodResponse.class);
assertThat(foodList).isNotEmpty();
}

@Test
void 키워드가_다이어트인_식품_조회_API() {
ExtractableResponse<Response> response = given().contentType(ContentType.JSON)
Expand Down

0 comments on commit 59a1e4d

Please sign in to comment.