diff --git a/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java b/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java index 32dcb85e2..932115005 100644 --- a/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java +++ b/backend/src/test/java/com/funeat/acceptance/common/CommonSteps.java @@ -74,4 +74,10 @@ public class CommonSteps { assertThat(actual).usingRecursiveComparison() .isEqualTo(expected); } + + public static void 다음_데이터가_있는지_검증한다(final ExtractableResponse response, final boolean expected) { + final var actual = response.jsonPath().getBoolean("hasNextReview"); + + assertThat(actual).isEqualTo(expected); + } } diff --git a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java index 07552c34c..b9a4c9110 100644 --- a/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java +++ b/backend/src/test/java/com/funeat/acceptance/review/ReviewAcceptanceTest.java @@ -2,6 +2,7 @@ import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키_획득; import static com.funeat.acceptance.common.CommonSteps.STATUS_CODE를_검증한다; +import static com.funeat.acceptance.common.CommonSteps.다음_데이터가_있는지_검증한다; import static com.funeat.acceptance.common.CommonSteps.사진_명세_요청; import static com.funeat.acceptance.common.CommonSteps.인증되지_않음; import static com.funeat.acceptance.common.CommonSteps.잘못된_요청; @@ -9,7 +10,6 @@ import static com.funeat.acceptance.common.CommonSteps.정상_처리; import static com.funeat.acceptance.common.CommonSteps.정상_처리_NO_CONTENT; import static com.funeat.acceptance.common.CommonSteps.찾을수_없음; -import static com.funeat.acceptance.common.CommonSteps.페이지를_검증한다; import static com.funeat.acceptance.product.ProductSteps.상품_상세_조회_요청; import static com.funeat.acceptance.review.ReviewSteps.리뷰_랭킹_조회_요청; import static com.funeat.acceptance.review.ReviewSteps.리뷰_작성_요청; @@ -28,19 +28,14 @@ import static com.funeat.fixture.MemberFixture.멤버2; import static com.funeat.fixture.MemberFixture.멤버3; import static com.funeat.fixture.PageFixture.FIRST_PAGE; -import static com.funeat.fixture.PageFixture.PAGE_SIZE; -import static com.funeat.fixture.PageFixture.마지막페이지O; -import static com.funeat.fixture.PageFixture.응답_페이지_생성; import static com.funeat.fixture.PageFixture.좋아요수_내림차순; -import static com.funeat.fixture.PageFixture.첫페이지O; -import static com.funeat.fixture.PageFixture.총_데이터_개수; -import static com.funeat.fixture.PageFixture.총_페이지; import static com.funeat.fixture.PageFixture.최신순; import static com.funeat.fixture.PageFixture.평점_내림차순; import static com.funeat.fixture.PageFixture.평점_오름차순; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격1000원_평점3점_생성; import static com.funeat.fixture.ProductFixture.상품_삼각김밥_가격2000원_평점3점_생성; import static com.funeat.fixture.ProductFixture.존재하지_않는_상품; +import static com.funeat.fixture.ReviewFixture.다음_데이터_존재X; import static com.funeat.fixture.ReviewFixture.리뷰; import static com.funeat.fixture.ReviewFixture.리뷰1; import static com.funeat.fixture.ReviewFixture.리뷰2; @@ -54,6 +49,7 @@ import static com.funeat.fixture.ReviewFixture.존재하지_않는_리뷰; import static com.funeat.fixture.ReviewFixture.좋아요O; import static com.funeat.fixture.ReviewFixture.좋아요X; +import static com.funeat.fixture.ReviewFixture.첫_목록을_가져옴; import static com.funeat.fixture.ScoreFixture.점수_1점; import static com.funeat.fixture.ScoreFixture.점수_2점; import static com.funeat.fixture.ScoreFixture.점수_3점; @@ -384,14 +380,12 @@ class 좋아요_기준_내림차순으로_리뷰_목록_조회 { 여러명이_리뷰_좋아요_요청(List.of(멤버1), 상품, 리뷰3, 좋아요O); 여러명이_리뷰_좋아요_요청(List.of(멤버2, 멤버3), 상품, 리뷰2, 좋아요O); - final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); - // when - final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 좋아요수_내림차순, FIRST_PAGE); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 첫_목록을_가져옴, 좋아요수_내림차순, FIRST_PAGE); // then STATUS_CODE를_검증한다(응답, 정상_처리); - 페이지를_검증한다(응답, 예상_응답_페이지); + 다음_데이터가_있는지_검증한다(응답, 다음_데이터_존재X); 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰2, 리뷰3, 리뷰1)); } @@ -407,14 +401,12 @@ class 좋아요_기준_내림차순으로_리뷰_목록_조회 { 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); - final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); - // when - final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 좋아요수_내림차순, FIRST_PAGE); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 첫_목록을_가져옴, 좋아요수_내림차순, FIRST_PAGE); // then STATUS_CODE를_검증한다(응답, 정상_처리); - 페이지를_검증한다(응답, 예상_응답_페이지); + 다음_데이터가_있는지_검증한다(응답, 다음_데이터_존재X); 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰3, 리뷰2, 리뷰1)); } } @@ -434,14 +426,12 @@ class 평점_기준_오름차순으로_리뷰_목록을_조회 { 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); - final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); - // when - final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 평점_오름차순, FIRST_PAGE); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 첫_목록을_가져옴, 평점_오름차순, FIRST_PAGE); // then STATUS_CODE를_검증한다(응답, 정상_처리); - 페이지를_검증한다(응답, 예상_응답_페이지); + 다음_데이터가_있는지_검증한다(응답, 다음_데이터_존재X); 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰1, 리뷰3, 리뷰2)); } @@ -457,14 +447,12 @@ class 평점_기준_오름차순으로_리뷰_목록을_조회 { 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_3점, List.of(태그))); 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); - final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); - // when - final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 평점_오름차순, FIRST_PAGE); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 첫_목록을_가져옴, 평점_오름차순, FIRST_PAGE); // then STATUS_CODE를_검증한다(응답, 정상_처리); - 페이지를_검증한다(응답, 예상_응답_페이지); + 다음_데이터가_있는지_검증한다(응답, 다음_데이터_존재X); 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰3, 리뷰2, 리뷰1)); } } @@ -484,14 +472,12 @@ class 평점_기준_내림차순으로_리뷰_목록_조회 { 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); - final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); - // when - final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 평점_내림차순, FIRST_PAGE); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 첫_목록을_가져옴, 평점_내림차순, FIRST_PAGE); // then STATUS_CODE를_검증한다(응답, 정상_처리); - 페이지를_검증한다(응답, 예상_응답_페이지); + 다음_데이터가_있는지_검증한다(응답, 다음_데이터_존재X); 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰2, 리뷰3, 리뷰1)); } @@ -507,14 +493,12 @@ class 평점_기준_내림차순으로_리뷰_목록_조회 { 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_3점, List.of(태그))); 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); - final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); - // when - final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 평점_내림차순, FIRST_PAGE); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 첫_목록을_가져옴, 평점_내림차순, FIRST_PAGE); // then STATUS_CODE를_검증한다(응답, 정상_처리); - 페이지를_검증한다(응답, 예상_응답_페이지); + 다음_데이터가_있는지_검증한다(응답, 다음_데이터_존재X); 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰3, 리뷰2, 리뷰1)); } } @@ -534,14 +518,12 @@ class 최신순으로_리뷰_목록을_조회 { 리뷰_작성_요청(로그인_쿠키_획득(멤버2), 상품, 사진_명세_요청(이미지2), 리뷰추가요청_재구매O_생성(점수_4점, List.of(태그))); 리뷰_작성_요청(로그인_쿠키_획득(멤버3), 상품, 사진_명세_요청(이미지3), 리뷰추가요청_재구매X_생성(점수_3점, List.of(태그))); - final var 예상_응답_페이지 = 응답_페이지_생성(총_데이터_개수(3L), 총_페이지(1L), 첫페이지O, 마지막페이지O, FIRST_PAGE, PAGE_SIZE); - // when - final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 최신순, FIRST_PAGE); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 상품, 첫_목록을_가져옴, 최신순, FIRST_PAGE); // then STATUS_CODE를_검증한다(응답, 정상_처리); - 페이지를_검증한다(응답, 예상_응답_페이지); + 다음_데이터가_있는지_검증한다(응답, 다음_데이터_존재X); 정렬된_리뷰_목록_조회_결과를_검증한다(응답, List.of(리뷰3, 리뷰2, 리뷰1)); } } @@ -562,7 +544,7 @@ class getSortingReviews_실패_테스트 { 리뷰_작성_요청(로그인_쿠키_획득(멤버1), 상품, 사진_명세_요청(이미지1), 리뷰추가요청_재구매O_생성(점수_2점, List.of(태그))); // when - final var 응답 = 정렬된_리뷰_목록_조회_요청(cookie, 상품, 좋아요수_내림차순, FIRST_PAGE); + final var 응답 = 정렬된_리뷰_목록_조회_요청(cookie, 상품, 첫_목록을_가져옴, 좋아요수_내림차순, FIRST_PAGE); // then STATUS_CODE를_검증한다(응답, 인증되지_않음); @@ -573,7 +555,7 @@ class getSortingReviews_실패_테스트 { @Test void 존재하지_않는_상품의_리뷰_목록을_조회시_예외가_발생한다() { // given && when - final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 존재하지_않는_상품, 좋아요수_내림차순, FIRST_PAGE); + final var 응답 = 정렬된_리뷰_목록_조회_요청(로그인_쿠키_획득(멤버1), 존재하지_않는_상품, 첫_목록을_가져옴, 좋아요수_내림차순, FIRST_PAGE); // then STATUS_CODE를_검증한다(응답, 찾을수_없음); diff --git a/backend/src/test/java/com/funeat/acceptance/review/ReviewSteps.java b/backend/src/test/java/com/funeat/acceptance/review/ReviewSteps.java index d59d9eded..805b12a54 100644 --- a/backend/src/test/java/com/funeat/acceptance/review/ReviewSteps.java +++ b/backend/src/test/java/com/funeat/acceptance/review/ReviewSteps.java @@ -1,7 +1,6 @@ package com.funeat.acceptance.review; import static com.funeat.acceptance.auth.LoginSteps.로그인_쿠키_획득; -import static com.funeat.acceptance.common.CommonSteps.LOCATION_헤더에서_ID_추출; import static com.funeat.fixture.ReviewFixture.리뷰좋아요요청_생성; import static io.restassured.RestAssured.given; @@ -56,14 +55,16 @@ public class ReviewSteps { } public static ExtractableResponse 정렬된_리뷰_목록_조회_요청(final String loginCookie, final Long productId, + final Long lastReviewId, final String sort, final Long page) { return given() .cookie("FUNEAT", loginCookie) .queryParam("sort", sort) .queryParam("page", page) + .queryParam("lastReviewId", lastReviewId).log().all() .when() .get("/api/products/{product_id}/reviews", productId) - .then() + .then().log().all() .extract(); } diff --git a/backend/src/test/java/com/funeat/fixture/ReviewFixture.java b/backend/src/test/java/com/funeat/fixture/ReviewFixture.java index e27227d0c..d68a09b6b 100644 --- a/backend/src/test/java/com/funeat/fixture/ReviewFixture.java +++ b/backend/src/test/java/com/funeat/fixture/ReviewFixture.java @@ -27,6 +27,10 @@ public class ReviewFixture { public static final boolean 재구매O = true; public static final boolean 재구매X = false; + public static final Long 첫_목록을_가져옴 = 0L; + public static final boolean 다음_데이터_존재O = true; + public static final boolean 다음_데이터_존재X = false; + public static Review 리뷰_이미지test1_평점1점_재구매O_생성(final Member member, final Product product, final Long count) { return new Review(member, product, "test1", 1L, "test", true, count); } diff --git a/backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java b/backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java index 198fedf9f..c5beacc07 100644 --- a/backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java +++ b/backend/src/test/java/com/funeat/review/persistence/ReviewRepositoryTest.java @@ -93,7 +93,7 @@ class findSortingReviewsByFavoriteCountDesc_관련_성공_테스트 { final var page = 페이지요청_좋아요_내림차순_생성(0, 2); // when - final var actual = reviewRepository.findSortingReviewsByFavoriteCountDescFirstPage(product, page); + final var actual = reviewRepository.findSortingReviewsByFavoriteCountDescFirstPage(product, member, page); // then assertThat(actual).extracting(SortingReviewDto::getId) @@ -121,7 +121,7 @@ class findSortingReviewsByFavoriteCountDesc_관련_성공_테스트 { final var page = 페이지요청_좋아요_내림차순_생성(0, 2); // when - final var actual = reviewRepository.findSortingReviewsByFavoriteCountDesc(product, lastReviewId, page); + final var actual = reviewRepository.findSortingReviewsByFavoriteCountDesc(product, member, lastReviewId, page); // then assertThat(actual).extracting(SortingReviewDto::getId) @@ -153,7 +153,7 @@ class findSortingReviewsByCreatedAtDesc_관련_성공_테스트 { final var page = 페이지요청_최신순_생성(0, 2); // when - final var actual = reviewRepository.findSortingReviewsByCreatedAtDescFirstPage(product, page); + final var actual = reviewRepository.findSortingReviewsByCreatedAtDescFirstPage(product, member, page); // then assertThat(actual).extracting(SortingReviewDto::getId) @@ -181,7 +181,7 @@ class findSortingReviewsByCreatedAtDesc_관련_성공_테스트 { final var page = 페이지요청_최신순_생성(0, 2); // when - final var actual = reviewRepository.findSortingReviewsByCreatedAtDesc(product, lastReviewId, page); + final var actual = reviewRepository.findSortingReviewsByCreatedAtDesc(product, member, lastReviewId, page); // then assertThat(actual).extracting(SortingReviewDto::getId) @@ -212,7 +212,7 @@ class findSortingReviewsByRating_관련_성공_테스트 { final var page = 페이지요청_평점_오름차순_생성(0, 2); // when - final var actual = reviewRepository.findSortingReviewsByRatingFirstPage(product, page); + final var actual = reviewRepository.findSortingReviewsByRatingFirstPage(product, member, page); // then assertThat(actual).extracting(SortingReviewDto::getId) @@ -239,7 +239,7 @@ class findSortingReviewsByRating_관련_성공_테스트 { final var page = 페이지요청_평점_내림차순_생성(0, 2); // when - final var actual = reviewRepository.findSortingReviewsByRatingFirstPage(product, page); + final var actual = reviewRepository.findSortingReviewsByRatingFirstPage(product, member, page); // then assertThat(actual).extracting(SortingReviewDto::getId) @@ -267,7 +267,7 @@ class findSortingReviewsByRating_관련_성공_테스트 { final var page = 페이지요청_평점_오름차순_생성(0, 2); // when - final var actual = reviewRepository.findSortingRatingByRatingAsc(product, lastReviewId, page); + final var actual = reviewRepository.findSortingRatingByRatingAsc(product, member, lastReviewId, page); // then assertThat(actual).extracting(SortingReviewDto::getId) @@ -295,7 +295,7 @@ class findSortingReviewsByRating_관련_성공_테스트 { final var page = 페이지요청_평점_내림차순_생성(0, 2); // when - final var actual = reviewRepository.findSortingRatingByRatingDesc(product, lastReviewId, page); + final var actual = reviewRepository.findSortingRatingByRatingDesc(product, member, lastReviewId, page); // then assertThat(actual).extracting(SortingReviewDto::getId)