|
|
@@ -0,0 +1,80 @@
|
|
|
+package com.etotem.cfc.unit;
|
|
|
+
|
|
|
+import com.baomidou.mybatisplus.core.MybatisConfiguration;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
+import com.baomidou.mybatisplus.core.metadata.TableInfoHelper;
|
|
|
+import com.etotem.cfc.controller.admin.AdminEarningsController;
|
|
|
+import com.etotem.cfc.entity.FamilyEarnings;
|
|
|
+import com.etotem.cfc.mapper.FamilyEarningsMapper;
|
|
|
+import org.apache.ibatis.builder.MapperBuilderAssistant;
|
|
|
+import org.junit.jupiter.api.BeforeAll;
|
|
|
+import org.junit.jupiter.api.BeforeEach;
|
|
|
+import org.junit.jupiter.api.DisplayName;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+
|
|
|
+import java.lang.reflect.Field;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import static org.mockito.ArgumentMatchers.any;
|
|
|
+import static org.mockito.Mockito.mock;
|
|
|
+import static org.mockito.Mockito.verify;
|
|
|
+import static org.mockito.Mockito.when;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 契约级单测:管理端家庭收益台账支持按 familyId 过滤(能力键 admin.earnings.familyFilter)。
|
|
|
+ *
|
|
|
+ * <p>需求/设计锚点:{@code docs/superpowers/specs/2026-11-15-family-workbench-tabs-design.md}——
|
|
|
+ * 家庭工作台 tab「收益」需锁定当前家庭,POST /api/admin/earnings/families 必须支持 {familyId} 过滤;
|
|
|
+ * 不传 familyId 时保持全量(向后兼容,现有全局收益台账不受影响)。</p>
|
|
|
+ */
|
|
|
+class AdminEarningsFamilyFilterContractTest {
|
|
|
+
|
|
|
+ private final FamilyEarningsMapper mapper = mock(FamilyEarningsMapper.class);
|
|
|
+ private AdminEarningsController controller;
|
|
|
+
|
|
|
+ @BeforeAll
|
|
|
+ static void initMybatisPlusTableInfo() {
|
|
|
+ MapperBuilderAssistant assistant = new MapperBuilderAssistant(new MybatisConfiguration(), "");
|
|
|
+ TableInfoHelper.initTableInfo(assistant, FamilyEarnings.class);
|
|
|
+ }
|
|
|
+
|
|
|
+ @BeforeEach
|
|
|
+ void setUp() throws Exception {
|
|
|
+ controller = new AdminEarningsController();
|
|
|
+ Field f = AdminEarningsController.class.getDeclaredField("familyEarningsMapper");
|
|
|
+ f.setAccessible(true);
|
|
|
+ f.set(controller, mapper);
|
|
|
+ when(mapper.selectList(any())).thenReturn(java.util.Collections.emptyList());
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("正常流:POST /api/admin/earnings/families 传 familyId 时按 family_id 过滤(tab 锁定家庭)")
|
|
|
+ void familyIdFiltersWrapper() {
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("page", 1);
|
|
|
+ params.put("size", 20);
|
|
|
+ params.put("familyId", 5001);
|
|
|
+ controller.listFamilies(params);
|
|
|
+ verify(mapper).selectList(
|
|
|
+ org.mockito.ArgumentMatchers.argThat(w -> {
|
|
|
+ if (!(w instanceof LambdaQueryWrapper)) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ LambdaQueryWrapper<?> lw = (LambdaQueryWrapper<?>) w;
|
|
|
+ String sql = lw.getSqlSegment() == null ? "" : lw.getSqlSegment();
|
|
|
+ return sql.contains("family_id") && sql.contains("=");
|
|
|
+ })
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ @DisplayName("兼容流:不传 familyId 时 wrapper 为 null(全局台账行为不变)")
|
|
|
+ void noFamilyIdKeepsAll() {
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ params.put("page", 1);
|
|
|
+ params.put("size", 20);
|
|
|
+ controller.listFamilies(params);
|
|
|
+ verify(mapper).selectList(org.mockito.ArgumentMatchers.isNull());
|
|
|
+ }
|
|
|
+}
|