Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] feat: 내가 받은 리뷰 목록에 페이지네이션 적용 #683

Merged
merged 41 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b85e6d2
test: RestDocs로 API 테스트 작성
nayonsoso Sep 24, 2024
b8b3666
refactor: 함수명, 변수명 병경
nayonsoso Sep 24, 2024
8c238a2
feat: 리뷰그룹에 대한 리뷰를 페이징해서 가져오는 함수 생성
nayonsoso Sep 24, 2024
2b3bb9a
feat: 페이지네이션을 사용해서 리뷰 목록 매핑하는 함수 생성
nayonsoso Sep 24, 2024
34077d6
feat: 페이지네이션을 사용해서 리뷰 목록 응답하는 서비스 함수 생성
nayonsoso Sep 24, 2024
79b4bda
refactor: 서비스 함수 바뀐 메서드 시그니처 적용
nayonsoso Sep 24, 2024
5c30f34
feat: 마지막 리뷰 아이디 기본값 설정 추가
nayonsoso Sep 24, 2024
787e707
chore: 코드 정렬
nayonsoso Sep 24, 2024
fc28d73
test: 페이지네이션 적용된 리뷰 목록 조회 테스트 작성
nayonsoso Sep 24, 2024
f0fa9c6
fix: 깨진 테스트 수정
nayonsoso Sep 24, 2024
8443181
refactor: 인자명, 변수명 변경
nayonsoso Sep 25, 2024
ecb444b
refactor: 변수명 변경
nayonsoso Sep 25, 2024
d2064d4
refactor: 오타 수정
nayonsoso Sep 25, 2024
34702c7
test: 수정한 함수를 사용해서 검증하도록 변경
nayonsoso Sep 25, 2024
a530a67
test: 마지막 리뷰 아이디 검증 추가
nayonsoso Sep 25, 2024
1ac7f16
refactor: 레포지토리 함수 이름 수정
nayonsoso Sep 26, 2024
88eea36
refactor: 응답 dto 레코드 이름 수정
nayonsoso Sep 26, 2024
1dceecb
feat: 페이지 크기를 포장하는 객체 생성
nayonsoso Sep 26, 2024
b865dce
feat: 페이지 크기 객체 적용
nayonsoso Sep 26, 2024
89cdb58
Merge remote-tracking branch 'refs/remotes/origin/develop' into be/fe…
nayonsoso Sep 26, 2024
b825f1b
fix: 컴파일 에러 해결
nayonsoso Sep 26, 2024
2b6f268
refactor: 세션-페이지네이션 컨트롤러 통합
nayonsoso Sep 26, 2024
622ea23
refactor: 세션-페이지네이션 API 문서 통합
nayonsoso Sep 26, 2024
840f337
refactor: 세션-페이지네이션 서비스 함수 통합
nayonsoso Sep 26, 2024
c793331
refactor: 사용하지 않는 dto 제거
nayonsoso Sep 26, 2024
d40ded6
refactor: 응답 dto 이름 변경
nayonsoso Sep 26, 2024
9364818
refactor: 컨트롤러 함수 이름 변경
nayonsoso Sep 26, 2024
ea61130
feat: 마지막에 조회된 리뷰 아이디를 포장하는 객체 생성
nayonsoso Sep 26, 2024
cb1c797
refactor: 포장 객체 적용
nayonsoso Sep 26, 2024
d4d546c
refactor: 서비스 함수 인자 순서 변경
nayonsoso Sep 26, 2024
3dcaeaf
refactor: 변수명 변경
nayonsoso Sep 26, 2024
1548304
chore: 주석 추가
nayonsoso Sep 26, 2024
5076911
test: 테스트 데이터를 경계값으로 설정
nayonsoso Sep 26, 2024
b83f55f
test: lastReviewId 를 통일
nayonsoso Sep 26, 2024
708afd2
refactor: 사용되지 않는 attribute 제거
nayonsoso Sep 26, 2024
8bc24d2
chore: 테스트 코드 주석 추가
nayonsoso Sep 26, 2024
cb64bb0
chore: 사용하지 않는 필드 삭제
nayonsoso Sep 26, 2024
7588097
refactor: 쿼리 사용으로 객체 대체
nayonsoso Sep 26, 2024
e86f4df
chore: 사용하지 않는 함수 삭제
nayonsoso Sep 26, 2024
fc5f345
refactor: 기본으로 제공할 리뷰 수 수정
nayonsoso Sep 26, 2024
7954cc4
fix: 깨진 테스트 코드 해결
nayonsoso Sep 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/src/docs/asciidoc/review-list.adoc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index.adoc의 리뷰 목록, 단건 조회 문서명이 서로 바뀌었는데 아루 세션 pr에서 수정되었네요!
저는 보면서 헷갈렸어서 여기도 남겨는 놓을게요~

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

