55
66import ddingdong .ddingdongBE .common .fixture .ClubFixture ;
77import ddingdong .ddingdongBE .common .fixture .FeedFixture ;
8+ import ddingdong .ddingdongBE .common .fixture .FeedMonthlyRankingFixture ;
89import ddingdong .ddingdongBE .common .fixture .UserFixture ;
910import ddingdong .ddingdongBE .common .support .TestContainerSupport ;
1011import ddingdong .ddingdongBE .domain .club .entity .Club ;
1112import ddingdong .ddingdongBE .domain .club .repository .ClubRepository ;
1213import ddingdong .ddingdongBE .domain .feed .entity .Feed ;
1314import ddingdong .ddingdongBE .domain .feed .repository .FeedCommentRepository ;
15+ import ddingdong .ddingdongBE .domain .feed .repository .FeedMonthlyRankingRepository ;
1416import ddingdong .ddingdongBE .domain .feed .repository .FeedRepository ;
1517import ddingdong .ddingdongBE .domain .feed .service .dto .query .ClubFeedRankingQuery ;
1618import ddingdong .ddingdongBE .domain .feed .service .dto .query .ClubMonthlyStatusQuery ;
@@ -41,6 +43,9 @@ class GeneralFeedRankingServiceTest extends TestContainerSupport {
4143 @ Autowired
4244 private FeedCommentRepository feedCommentRepository ;
4345
46+ @ Autowired
47+ private FeedMonthlyRankingRepository feedMonthlyRankingRepository ;
48+
4449 @ Autowired
4550 private UserRepository userRepository ;
4651
@@ -280,18 +285,17 @@ void getClubMonthlyStatus_rankAccuracy() {
280285 });
281286 }
282287
283- @ DisplayName ("동아리 이달의 현황 조회 - 성공: 저번 달에 피드가 있으면 lastMonthRank가 반환된다" )
288+ @ DisplayName ("동아리 이달의 현황 조회 - 성공: 저번 달 스냅샷이 있으면 lastMonthRank가 반환된다" )
284289 @ Test
285290 void getClubMonthlyStatus_withLastMonthRank () {
286291 // given
287292 User user = userRepository .save (UserFixture .createClubUser ());
288293 Club club = clubRepository .save (ClubFixture .createClub (user ));
289294
290- // 저번 달 피드 생성
295+ // 저번 달 스냅샷 저장
291296 LocalDate lastMonth = LocalDate .now ().minusMonths (1 );
292- Feed lastMonthFeed = feedRepository .save (FeedFixture .createImageFeed (club , "저번달 피드" ));
293- jdbcTemplate .update ("UPDATE feed SET created_at = ? WHERE id = ?" ,
294- Timestamp .valueOf (lastMonth .atStartOfDay ()), lastMonthFeed .getId ());
297+ feedMonthlyRankingRepository .save (FeedMonthlyRankingFixture .createWithRanking (
298+ club .getId (), club .getName (), lastMonth .getYear (), lastMonth .getMonthValue (), 1 ));
295299
296300 // 이번 달 피드 생성
297301 feedRepository .save (FeedFixture .createImageFeed (club , "이번달 피드" ));
@@ -302,7 +306,7 @@ void getClubMonthlyStatus_withLastMonthRank() {
302306 // when
303307 ClubMonthlyStatusQuery result = feedRankingService .getClubMonthlyStatus (user .getId (), year , month );
304308
305- // then — 저번 달에도 피드가 있으므로 lastMonthRank > 0
309+ // then — 저번 달 스냅샷이 있으므로 lastMonthRank > 0
306310 assertSoftly (softly -> {
307311 softly .assertThat (result .rank ()).isEqualTo (1 );
308312 softly .assertThat (result .lastMonthRank ()).isEqualTo (1 );
@@ -336,11 +340,10 @@ void getClubMonthlyStatus_noCurrentMonthFeed_butHasLastMonthRank() {
336340 User user = userRepository .save (UserFixture .createClubUser ());
337341 Club club = clubRepository .save (ClubFixture .createClub (user ));
338342
339- // 저번 달 피드만 생성 (이번 달 피드 없음)
343+ // 저번 달 스냅샷만 저장 (이번 달 피드 없음)
340344 LocalDate lastMonth = LocalDate .now ().minusMonths (1 );
341- Feed lastMonthFeed = feedRepository .save (FeedFixture .createImageFeed (club , "저번달 피드" ));
342- jdbcTemplate .update ("UPDATE feed SET created_at = ? WHERE id = ?" ,
343- Timestamp .valueOf (lastMonth .atStartOfDay ()), lastMonthFeed .getId ());
345+ feedMonthlyRankingRepository .save (FeedMonthlyRankingFixture .createWithRanking (
346+ club .getId (), club .getName (), lastMonth .getYear (), lastMonth .getMonthValue (), 1 ));
344347
345348 int year = LocalDate .now ().getYear ();
346349 int month = LocalDate .now ().getMonthValue ();
@@ -363,11 +366,11 @@ void getClubMonthlyStatus_januaryLooksAtDecember() {
363366 User user = userRepository .save (UserFixture .createClubUser ());
364367 Club club = clubRepository .save (ClubFixture .createClub (user ));
365368
366- // 전년도 12월 피드 생성
367369 int currentYear = LocalDate .now ().getYear ();
368- Feed decemberFeed = feedRepository .save (FeedFixture .createImageFeed (club , "12월 피드" ));
369- jdbcTemplate .update ("UPDATE feed SET created_at = ? WHERE id = ?" ,
370- Timestamp .valueOf (LocalDateTime .of (currentYear - 1 , 12 , 15 , 10 , 0 )), decemberFeed .getId ());
370+
371+ // 전년도 12월 스냅샷 저장
372+ feedMonthlyRankingRepository .save (FeedMonthlyRankingFixture .createWithRanking (
373+ club .getId (), club .getName (), currentYear - 1 , 12 , 1 ));
371374
372375 // 1월 피드 생성
373376 Feed januaryFeed = feedRepository .save (FeedFixture .createImageFeed (club , "1월 피드" ));
0 commit comments