diff --git a/fruitshorts-app-api/src/main/java/com/fruitshorts/app/service/AppCatalogService.java b/fruitshorts-app-api/src/main/java/com/fruitshorts/app/service/AppCatalogService.java index 0d82b01..44e5e16 100644 --- a/fruitshorts-app-api/src/main/java/com/fruitshorts/app/service/AppCatalogService.java +++ b/fruitshorts-app-api/src/main/java/com/fruitshorts/app/service/AppCatalogService.java @@ -107,7 +107,7 @@ public class AppCatalogService { Drama drama = dramaService.getPublished(dramaId); List episodes = episodeService.listPublishedByDrama(dramaId); Map episodeCommentCounts = commentService.countByEpisodes( - episodes.stream().map(DramaEpisode::getId).toList()); + episodes.stream().map(DramaEpisode::getId).sorted().toList()); String categoryName = categoryNameMap().getOrDefault(drama.getCategoryId(), ""); AppDramaDetailVO detail = new AppDramaDetailVO(); @@ -173,7 +173,7 @@ public class AppCatalogService { List ids = dramas.stream().map(Drama::getId).toList(); Map previews = episodeService.firstPlayableByDramas(ids); Map commentCounts = commentService.countByEpisodes( - previews.values().stream().map(DramaEpisode::getId).toList()); + previews.values().stream().map(DramaEpisode::getId).sorted().toList()); return dramas.stream() .map(drama -> toCard( drama, categoryNames, previews.get(drama.getId()), commentCounts)) diff --git a/fruitshorts-app-api/src/test/java/com/fruitshorts/app/service/AppCatalogServiceTest.java b/fruitshorts-app-api/src/test/java/com/fruitshorts/app/service/AppCatalogServiceTest.java index 1fde422..711a5be 100644 --- a/fruitshorts-app-api/src/test/java/com/fruitshorts/app/service/AppCatalogServiceTest.java +++ b/fruitshorts-app-api/src/test/java/com/fruitshorts/app/service/AppCatalogServiceTest.java @@ -15,6 +15,7 @@ import com.fruitshorts.media.service.PlaybackSigner; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -56,12 +57,15 @@ class AppCatalogServiceTest { drama.setLikeCount(3200L); drama.setFavoriteCount(1800L); drama.setViewCount(12400L); - DramaEpisode episode = episode(11L, 42L, 55L); + DramaEpisode firstEpisode = episode(11L, 42L, 55L); + DramaEpisode secondEpisode = episode(22L, 42L, 66L); given(dramaService.getPublished(42L)).willReturn(drama); - given(episodeService.listPublishedByDrama(42L)).willReturn(List.of(episode)); + given(episodeService.listPublishedByDrama(42L)) + .willReturn(List.of(secondEpisode, firstEpisode)); given(dramaCategoryService.listBasic()).willReturn(List.of()); given(commentService.countByDrama(42L)).willReturn(96L); - given(commentService.countByEpisodes(List.of(11L))).willReturn(Map.of(11L, 2L)); + given(commentService.countByEpisodes(List.of(11L, 22L))) + .willReturn(Map.of(11L, 2L, 22L, 4L)); AppDramaDetailVO detail = catalogService.dramaDetail(42L); @@ -69,8 +73,8 @@ class AppCatalogServiceTest { assertThat(detail.getLikeCount()).isEqualTo(3200L); assertThat(detail.getFavoriteCount()).isEqualTo(1800L); assertThat(detail.getCommentCount()).isEqualTo(96L); - assertThat(detail.getEpisodes().get(0).getLikeCount()).isEqualTo(55L); - assertThat(detail.getEpisodes().get(0).getCommentCount()).isEqualTo(2L); + assertThat(detail.getEpisodes().get(0).getLikeCount()).isEqualTo(66L); + assertThat(detail.getEpisodes().get(0).getCommentCount()).isEqualTo(4L); verify(commentService).countByDrama(42L); } @@ -90,8 +94,10 @@ class AppCatalogServiceTest { second.setFavoriteCount(80L); DramaEpisode firstEpisode = episode(11L, 1L, 320L); DramaEpisode secondEpisode = episode(22L, 2L, 120L); - given(episodeService.firstPlayableByDramas(List.of(1L, 2L))) - .willReturn(Map.of(1L, firstEpisode, 2L, secondEpisode)); + Map previews = new LinkedHashMap<>(); + previews.put(2L, secondEpisode); + previews.put(1L, firstEpisode); + given(episodeService.firstPlayableByDramas(List.of(1L, 2L))).willReturn(previews); given(dramaCategoryService.listBasic()).willReturn(List.of()); given(commentService.countByEpisodes(List.of(11L, 22L))) .willReturn(Map.of(11L, 9L));