Skip to content

Commit

Permalink
test: 꿀조합 검색 결과 검증 테스트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Go-Jaecheol committed Jan 20, 2024
1 parent 9b38ad5 commit f1f94a0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,16 @@
import static com.funeat.fixture.ProductFixture.상품_애플망고_가격3000원_평점5점_생성;
import static com.funeat.fixture.RecipeFixture.레시피;
import static com.funeat.fixture.RecipeFixture.레시피1;
import static com.funeat.fixture.RecipeFixture.레시피10;
import static com.funeat.fixture.RecipeFixture.레시피11;
import static com.funeat.fixture.RecipeFixture.레시피2;
import static com.funeat.fixture.RecipeFixture.레시피3;
import static com.funeat.fixture.RecipeFixture.레시피4;
import static com.funeat.fixture.RecipeFixture.레시피5;
import static com.funeat.fixture.RecipeFixture.레시피6;
import static com.funeat.fixture.RecipeFixture.레시피7;
import static com.funeat.fixture.RecipeFixture.레시피8;
import static com.funeat.fixture.RecipeFixture.레시피9;
import static com.funeat.fixture.RecipeFixture.레시피_본문;
import static com.funeat.fixture.RecipeFixture.레시피_제목;
import static com.funeat.fixture.RecipeFixture.레시피좋아요요청_생성;
Expand Down Expand Up @@ -389,7 +396,7 @@ class getSearchResults_성공_테스트 {

// then
STATUS_CODE를_검증한다(응답, 정상_처리);
레시피_검색_결과를_검증한다(응답, List.of(레시피3, 레시피2));
레시피_검색_결과를_검증한다(응답, false, List.of(레시피3, 레시피2));
}

@Test
Expand All @@ -407,7 +414,7 @@ class getSearchResults_성공_테스트 {

// then
STATUS_CODE를_검증한다(응답, 정상_처리);
레시피_검색_결과를_검증한다(응답, List.of(레시피));
레시피_검색_결과를_검증한다(응답, false, List.of(레시피));
}

@Test
Expand All @@ -424,7 +431,23 @@ class getSearchResults_성공_테스트 {

// then
STATUS_CODE를_검증한다(응답, 정상_처리);
레시피_검색_결과를_검증한다(응답, Collections.emptyList());
레시피_검색_결과를_검증한다(응답, false, Collections.emptyList());
}

@Test
void 검색_결과가_10개_이상일_때_해당_페이지_레시피_10개만_반환한다() {
// given
final var 카테고리 = 카테고리_간편식사_생성();
단일_카테고리_저장(카테고리);
final var 상품1 = 단일_상품_저장(상품_망고빙수_가격5000원_평점4점_생성(카테고리));
반복_레시피_작성_요청(11, 상품1);

// when
final var 응답 = 레시피_검색_결과_조회_요청("망고", 0L);

// then
STATUS_CODE를_검증한다(응답, 정상_처리);
레시피_검색_결과를_검증한다(응답, true, List.of(레시피11, 레시피10, 레시피9, 레시피8, 레시피7, 레시피6, 레시피5, 레시피4, 레시피3, 레시피2));
}
}

Expand Down Expand Up @@ -761,11 +784,14 @@ class getRecipeComment_실패_테스트 {
.isEqualTo(recipeIds);
}

private void 레시피_검색_결과를_검증한다(final ExtractableResponse<Response> response, final List<Long> recipeIds) {
final var actual = response.jsonPath()
private void 레시피_검색_결과를_검증한다(final ExtractableResponse<Response> response, final boolean hasNext, final List<Long> recipeIds) {
final var actualHasNext = response.jsonPath()
.getBoolean("hasNext");
final var actualRecipes = response.jsonPath()
.getList("recipes", SearchRecipeResultDto.class);

assertThat(actual).extracting(SearchRecipeResultDto::getId)
assertThat(actualHasNext).isEqualTo(hasNext);
assertThat(actualRecipes).extracting(SearchRecipeResultDto::getId)
.containsExactlyElementsOf(recipeIds);
}

Expand Down Expand Up @@ -794,4 +820,10 @@ class getRecipeComment_실패_테스트 {
assertThat(actualComments).hasSize(expectedSize);
assertThat(actualHasNext).isEqualTo(expectedHasNext);
}

private void 반복_레시피_작성_요청(final int repeat, final Long productId) {
for (int i = 0; i < repeat; i++) {
레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(productId));
}
}
}
7 changes: 7 additions & 0 deletions src/test/java/com/funeat/fixture/RecipeFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ public class RecipeFixture {
public static final Long 레시피2 = 2L;
public static final Long 레시피3 = 3L;
public static final Long 레시피4 = 4L;
public static final Long 레시피5 = 5L;
public static final Long 레시피6 = 6L;
public static final Long 레시피7 = 7L;
public static final Long 레시피8 = 8L;
public static final Long 레시피9 = 9L;
public static final Long 레시피10 = 10L;
public static final Long 레시피11 = 11L;

public static final boolean 좋아요O = true;
public static final boolean 좋아요X = false;
Expand Down

0 comments on commit f1f94a0

Please sign in to comment.