feat(interaction): 点赞与评论按集统计

This commit is contained in:
Zhou Weidong committed 2026-10-21 15:56:26 +08:00
1 parent c7ff729f84
commit c6f729fb27
28 files changed
+683 -41

No files matched your search

@@ -5,6 +5,7 @@ package com.fruitshorts.admin.controller;
import com.fruitshorts.admin.support.ControllerContractSupport;
import com.fruitshorts.common.pojo.PageResult;
import com.fruitshorts.content.service.DramaService;
import com.fruitshorts.content.service.EpisodeService;
import com.fruitshorts.content.vo.DramaPageReqVO;
import com.fruitshorts.content.vo.DramaRespVO;
import com.fruitshorts.interaction.service.CommentService;
@@ -28,14 +29,16 @@ class DramaControllerContractTest {
private DramaService dramaService;
private CommentService commentService;
private EpisodeService episodeService;
private MockMvc mockMvc;
@BeforeEach
void setUp() {
dramaService = mock(DramaService.class);
commentService = mock(CommentService.class);
episodeService = mock(EpisodeService.class);
mockMvc = ControllerContractSupport.mockMvcOf(
new DramaController(dramaService, commentService));
new DramaController(dramaService, commentService, episodeService));
}
@Test
@@ -46,6 +49,8 @@ class DramaControllerContractTest {
.willReturn(new PageResult<>(2L, List.of(first, second)));
given(commentService.countByDramas(List.of(7L, 8L)))
.willReturn(Map.of(7L, 11L));
given(episodeService.sumLikeCountsByDramas(List.of(7L, 8L)))
.willReturn(Map.of(7L, 3200L, 8L, 120L));
mockMvc.perform(get("/admin/dramas/page"))
.andExpect(status().isOk())
@@ -65,6 +70,7 @@ class DramaControllerContractTest {
void should_fill_comment_count_when_detail_is_requested() throws Exception {
given(dramaService.get(7L)).willReturn(drama(7L, 3200L, 1800L));
given(commentService.countByDramas(List.of(7L))).willReturn(Map.of(7L, 11L));
given(episodeService.sumLikeCountsByDramas(List.of(7L))).willReturn(Map.of(7L, 3200L));
mockMvc.perform(get("/admin/dramas/7"))
.andExpect(status().isOk())
@@ -0,0 +1,70 @@
// Author: fruit.com.cn
package com.fruitshorts.admin.controller;
import com.fruitshorts.admin.support.ControllerContractSupport;
import com.fruitshorts.content.dal.entity.Drama;
import com.fruitshorts.content.service.DramaService;
import com.fruitshorts.content.service.EpisodeService;
import com.fruitshorts.content.vo.EpisodeRespVO;
import com.fruitshorts.interaction.service.CommentService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.test.web.servlet.MockMvc;
import java.util.List;
import java.util.Map;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
/** K89:后台剧集列表按集回填点赞/评论,并带所属剧收藏/热度。 */
class EpisodeControllerContractTest {
private EpisodeService episodeService;
private CommentService commentService;
private DramaService dramaService;
private MockMvc mockMvc;
@BeforeEach
void setUp() {
episodeService = mock(EpisodeService.class);
commentService = mock(CommentService.class);
dramaService = mock(DramaService.class);
mockMvc = ControllerContractSupport.mockMvcOf(
new EpisodeController(episodeService, commentService, dramaService));
}
@Test
void should_return_episode_and_drama_interaction_counts() throws Exception {
given(episodeService.listByDrama(5L, null)).willReturn(List.of(
episode(11L, 10L),
episode(12L, 20L)));
given(commentService.countByEpisodes(List.of(11L, 12L)))
.willReturn(Map.of(11L, 3L));
Drama drama = new Drama();
drama.setFavoriteCount(88L);
drama.setViewCount(1000L);
given(dramaService.getExisting(5L)).willReturn(drama);
mockMvc.perform(get("/admin/episodes").param("dramaId", "5"))
.andExpect(status().isOk())
.andExpect(jsonPath("$.data[0].likeCount").value("10"))
.andExpect(jsonPath("$.data[0].commentCount").value("3"))
.andExpect(jsonPath("$.data[0].favoriteCount").value("88"))
.andExpect(jsonPath("$.data[0].heat").value("1000"))
.andExpect(jsonPath("$.data[1].likeCount").value("20"))
.andExpect(jsonPath("$.data[1].commentCount").value("0"));
}
private EpisodeRespVO episode(Long id, Long likeCount) {
EpisodeRespVO episode = new EpisodeRespVO();
episode.setId(id);
episode.setDramaId(5L);
episode.setLikeCount(likeCount);
return episode;
}
}