Skip to content

Commit

Permalink
test : 모든 동아리 최신 피드 페이지 조회 쿼리 테스트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
KoSeonJe committed Jan 11, 2025
1 parent aa2adb5 commit c82b50d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ void setUp() {
feedRepository.flush();
}

@DisplayName("모든 동아리의 최신 피드를 모두 조회할 수 있다.")
@DisplayName("모든 동아리의 최신 피드 페이지를 주어진 정보에 맞춰 반환한다.")
@Test
void test() {
void findNewestPerClubPage() {
// given
Club club1 = fixture.giveMeBuilder(Club.class)
.set("name", "카우1")
Expand Down Expand Up @@ -86,14 +86,16 @@ void test() {
.sample();
feedRepository.saveAll(List.of(feed1, feed2, feed3, feed4, feed5, feed6));

int size = 2;
Long currentCursorId = -1L;
// when
List<Feed> newestFeeds = feedRepository.findNewestAll();
Slice<Feed> newestFeeds = feedRepository.findNewestPerClubPage(size, currentCursorId);

// then
assertThat(newestFeeds.size()).isEqualTo(3);
assertThat(newestFeeds.get(0).getId()).isEqualTo(6L);
assertThat(newestFeeds.get(1).getId()).isEqualTo(4L);
assertThat(newestFeeds.get(2).getId()).isEqualTo(2L);
List<Feed> feeds = newestFeeds.getContent();
assertThat(feeds.size()).isEqualTo(2);
assertThat(feeds.get(0).getId()).isEqualTo(6);
assertThat(feeds.get(1).getId()).isEqualTo(4);
}

@DisplayName("size 개수보다 남은 feed의 개수가 적다면, 그 수만큼 페이지로 반환한다.")
Expand Down Expand Up @@ -140,7 +142,6 @@ void test() {
assertThat(feeds.size()).isEqualTo(1);
assertThat(feeds.get(0).getId()).isEqualTo(feed1.getId());
assertThat(feeds.get(0).getActivityContent()).isEqualTo(feed1.getActivityContent());

}

@DisplayName("cursorId보다 작은 Feed를 size 개수만큼 페이지로 반환한다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@
import ddingdong.ddingdongBE.domain.feed.entity.Feed;
import ddingdong.ddingdongBE.domain.feed.entity.FeedType;
import ddingdong.ddingdongBE.domain.feed.repository.FeedRepository;
import ddingdong.ddingdongBE.domain.feed.service.dto.query.FeedListQuery;
import ddingdong.ddingdongBE.domain.feed.service.dto.query.FeedQuery;
import ddingdong.ddingdongBE.domain.fileinformation.service.FileInformationService;
import ddingdong.ddingdongBE.domain.scorehistory.entity.Score;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -45,62 +43,6 @@ class FacadeFeedServiceTest extends TestContainerSupport {

private final FixtureMonkey fixture = FixtureMonkeyFactory.getNotNullBuilderIntrospectorMonkey();

@DisplayName("모든 사용자는 전체 동아리의 최신 피드를 조회할 수 있다.")
@Test
void getNewestAll() {
// given
Club club1 = fixture.giveMeBuilder(Club.class)
.set("name", "카우1")
.set("user", null)
.set("score", Score.from(BigDecimal.ZERO))
.set("clubMembers", null)
.sample();
Club club2 = fixture.giveMeBuilder(Club.class)
.set("name", "카우2")
.set("user", null)
.set("score", Score.from(BigDecimal.ZERO))
.set("clubMembers", null)
.sample();
Club club3 = fixture.giveMeBuilder(Club.class)
.set("name", "카우3")
.set("user", null)
.set("score", Score.from(BigDecimal.ZERO))
.set("clubMembers", null)
.sample();
Club savedClub1 = clubRepository.save(club1);
Club savedClub2 = clubRepository.save(club2);
Club savedClub3 = clubRepository.save(club3);

Feed feed1 = fixture.giveMeBuilder(Feed.class)
.set("club", savedClub1)
.sample();
Feed feed2 = fixture.giveMeBuilder(Feed.class)
.set("club", savedClub1)
.sample();
Feed feed3 = fixture.giveMeBuilder(Feed.class)
.set("club", savedClub2)
.sample();
Feed feed4 = fixture.giveMeBuilder(Feed.class)
.set("club", savedClub2)
.sample();
Feed feed5 = fixture.giveMeBuilder(Feed.class)
.set("club", savedClub3)
.sample();
Feed feed6 = fixture.giveMeBuilder(Feed.class)
.set("club", savedClub3)
.sample();
feedRepository.saveAll(List.of(feed1, feed2, feed3, feed4, feed5, feed6));

// when
List<FeedListQuery> infos = facadeFeedService.getNewestAll();

// then
assertThat(infos).hasSize(3);
assertThat(infos.get(0).id()).isEqualTo(feed6.getId());
assertThat(infos.get(1).id()).isEqualTo(feed4.getId());
assertThat(infos.get(2).id()).isEqualTo(feed2.getId());
}

@DisplayName("모든 사용자는 동아리 피드에 대해 상세 조회할 수 있다.")
@Test
void getFeedById() {
Expand Down

0 comments on commit c82b50d

Please sign in to comment.