feat(content): 列表卡片与后台返回收藏点赞评论数
This commit is contained in:
1 parent
f90336963b
commit
256821b824
13 files changed
+324
-50
No files matched your search
+83
@@ -0,0 +1,83 @@
|
||||
// Author: fruit.com.cn
|
||||
|
||||
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.vo.DramaPageReqVO;
|
||||
import com.fruitshorts.content.vo.DramaRespVO;
|
||||
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.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
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;
|
||||
|
||||
/** 后台短剧列表与详情的互动数量回填契约。 */
|
||||
class DramaControllerContractTest {
|
||||
|
||||
private DramaService dramaService;
|
||||
private CommentService commentService;
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
dramaService = mock(DramaService.class);
|
||||
commentService = mock(CommentService.class);
|
||||
mockMvc = ControllerContractSupport.mockMvcOf(
|
||||
new DramaController(dramaService, commentService));
|
||||
}
|
||||
|
||||
@Test
|
||||
void should_fill_comment_counts_in_batch_when_page_is_requested() throws Exception {
|
||||
DramaRespVO first = drama(7L, 3200L, 1800L);
|
||||
DramaRespVO second = drama(8L, 120L, 80L);
|
||||
given(dramaService.page(any(DramaPageReqVO.class)))
|
||||
.willReturn(new PageResult<>(2L, List.of(first, second)));
|
||||
given(commentService.countByDramas(List.of(7L, 8L)))
|
||||
.willReturn(Map.of(7L, 11L));
|
||||
|
||||
mockMvc.perform(get("/admin/dramas/page"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.code").value(0))
|
||||
.andExpect(jsonPath("$.data.list[0].likeCount").value("3200"))
|
||||
.andExpect(jsonPath("$.data.list[0].favoriteCount").value("1800"))
|
||||
.andExpect(jsonPath("$.data.list[0].commentCount").value("11"))
|
||||
.andExpect(jsonPath("$.data.list[1].likeCount").value("120"))
|
||||
.andExpect(jsonPath("$.data.list[1].favoriteCount").value("80"))
|
||||
.andExpect(jsonPath("$.data.list[1].commentCount").value("0"));
|
||||
|
||||
verify(commentService).countByDramas(List.of(7L, 8L));
|
||||
}
|
||||
|
||||
@Test
|
||||
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));
|
||||
|
||||
mockMvc.perform(get("/admin/dramas/7"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.data.likeCount").value("3200"))
|
||||
.andExpect(jsonPath("$.data.favoriteCount").value("1800"))
|
||||
.andExpect(jsonPath("$.data.commentCount").value("11"));
|
||||
}
|
||||
|
||||
private DramaRespVO drama(Long id, Long likeCount, Long favoriteCount) {
|
||||
DramaRespVO drama = new DramaRespVO();
|
||||
drama.setId(id);
|
||||
drama.setTitle("短剧" + id);
|
||||
drama.setLikeCount(likeCount);
|
||||
drama.setFavoriteCount(favoriteCount);
|
||||
return drama;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user