operation::received-reviews[snippets="curl-request,request-headers,http-response,response-fields"]

==== 자신이 받은 리뷰 목록 조회 (세션 사용)
==== 자신이 받은 리뷰 목록 조회

operation::received-review-list-with-session[snippets="curl-request,request-cookies,http-response,response-fields"]
operation::received-review-list-with-pagination[snippets="curl-request,request-cookies,query-parameters,http-response,response-fields"]
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttribute;
import reviewme.review.service.ReviewDetailLookupService;
Expand Down Expand Up @@ -35,9 +36,12 @@ public ResponseEntity<Void> createReview(@Valid @RequestBody ReviewRegisterReque

@GetMapping("/v2/reviews")
public ResponseEntity<ReceivedReviewsResponse> findReceivedReviews(
@RequestParam(required = false) Long lastReviewId,
@RequestParam(required = false) Integer size,
@SessionAttribute("reviewRequestCode") String reviewRequestCode
) {
ReceivedReviewsResponse response = reviewListLookupService.getReceivedReviews(reviewRequestCode);
ReceivedReviewsResponse response = reviewListLookupService.getReceivedReviews(
lastReviewId, size, reviewRequestCode);
return ResponseEntity.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,16 @@ public interface ReviewRepository extends JpaRepository<Review, Long> {
""", nativeQuery = true)
List<Review> findAllByGroupId(long reviewGroupId);

@Query(value = """
SELECT r.* FROM review r
WHERE r.review_group_id = :reviewGroupId
AND r.id < :lastReviewId
ORDER BY r.created_at DESC
LIMIT :limit
""", nativeQuery = true)
List<Review> findByReviewGroupIdWithLimit(long reviewGroupId, long lastReviewId, int limit);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AND (:lastReviewId IS NULL OR r.id < :lastReviewId)

이렇게 하면 LastReviewId 클래스 필요 없을 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오! 적용해볼게요!


Optional<Review> findByIdAndReviewGroupId(long reviewId, long reviewGroupId);

int countByReviewGroupId(long id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삭제했습니다!

}
19 changes: 19 additions & 0 deletions backend/src/main/java/reviewme/review/service/LastReviewId.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package reviewme.review.service;

import lombok.Getter;

@Getter
public class LastReviewId {

private static final long DEFAULT_LAST_REVIEW_ID = Long.MAX_VALUE;

private final long id;

LastReviewId(Long id) {
if (id == null) {
this.id = DEFAULT_LAST_REVIEW_ID;
return;
}
this.id = id;
}
}
20 changes: 20 additions & 0 deletions backend/src/main/java/reviewme/review/service/PageSize.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package reviewme.review.service;

import lombok.Getter;

@Getter
public class PageSize {

private static final int DEFAULT_SIZE = 5;
private static final int MAX_SIZE = 50;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 두가지가 도메인의 특성보다는 정책적인 특성이라고 생각해서(=변경 가능성 있음) 서비스로 올리고 주입받는 건 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

설득완!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

디폴트가 5인 이유는 무엇인가요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

추가로 ReviewListLookupService 에서 리뷰 목록 조회만의 기능을 가지고 있는데 따로 클래스로 분리한 이유가 있을까요?? 안에서 해도 될 것 같다는 생각..


private final int size;

PageSize(Integer size) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오호 default로 해도 되겠곤요👍

if (size == null || size < 1 || size > MAX_SIZE) {
this.size = DEFAULT_SIZE;
return;
}
this.size = size;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import reviewme.review.repository.ReviewRepository;
import reviewme.review.service.dto.response.list.ReceivedReviewsResponse;
import reviewme.review.service.dto.response.list.ReviewListElementResponse;
import reviewme.review.service.exception.ReviewGroupNotFoundByReviewRequestCodeException;
Expand All @@ -17,15 +18,28 @@ public class ReviewListLookupService {

private final ReviewGroupRepository reviewGroupRepository;
private final ReviewListMapper reviewListMapper;
private final ReviewRepository reviewRepository;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사용하지 않는 것 같슴다

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영했습니다🫡


@Transactional(readOnly = true)
public ReceivedReviewsResponse getReceivedReviews(String reviewRequestCode) {
public ReceivedReviewsResponse getReceivedReviews(Long lastReviewId, Integer size, String reviewRequestCode) {
ReviewGroup reviewGroup = reviewGroupRepository.findByReviewRequestCode(reviewRequestCode)
.orElseThrow(() -> new ReviewGroupNotFoundByReviewRequestCodeException(reviewRequestCode));

List<ReviewListElementResponse> reviewGroupResponse = reviewListMapper.mapToReviewList(reviewGroup);
LastReviewId lastId = new LastReviewId(lastReviewId);
PageSize pageSize = new PageSize(size);
List<ReviewListElementResponse> reviewListResponse
= reviewListMapper.mapToReviewList(reviewGroup, lastId.getId(), pageSize.getSize());
int totalSize = reviewRepository.countByReviewGroupId(reviewGroup.getId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totalSize를 먼저 확인해서 0일경우 별다른 로직을 타지 않고 반환하는건 어때요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 지금은 outdated 인 것 같아요
이번 배포에서 totalSize를 아예 내려주지 않도록 이야기되었습니다..🥲
image

long newLastReviewId = calculateLastReviewId(reviewListResponse);
return new ReceivedReviewsResponse(
reviewGroup.getReviewee(), reviewGroup.getProjectName(), reviewGroupResponse
reviewGroup.getReviewee(), reviewGroup.getProjectName(), totalSize, newLastReviewId, reviewListResponse
);
}

private long calculateLastReviewId(List<ReviewListElementResponse> elements) {
if (elements.isEmpty()) {
return 0;
}
return elements.get(elements.size() - 1).reviewId();
}
Comment on lines +35 to +40
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

책임 가질 객체 나올 것 같은데 나중에 고민해볼게요

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
public record ReceivedReviewsResponse(
String revieweeName,
String projectName,
int totalSize,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totalSize 말고 reviewCount와 같은 건 어떨까요?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 반영하려면 프론트와 상의해야 해요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요청-응답간에 크기를 나타내는 용어로 'size'가 사용되고 있어서 이것도 size 로 끝나면 좋겠어요🥹
totalSize가 명시적이지 않다면 totalReviewSize 정도는 어떠신가요?!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

size도 count도 지금 보면 괜찮은 듯 하기도 하고... total이 들어갈 이유는 아직 모르겠긴 해요!

long lastReviewId,
List<ReviewListElementResponse> reviews
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ public class ReviewListMapper {

private final ReviewPreviewGenerator reviewPreviewGenerator = new ReviewPreviewGenerator();

public List<ReviewListElementResponse> mapToReviewList(ReviewGroup reviewGroup) {
public List<ReviewListElementResponse> mapToReviewList(ReviewGroup reviewGroup,
long lastReviewId, int size) {
List<OptionItem> categoryOptionIds = optionItemRepository.findAllByOptionType(OptionType.CATEGORY);
return reviewRepository.findAllByGroupId(reviewGroup.getId())
return reviewRepository.findByReviewGroupIdWithLimit(reviewGroup.getId(), lastReviewId, size)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

~WithLimit 보다는 페이지네이션을 명시해서 확실하게 사용처를 알 수 있게 해도 좋을 것 같습니다

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Repository 입장에서 Pagination이라는 단어가 너무 추상적이지 않을까요? 몇 개를 내려줄 것이라는 걸 강조하기 위해 제가 제안했어요 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

저는 pagination을 사용하는 경우가 있고 없고, 이렇다면 pagination이 명시되는게 맞다고 생각하지만!
지금은 pagination을 사용하는게 default이고 유일한 경우니 굳이 명시하지 않아도 된다고 생각해요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이하동문입니다~.~

.stream()
.map(review -> mapToReviewListElementResponse(review, categoryOptionIds))
.toList();
Expand All @@ -43,7 +44,7 @@ private ReviewListElementResponse mapToReviewListElementResponse(Review review,
}

private List<ReviewCategoryResponse> mapToCategoryOptionResponse(Review review,
List<OptionItem> categoryOptionItems) {
List<OptionItem> categoryOptionItems) {
Set<Long> checkBoxOptionIds = review.getAllCheckBoxOptionIds();
return categoryOptionItems.stream()
.filter(optionItem -> checkBoxOptionIds.contains(optionItem.getId()))
Expand Down
23 changes: 19 additions & 4 deletions backend/src/test/java/reviewme/api/ReviewApiTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package reviewme.api;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.springframework.restdocs.cookies.CookieDocumentation.cookieWithName;
Expand All @@ -11,6 +12,7 @@
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
import static org.springframework.restdocs.request.RequestDocumentation.queryParameters;

import java.time.LocalDate;
import java.util.List;
Expand Down Expand Up @@ -156,24 +158,33 @@ class ReviewApiTest extends ApiTest {
}

@Test
void 세션으로_자신이_받은_리뷰_목록을_조회한다() {
void 자신이_받은_리뷰_목록을_조회한다() {
List<ReviewListElementResponse> receivedReviews = List.of(
new ReviewListElementResponse(1L, LocalDate.of(2024, 8, 1), "(리뷰 미리보기 1)",
List.of(new ReviewCategoryResponse(1L, "카테고리 1"))),
new ReviewListElementResponse(2L, LocalDate.of(2024, 8, 2), "(리뷰 미리보기 2)",
List.of(new ReviewCategoryResponse(2L, "카테고리 2")))
);
ReceivedReviewsResponse response = new ReceivedReviewsResponse("아루", "리뷰미", receivedReviews);
BDDMockito.given(reviewListLookupService.getReceivedReviews(anyString()))
ReceivedReviewsResponse response = new ReceivedReviewsResponse(
"아루3", "리뷰미", receivedReviews.size(), 2, receivedReviews);
BDDMockito.given(reviewListLookupService.getReceivedReviews(anyLong(), anyInt(), anyString()))
.willReturn(response);

CookieDescriptor[] cookieDescriptors = {
cookieWithName("JSESSIONID").description("세션 쿠키")
};

ParameterDescriptor[] queryParameter = {
parameterWithName("reviewRequestCode").description("리뷰 요청 코드"),
parameterWithName("lastReviewId").description("페이지의 마지막 리뷰 ID - 기본으로 최신순 첫번째 페이지 응답"),
parameterWithName("size").description("페이지의 크기 - 기본으로 5개씩 응답")
};

FieldDescriptor[] responseFieldDescriptors = {
fieldWithPath("revieweeName").description("리뷰이 이름"),
fieldWithPath("projectName").description("프로젝트 이름"),
fieldWithPath("totalSize").description("받은 리뷰 전체 개수"),
fieldWithPath("lastReviewId").description("페이지의 마지막 리뷰 ID"),

fieldWithPath("reviews[]").description("리뷰 목록"),
fieldWithPath("reviews[].reviewId").description("리뷰 ID"),
Expand All @@ -186,13 +197,17 @@ class ReviewApiTest extends ApiTest {
};

RestDocumentationResultHandler handler = document(
"received-review-list-with-session",
"received-review-list-with-pagination",
requestCookies(cookieDescriptors),
queryParameters(queryParameter),
responseFields(responseFieldDescriptors)
);

givenWithSpec().log().all()
.cookie("JSESSIONID", "ASVNE1VAKDNV4")
.queryParam("reviewRequestCode", "hello!!")
.queryParam("lastReviewId", "2")
.queryParam("size", "5")
.when().get("/v2/reviews")
.then().log().all()
.apply(handler)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package reviewme.review.repository;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
import static reviewme.fixture.QuestionFixture.서술형_필수_질문;
import static reviewme.fixture.ReviewGroupFixture.리뷰_그룹;
import static reviewme.fixture.SectionFixture.항상_보이는_섹션;
import static reviewme.fixture.TemplateFixture.템플릿;

import java.util.List;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
Expand Down Expand Up @@ -59,4 +59,83 @@ class ReviewRepositoryTest {
// then
assertThat(actual).containsExactly(review2, review1);
}

@Nested
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

중복 데이터 삽입을 안해도 되는 것 좋네요👍👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

하하~ 신경 좀 썼습니다 Nested 아름답죵? ㅎㅎ

class 리뷰그룹_아이디에_해당하는_리뷰를_생성일_기준_내림차순으로_페이징하여_불러온다 {

private final Question question = questionRepository.save(서술형_필수_질문());
private final Section section = sectionRepository.save(항상_보이는_섹션(List.of(question.getId())));
private final Template template = templateRepository.save(템플릿(List.of(section.getId())));
private final ReviewGroup reviewGroup = reviewGroupRepository.save(리뷰_그룹());

private final Review review1 = reviewRepository.save(
new Review(template.getId(), reviewGroup.getId(), null, null));
private final Review review2 = reviewRepository.save(
new Review(template.getId(), reviewGroup.getId(), null, null));
private final Review review3 = reviewRepository.save(
new Review(template.getId(), reviewGroup.getId(), null, null));


@Test
void 페이징_크기보다_적은_수의_리뷰가_등록되었으면_그_크기만큼의_리뷰만_반환한다() {
// given
int limit = 5;
long lastReviewId = Long.MAX_VALUE;

// when
List<Review> actual = reviewRepository.findByReviewGroupIdWithLimit(
reviewGroup.getId(), lastReviewId, limit);

// then
assertThat(actual)
.hasSize(3)
.containsExactly(review3, review2, review1);
}

@Test
void 페이징_크기보다_큰_수의_리뷰가_등록되었으면_페이징_크기만큼의_리뷰를_반환한다() {
// given
int limit = 2;
long lastReviewId = Long.MAX_VALUE;

// when
List<Review> actual = reviewRepository.findByReviewGroupIdWithLimit(
reviewGroup.getId(), lastReviewId, limit);

// then
assertThat(actual)
.hasSize(2)
.containsExactly(review3, review2);
}

@Test
void 마지막_리뷰_아이디를_기준으로_그보다_전에_적힌_리뷰를_반환한다() {
// given
int limit = 5;
long lastReviewId = review3.getId();

// when
List<Review> actual = reviewRepository.findByReviewGroupIdWithLimit(
reviewGroup.getId(), lastReviewId, limit);

// then
assertThat(actual)
.hasSize(2)
.containsExactly(review2, review1);
}

@Test
void 마지막으로_온_리뷰_전에_작성된_리뷰가_없으면_빈_리스트를_반환한다() {
// given
int limit = 5;
long lastReviewId = review1.getId();

// when
List<Review> actual = reviewRepository.findByReviewGroupIdWithLimit(
reviewGroup.getId(), lastReviewId, limit);

// then
assertThat(actual).isEmpty();
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5초컷 given,when,then 추가 요청😋

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영완!

Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package reviewme.review.service;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class LastReviewIdTest {

@Test
void null이_들어오면_기본값이_설정된다() {
LastReviewId lastReviewId = new LastReviewId(null);
assertEquals(Long.MAX_VALUE, lastReviewId.getId());
}

@Test
void 유효한_값이_들어오면_그_값이_설정된다() {
long id = 10L;
LastReviewId lastReviewId = new LastReviewId(id);
assertEquals(id, lastReviewId.getId());
}
}
44 changes: 44 additions & 0 deletions backend/src/test/java/reviewme/review/service/PageSizeTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package reviewme.review.service;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

class PageSizeTest {

@Test
void 유효한_값이_들어오면_그_값을_설정한다() {
int size = 10;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아주 쬐~~~그만 수정 요청)
경계값인 50으로 설정하는 건 어떨까요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영완!


PageSize pageSize = new PageSize(size);

assertEquals(size, pageSize.getSize());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

given, when, then 추가를 소소하게 요청합니다~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영완!

}

@ParameterizedTest
@ValueSource(ints = {0, -1, 51})
void 유효한_범위_외의_값이_들어오면_기본값으로_설정한다(Integer size) {
// given
int defaultSize = 5;

// when
PageSize pageSize = new PageSize(size);

// then
assertEquals(defaultSize, pageSize.getSize());
}

@Test
void null이_들어오면_기본값으로_설정한다() {
// given
int defaultSize = 5;

// when
PageSize pageSize = new PageSize(null);

// then
assertEquals(defaultSize, pageSize.getSize());
}
}
Loading