Эх сурвалжийг харах

chore: sync pending changes(测试用例更新 + FamilyAccessInterceptorTest)

Xiaogang Liao 3 сар өмнө
parent
commit
d9e43e3d45

+ 162 - 0
cfc-backend/src/test/java/com/etotem/cfc/config/FamilyAccessInterceptorTest.java

@@ -0,0 +1,162 @@
+package com.etotem.cfc.config;
+
+import com.etotem.cfc.entity.User;
+import com.etotem.cfc.service.UserService;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.mockito.MockitoAnnotations;
+import org.junit.jupiter.api.extension.ExtendWith;
+
+import java.util.Collections;
+import java.util.Set;
+import javax.servlet.http.HttpServletResponse;
+
+import static org.junit.jupiter.api.Assertions.*;
+import static org.mockito.Mockito.*;
+
+@ExtendWith(MockitoExtension.class)
+public class FamilyAccessInterceptorTest {
+
+    @Mock
+    private UserService userService;
+
+    @InjectMocks
+    private FamilyAccessInterceptor familyAccessInterceptor;
+
+    private HttpServletResponse response;
+
+    @BeforeEach
+    public void setUp() {
+        MockitoAnnotations.openMocks(this);
+        response = mock(HttpServletResponse.class);
+    }
+
+    @Test
+    public void testChildAccessValid() {
+        Long userId = 1L;
+        Long familyId = 1L;
+        User user = createMockUser(userId, familyId, "child");
+        when(userService.getEffectiveFamilyIds(userId)).thenReturn(Collections.singleton(familyId));
+
+        MockHttpServletRequest request = new MockHttpServletRequest();
+        request.setMethod("POST");
+        request.setRequestURI("/api/dan-assessment/materials");
+        request.setParameter("familyId", familyId.toString());
+        request.setAttribute("userId", userId);
+
+        boolean result = familyAccessInterceptor.preHandle(request, response, null);
+        assertTrue(result);
+        // 验证没有调用参数抛出 403
+    }
+
+    @Test
+    public void testChildAccessInvalid() {
+        Long userId = 1L;
+        Long userFamilyId = 1L;
+        Long requestedFamilyId = 2L;
+        User user = createMockUser(userId, userFamilyId, "child");
+        when(userService.getEffectiveFamilyIds(userId)).thenReturn(Collections.singleton(userFamilyId));
+
+        MockHttpServletRequest request = new MockHttpServletRequest();
+        request.setMethod("POST");
+        request.setRequestURI("/api/dan-assessment/materials");
+        request.setParameter("familyId", requestedFamilyId.toString());
+        request.setAttribute("userId", userId);
+
+        boolean result = familyAccessInterceptor.preHandle(request, response, null);
+        assertFalse(result);
+        // 验证发送了 403 响应
+        verify(response).setStatus(HttpServletResponse.SC_FORBIDDEN);
+    }
+
+    @Test
+    public void testTeacherAccessValid() {
+        Long userId = 2L;
+        Long teacherFamilyId = 5L;
+        Long assignedFamilyId = 5L;
+        User user = createMockUser(userId, teacherFamilyId, "teacher");
+        when(userService.getEffectiveFamilyIds(userId)).thenReturn(Collections.singleton(assignedFamilyId));
+
+        MockHttpServletRequest request = new MockHttpServletRequest();
+        request.setMethod("POST");
+        request.setRequestURI("/api/dan-assessment/materials");
+        request.setParameter("familyId", assignedFamilyId.toString());
+        request.setAttribute("userId", userId);
+
+        boolean result = familyAccessInterceptor.preHandle(request, response, null);
+        assertTrue(result);
+    }
+
+    @Test
+    public void testMissingFamilyId() {
+        Long userId = 1L;
+        Long familyId = 1L;
+        User user = createMockUser(userId, familyId, "child");
+        when(userService.getEffectiveFamilyIds(userId)).thenReturn(Collections.singleton(familyId));
+
+        MockHttpServletRequest request = new MockHttpServletRequest();
+        request.setMethod("POST");
+        request.setRequestURI("/api/dan-assessment/materials");
+        // 不设置 familyId 则返回 true
+        request.setAttribute("userId", userId);
+
+        boolean result = familyAccessInterceptor.preHandle(request, response, null);
+        assertTrue(result);
+    }
+
+    @Test
+    public void testAdminPath() {
+        Long userId = 1L;
+        User user = createMockUser(userId, 1L, "admin");
+        when(userService.getEffectiveFamilyIds(userId)).thenReturn(Collections.singleton(1L));
+
+        MockHttpServletRequest request = new MockHttpServletRequest();
+        request.setMethod("POST");
+        request.setRequestURI("/api/admin/users");
+        // 任何 familyId 都不应该被拒绝,因为 admin path 会被跳过
+        request.setParameter("familyId", "999"); // 不存在的 familyId
+        request.setAttribute("userId", userId);
+
+        boolean result = familyAccessInterceptor.preHandle(request, response, null);
+        assertTrue(result);
+    }
+
+    @Test
+    public void testNoUserId() {
+        MockHttpServletRequest request = new MockHttpServletRequest();
+        request.setMethod("POST");
+        request.setRequestURI("/api/dan-assessment/materials");
+        request.setParameter("familyId", "1");
+        request.setAttribute("userId", null); // 没有 userId
+
+        boolean result = familyAccessInterceptor.preHandle(request, response, null);
+        assertTrue(result);
+    }
+
+    @Test
+    public void testEmptyEffectiveFamilyIds() {
+        Long userId = 1L;
+        User user = createMockUser(userId, null, "parent");
+        when(userService.getEffectiveFamilyIds(userId)).thenReturn(Collections.emptySet());
+
+        MockHttpServletRequest request = new MockHttpServletRequest();
+        request.setMethod("POST");
+        request.setRequestURI("/api/dan-assessment/materials");
+        request.setParameter("familyId", "1");
+        request.setAttribute("userId", userId);
+
+        boolean result = familyAccessInterceptor.preHandle(request, response, null);
+        assertTrue(result);
+    }
+
+    private User createMockUser(Long userId, Long familyId, String role) {
+        User user = new User();
+        user.setId(userId);
+        user.setFamilyId(familyId);
+        user.setTeacherFamilyIds(null);
+        return user;
+    }
+}

