feat(app): 推荐流支持分类过滤
This commit is contained in:
1 parent
0e8fb1582d
commit
8f35160b56
12 files changed
+255
-24
No files matched your search
+3
-2
@@ -96,11 +96,12 @@ class AppCatalogControllerContractTest {
|
||||
card.setId(12L);
|
||||
card.setTitle("漫剧卡片");
|
||||
card.setDramaType("ANIME");
|
||||
given(catalogService.feed("ANIME", null, 20))
|
||||
given(catalogService.feed("ANIME", 7L, null, 20))
|
||||
.willReturn(new CursorResult<>(List.of(card), 12L, true));
|
||||
|
||||
catalogMvc.perform(get("/app/feed")
|
||||
.param("types", "ANIME")
|
||||
.param("categoryId", "7")
|
||||
.param("size", "20"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0))
|
||||
@@ -109,7 +110,7 @@ class AppCatalogControllerContractTest {
|
||||
.andExpect(jsonPath("$.data.nextCursor").value("12"))
|
||||
.andExpect(jsonPath("$.data.hasMore").value(true));
|
||||
|
||||
verify(catalogService).feed("ANIME", null, 20);
|
||||
verify(catalogService).feed("ANIME", 7L, null, 20);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -56,7 +56,7 @@ class AppCommentCountAnonymousSecurityTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
given(commentService.countByDrama(7L)).willReturn(9L);
|
||||
given(catalogService.feed("ANIME", null, 20))
|
||||
given(catalogService.feed("ANIME", null, null, 20))
|
||||
.willReturn(new CursorResult<>(List.of(), null, false));
|
||||
}
|
||||
|
||||
|
||||
+28
-10
@@ -118,7 +118,7 @@ class AppCatalogServiceTest {
|
||||
@Test
|
||||
void should_filter_feed_by_drama_type_and_expose_it_on_card() {
|
||||
Drama anime = drama(1L, "ANIME");
|
||||
given(dramaService.listPublishedFeed(List.of("ANIME"), null, 21))
|
||||
given(dramaService.listPublishedFeed(List.of("ANIME"), null, null, 21))
|
||||
.willReturn(List.of(anime));
|
||||
given(dramaCategoryService.listBasic()).willReturn(List.of());
|
||||
DramaEpisode preview = episode(11L, 1L, 45L);
|
||||
@@ -126,41 +126,59 @@ class AppCatalogServiceTest {
|
||||
.willReturn(Map.of(1L, preview));
|
||||
given(commentService.countByEpisodes(List.of(11L))).willReturn(Map.of(11L, 3L));
|
||||
|
||||
CursorResult<AppDramaCardVO> result = catalogService.feed("ANIME", null, null);
|
||||
CursorResult<AppDramaCardVO> result = catalogService.feed(
|
||||
"ANIME", null, null, null);
|
||||
|
||||
assertThat(result.getList()).hasSize(1);
|
||||
assertThat(result.getList().get(0).getDramaType()).isEqualTo("ANIME");
|
||||
assertThat(result.getList().get(0).getCommentCount()).isEqualTo(3L);
|
||||
assertThat(result.getList().get(0).getLikeCount()).isEqualTo(45L);
|
||||
assertThat(result.isHasMore()).isFalse();
|
||||
verify(dramaService).listPublishedFeed(List.of("ANIME"), null, 21);
|
||||
verify(dramaService).listPublishedFeed(List.of("ANIME"), null, null, 21);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_parse_multiple_feed_types() {
|
||||
given(dramaService.listPublishedFeed(List.of("ANIME", "LIVE"), null, 11))
|
||||
given(dramaService.listPublishedFeed(
|
||||
List.of("ANIME", "LIVE"), null, null, 11))
|
||||
.willReturn(List.of());
|
||||
|
||||
CursorResult<AppDramaCardVO> result = catalogService.feed("ANIME,LIVE", null, 10);
|
||||
CursorResult<AppDramaCardVO> result = catalogService.feed(
|
||||
"ANIME,LIVE", null, null, 10);
|
||||
|
||||
assertThat(result.getList()).isEmpty();
|
||||
verify(dramaService).listPublishedFeed(List.of("ANIME", "LIVE"), null, 11);
|
||||
verify(dramaService).listPublishedFeed(
|
||||
List.of("ANIME", "LIVE"), null, null, 11);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_filter_feed_by_category_id_only() {
|
||||
given(dramaService.listPublishedFeed(List.of(), 7L, null, 21))
|
||||
.willReturn(List.of());
|
||||
|
||||
CursorResult<AppDramaCardVO> result = catalogService.feed(
|
||||
null, 7L, null, null);
|
||||
|
||||
assertThat(result.getList()).isEmpty();
|
||||
verify(dramaService).listPublishedFeed(List.of(), 7L, null, 21);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_page_feed_with_cursor_without_duplicates() {
|
||||
Drama first = drama(1L, "ANIME");
|
||||
Drama second = drama(2L, "LIVE");
|
||||
given(dramaService.listPublishedFeed(List.of(), null, 2))
|
||||
given(dramaService.listPublishedFeed(List.of(), null, null, 2))
|
||||
.willReturn(List.of(first, second));
|
||||
given(dramaService.listPublishedFeed(List.of(), 1L, 2))
|
||||
given(dramaService.listPublishedFeed(List.of(), null, 1L, 2))
|
||||
.willReturn(List.of(second));
|
||||
given(dramaCategoryService.listBasic()).willReturn(List.of());
|
||||
given(episodeService.firstPlayableByDramas(any())).willReturn(Map.of());
|
||||
given(commentService.countByEpisodes(any())).willReturn(Map.of());
|
||||
|
||||
CursorResult<AppDramaCardVO> firstPage = catalogService.feed(null, null, 1);
|
||||
CursorResult<AppDramaCardVO> secondPage = catalogService.feed(null, firstPage.getNextCursor(), 1);
|
||||
CursorResult<AppDramaCardVO> firstPage = catalogService.feed(
|
||||
null, null, null, 1);
|
||||
CursorResult<AppDramaCardVO> secondPage = catalogService.feed(
|
||||
null, null, firstPage.getNextCursor(), 1);
|
||||
|
||||
assertThat(firstPage.getList()).extracting(AppDramaCardVO::getId).containsExactly(1L);
|
||||
assertThat(firstPage.getNextCursor()).isEqualTo(1L);
|
||||
|
||||
+64
-2
@@ -23,6 +23,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/** K88 App 推荐流的类型过滤与三字段 keyset 游标。 */
|
||||
@@ -60,7 +61,7 @@ class DramaServiceFeedTest {
|
||||
given(dramaMapper.selectList(any())).willReturn(List.of());
|
||||
ArgumentCaptor<QueryWrapper<Drama>> captor = ArgumentCaptor.forClass(QueryWrapper.class);
|
||||
|
||||
dramaService.listPublishedFeed(List.of("ANIME"), 9L, 5);
|
||||
dramaService.listPublishedFeed(List.of("ANIME"), null, 9L, 5);
|
||||
|
||||
verify(dramaMapper).selectList(captor.capture());
|
||||
QueryWrapper<Drama> query = captor.getValue();
|
||||
@@ -86,7 +87,7 @@ class DramaServiceFeedTest {
|
||||
given(dramaMapper.selectList(any())).willReturn(List.of());
|
||||
ArgumentCaptor<QueryWrapper<Drama>> captor = ArgumentCaptor.forClass(QueryWrapper.class);
|
||||
|
||||
dramaService.listPublishedFeed(List.of("LIVE"), 9L, 5);
|
||||
dramaService.listPublishedFeed(List.of("LIVE"), null, 9L, 5);
|
||||
|
||||
verify(dramaMapper).selectList(captor.capture());
|
||||
assertThat(captor.getValue().getSqlSegment())
|
||||
@@ -94,4 +95,65 @@ class DramaServiceFeedTest {
|
||||
.contains("view_count")
|
||||
.contains("id");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void should_apply_category_and_type_tokens_together() {
|
||||
given(dramaMapper.selectList(any())).willReturn(List.of());
|
||||
ArgumentCaptor<QueryWrapper<Drama>> captor = ArgumentCaptor.forClass(QueryWrapper.class);
|
||||
|
||||
dramaService.listPublishedFeed(List.of("ANIME"), 7L, null, 5);
|
||||
|
||||
verify(dramaMapper).selectList(captor.capture());
|
||||
QueryWrapper<Drama> query = captor.getValue();
|
||||
assertThat(query.getSqlSegment())
|
||||
.contains("drama_types")
|
||||
.contains("category_ids")
|
||||
.contains("recommend_weight");
|
||||
assertThat(query.getParamNameValuePairs().values())
|
||||
.contains("%,ANIME,%", "%,7,%");
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void should_apply_category_cursor_for_matching_marker() {
|
||||
Drama marker = new Drama();
|
||||
marker.setId(9L);
|
||||
marker.setStatus("published");
|
||||
marker.setDramaType("ANIME");
|
||||
marker.setCategoryId(7L);
|
||||
marker.setCategoryIds("7,8");
|
||||
marker.setRecommendWeight(30);
|
||||
marker.setViewCount(1200L);
|
||||
given(dramaMapper.selectById(9L)).willReturn(marker);
|
||||
given(dramaMapper.selectList(any())).willReturn(List.of());
|
||||
ArgumentCaptor<QueryWrapper<Drama>> captor = ArgumentCaptor.forClass(QueryWrapper.class);
|
||||
|
||||
dramaService.listPublishedFeed(List.of(), 7L, 9L, 5);
|
||||
|
||||
verify(dramaMapper).selectList(captor.capture());
|
||||
QueryWrapper<Drama> query = captor.getValue();
|
||||
assertThat(query.getSqlSegment())
|
||||
.contains("category_ids")
|
||||
.contains("recommend_weight")
|
||||
.contains("id");
|
||||
assertThat(query.getParamNameValuePairs().values())
|
||||
.contains("%,7,%", 30, 1200L, 9L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_return_empty_when_cursor_marker_does_not_match_category() {
|
||||
Drama marker = new Drama();
|
||||
marker.setId(9L);
|
||||
marker.setStatus("published");
|
||||
marker.setDramaType("ANIME");
|
||||
marker.setCategoryId(8L);
|
||||
marker.setCategoryIds("8");
|
||||
given(dramaMapper.selectById(9L)).willReturn(marker);
|
||||
|
||||
List<Drama> rows = dramaService.listPublishedFeed(List.of("ANIME"), 7L, 9L, 5);
|
||||
|
||||
assertThat(rows).isEmpty();
|
||||
verify(dramaMapper, never()).selectList(any());
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -134,8 +134,8 @@ class DramaServiceMultiTagTest {
|
||||
given(dramaMapper.selectList(any())).willReturn(List.of());
|
||||
ArgumentCaptor<QueryWrapper<Drama>> captor = ArgumentCaptor.forClass(QueryWrapper.class);
|
||||
|
||||
dramaService.listPublishedFeed(List.of("ANIME"), 9L, 5);
|
||||
dramaService.listPublishedFeed(List.of("LIVE"), 9L, 5);
|
||||
dramaService.listPublishedFeed(List.of("ANIME"), null, 9L, 5);
|
||||
dramaService.listPublishedFeed(List.of("LIVE"), null, 9L, 5);
|
||||
|
||||
verify(dramaMapper, times(2)).selectList(captor.capture());
|
||||
assertThat(captor.getAllValues()).allSatisfy(query ->
|
||||
|
||||
Reference in new issue
Block a user