Skip to content

Commit

Permalink
refactor: 로그인 여부에 따른 꿀조합 랭킹 인수 테스트 분리
Browse files Browse the repository at this point in the history
  • Loading branch information
Go-Jaecheol committed Apr 19, 2024
1 parent 4717e9b commit d523759
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ class getSortingRecipes_성공_테스트 {
class getRankingRecipes_성공_테스트 {
@Test
void 전체_꿀조합들_중에서_랭킹_TOP4를_조회할_수_있다() {
void 로그인을_하지_않고_전체_꿀조합들_중에서_랭킹_TOP4를_조회할_수_있다() {
// given
final var 카테고리 = 카테고리_간편식사_생성();
단일_카테고리_저장(카테고리);
Expand All @@ -544,7 +544,31 @@ class getRankingRecipes_성공_테스트 {
// then
STATUS_CODE를_검증한다(응답, 정상_처리);
레시피_랭킹_조회_결과를_검증한다(응답, List.of(레시피4, 레시피2, 레시피3, 레시피1));
레시피_랭킹_조회_결과를_검증한다(응답, List.of(레시피4, 레시피2, 레시피3, 레시피1), List.of(false, false, false, false));
}
@Test
void 로그인_후_전체_꿀조합들_중에서_랭킹_TOP4를_조회할_수_있다() {
// given
final var 카테고리 = 카테고리_간편식사_생성();
단일_카테고리_저장(카테고리);
final var 상품 = 단일_상품_저장(상품_삼각김밥_가격1000원_평점5점_생성(카테고리));
레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지1), 레시피추가요청_생성(상품));
레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지2), 레시피추가요청_생성(상품));
레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지3), 레시피추가요청_생성(상품));
레시피_작성_요청(로그인_쿠키_획득(멤버1), 여러개_사진_명세_요청(이미지4), 레시피추가요청_생성(상품));
여러명이_레시피_좋아요_요청(List.of(멤버1), 레시피1, 좋아요O);
여러명이_레시피_좋아요_요청(List.of(멤버1, 멤버2), 레시피2, 좋아요O);
여러명이_레시피_좋아요_요청(List.of(멤버1, 멤버2), 레시피3, 좋아요O);
여러명이_레시피_좋아요_요청(List.of(멤버1, 멤버2, 멤버3), 레시피4, 좋아요O);
// when
final var 응답 = 레시피_랭킹_조회_요청(로그인_쿠키_획득(멤버2));
// then
STATUS_CODE를_검증한다(응답, 정상_처리);
레시피_랭킹_조회_결과를_검증한다(응답, List.of(레시피4, 레시피2, 레시피3, 레시피1), List.of(true, true, true, false));
}
}
Expand Down Expand Up @@ -768,12 +792,15 @@ class getRecipeComment_실패_테스트 {
});
}

private void 레시피_랭킹_조회_결과를_검증한다(final ExtractableResponse<Response> response, final List<Long> recipeIds) {
private void 레시피_랭킹_조회_결과를_검증한다(final ExtractableResponse<Response> response, final List<Long> recipeIds,
final List<Boolean> favorites) {
final var actual = response.jsonPath()
.getList("recipes", RankingRecipeDto.class);

assertThat(actual).extracting(RankingRecipeDto::getId)
.isEqualTo(recipeIds);
assertThat(actual).extracting(RankingRecipeDto::getFavorite)
.isEqualTo(favorites);
}

private void 레시피_검색_결과를_검증한다(final ExtractableResponse<Response> response, final boolean hasNext, final List<Long> recipeIds) {
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/funeat/acceptance/recipe/RecipeSteps.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ public class RecipeSteps {
.extract();
}

public static ExtractableResponse<Response> 레시피_랭킹_조회_요청(final String loginCookie) {
return given()
.cookie("SESSION", loginCookie)
.when()
.get("/api/ranks/recipes")
.then()
.extract();
}

public static ExtractableResponse<Response> 레시피_검색_결과_조회_요청(final String query, final Long lastRecipeId) {
return given()
.queryParam("query", query)
Expand Down

0 comments on commit d523759

Please sign in to comment.