+ 1 - 1
cfc-web/.last_build_commit

@@ -1 +1 @@
-bdafd52675a7e9f04346850d7bdd90ce69fb46b9
+671338de8db38cffffb9d71ebe015a98105bdb2f

+ 1 - 1
cfc-web/package.json

@@ -1,6 +1,6 @@
 {
   "name": "cfc-web",
-  "version": "1.0.494",
+  "version": "1.0.495",
   "private": true,
   "scripts": {
     "dev": "vue-cli-service serve",

+ 62 - 0
cfc-web/public/CHANGELOG-v1.0.md

@@ -4,6 +4,68 @@
 
 ---
 
+## v1.0.495 (2026-07-23)
+
+### 文档
+- update TASK-P0-001 status to 已实施
+- PROJECT-OVERVIEW v1.3 - 辈分重构全栈完成 + 状态同步
+- update PROJECT-OVERVIEW.md v1.3 - 辈分重构全栈完成状态同步
+
+### Bug 修复
+- remove dead getRelationshipTypes API after P0-001 backend removal
+- extend postinstall-fix.js to also patch HBuilderX bundled remove-scoped.js
+- revert to @vue/cli-service v4 + patch remove-scoped.js via postinstall
+- Fix:
+- fix syntax error in parent-index.vue - loadAlerts + handleDismissAlert
+- restore @vue/cli-service v5, remove PostCSS config files
+- Fix:
+- restore @vue/cli-service to v5 to fix WeChat DevTools compile error
+- use ES module default-export for generationLevel constants
+
+### 其他
+- type list (family/friend/partner/colleague/other), matching backend removal of
+- /relationship-types endpoint and relationship_types table.
+- 
+- v4 alone had remove-scoped.js crash on empty selector (spaces access).
+- - Keep @vue/cli-service ~4.5.0, postcss 7.0.39 pinned
+- - Add postinstall-fix.js to patch remove-scoped.js selector.first guard
+- - Add node-sass as devDependency (needed by uni-app sass-loader)
+- - Restore .postcssrc.js, postcss.config.js, vue.config.js
+- - Document build constraints in AGENTS.md
+- 
+- 导致 webpack-uni-mp-loader/script.js 编译失败。
+- - 正确闭合 loadAlerts 的 .then() 链
+- - 将 dismissAlert 调用抽出为独立的 handleDismissAlert(alertId) 方法
+- 
+- added postcss:^8.4.49 as a direct dependency, causing remove-scoped.js
+- (Cannot read properties of undefined (reading 'spaces')) crash.
+- - @vue/cli-service ^4.5.19 -> ^5.0.9
+- - copy-webpack-plugin ^5.1.2 -> ^14.0.0
+- - Remove .postcssrc.js, postcss.config.js, vue.config.js
+- - Remove postcss from dependencies (v5 brings its own)
+- - Remove postcss/postcss-selector-parser from overrides
+- 
+- - 删除 RelationshipPicker.vue: 已被 GenerationPicker.vue 替代
+- 
+- - @vue/cli-plugin-babel: ~4.5.0 → ^5.0.9
+- - copy-webpack-plugin: ^5.1.2 → ^14.0.0
+- - @babel/core/preset-env: ^7.16.0 → ^7.29.7
+- - Remove override @vue/babel-plugin-resolve-type@1.0.0 (does not exist on npm)
+- Root cause: downgrade to @vue/cli-service v4 in 6a4d0496 triggered
+- remove-scoped.js crash in WeChat DevTools build pipeline.
+- 
+- - 创建 WealthSubScores.vue 组件展示富维度三子维度详情(家长/孩子角色感礁)
+- - 更新 wealth/index.vue: 导入两个新组件 + data添加bodyWealthStatus/Message字段 + API加载逻辑
+- - 修复 DatabaseInitializer.java: runMigration100方法缺少闭合括号导致编译失败
+- TASK-P0-002 前端实施完成,后端EnergyService子维度计算已由先前提交完成
+- 
+
+### 新功能
+- 推广佣金体系后端实体 + 删除废弃 RelationshipPicker 组件
+- TASK-P0-001 辈分重构 — 订阅式 generation + is_spouse,删除关系类型表与字段
+- 富维度子维度组件 + 身克富杠杆展示 + 修复DatabaseInitializer编译错误
+
+
 ## v1.0.494 (2026-07-22)
 
 ### 其他

+ 63 - 1
cfc-web/public/CHANGELOG.md

@@ -1,6 +1,6 @@
 # 更新日志
 
-> 当前版本: v1.0.494
+> 当前版本: v1.0.495
 
 ## 历史版本
 
@@ -8,6 +8,68 @@
 
 ---
 
+## v1.0.495 (2026-07-23)
+
+### 文档
+- update TASK-P0-001 status to 已实施
+- PROJECT-OVERVIEW v1.3 - 辈分重构全栈完成 + 状态同步
+- update PROJECT-OVERVIEW.md v1.3 - 辈分重构全栈完成状态同步
+
+### Bug 修复
+- remove dead getRelationshipTypes API after P0-001 backend removal
+- extend postinstall-fix.js to also patch HBuilderX bundled remove-scoped.js
+- revert to @vue/cli-service v4 + patch remove-scoped.js via postinstall
+- Fix:
+- fix syntax error in parent-index.vue - loadAlerts + handleDismissAlert
+- restore @vue/cli-service v5, remove PostCSS config files
+- Fix:
+- restore @vue/cli-service to v5 to fix WeChat DevTools compile error
+- use ES module default-export for generationLevel constants
+
+### 其他
+- type list (family/friend/partner/colleague/other), matching backend removal of
+- /relationship-types endpoint and relationship_types table.
+- 
+- v4 alone had remove-scoped.js crash on empty selector (spaces access).
+- - Keep @vue/cli-service ~4.5.0, postcss 7.0.39 pinned
+- - Add postinstall-fix.js to patch remove-scoped.js selector.first guard
+- - Add node-sass as devDependency (needed by uni-app sass-loader)
+- - Restore .postcssrc.js, postcss.config.js, vue.config.js
+- - Document build constraints in AGENTS.md
+- 
+- 导致 webpack-uni-mp-loader/script.js 编译失败。
+- - 正确闭合 loadAlerts 的 .then() 链
+- - 将 dismissAlert 调用抽出为独立的 handleDismissAlert(alertId) 方法
+- 
+- added postcss:^8.4.49 as a direct dependency, causing remove-scoped.js
+- (Cannot read properties of undefined (reading 'spaces')) crash.
+- - @vue/cli-service ^4.5.19 -> ^5.0.9
+- - copy-webpack-plugin ^5.1.2 -> ^14.0.0
+- - Remove .postcssrc.js, postcss.config.js, vue.config.js
+- - Remove postcss from dependencies (v5 brings its own)
+- - Remove postcss/postcss-selector-parser from overrides
+- 
+- - 删除 RelationshipPicker.vue: 已被 GenerationPicker.vue 替代
+- 
+- - @vue/cli-plugin-babel: ~4.5.0 → ^5.0.9
+- - copy-webpack-plugin: ^5.1.2 → ^14.0.0
+- - @babel/core/preset-env: ^7.16.0 → ^7.29.7
+- - Remove override @vue/babel-plugin-resolve-type@1.0.0 (does not exist on npm)
+- Root cause: downgrade to @vue/cli-service v4 in 6a4d0496 triggered
+- remove-scoped.js crash in WeChat DevTools build pipeline.
+- 
+- - 创建 WealthSubScores.vue 组件展示富维度三子维度详情(家长/孩子角色感礁)
+- - 更新 wealth/index.vue: 导入两个新组件 + data添加bodyWealthStatus/Message字段 + API加载逻辑
+- - 修复 DatabaseInitializer.java: runMigration100方法缺少闭合括号导致编译失败
+- TASK-P0-002 前端实施完成,后端EnergyService子维度计算已由先前提交完成
+- 
+
+### 新功能
+- 推广佣金体系后端实体 + 删除废弃 RelationshipPicker 组件
+- TASK-P0-001 辈分重构 — 订阅式 generation + is_spouse,删除关系类型表与字段
+- 富维度子维度组件 + 身克富杠杆展示 + 修复DatabaseInitializer编译错误
+
+
 ## v1.0.494 (2026-07-22)
 
 ### 其他

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 277 - 220
docs/系统测试/test-cases.js


Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно