Ver código fonte

✅ test(shared-crud): complete integration tests for data permission control

- mark test suite implementation as completed in story documentation
- fix mockAuthMiddleware variable declaration to allow reassignment
- add detailed error logging for permission control disabled test cases
- disable parallel testing to prevent database connection conflicts

📝 docs(stories): update shared CRUD data permission story status

- mark "实现完整的测试套件" task as completed
- mark "编写集成测试验证完整CRUD路由的权限控制" subtask as completed
yourname 1 mês atrás
pai
commit
6713b921f8

+ 2 - 2
docs/stories/006.001.shared-crud-data-permission.story.md

@@ -47,8 +47,8 @@ Draft
   - [ ] 添加管理员角色检查逻辑
   - [ ] 添加管理员角色检查逻辑
   - [ ] 实现管理员权限覆盖功能
   - [ ] 实现管理员权限覆盖功能
   - [ ] 确保管理员可以访问所有数据
   - [ ] 确保管理员可以访问所有数据
-- [ ] 实现完整的测试套件 (AC: 8)
-  - [ ] 编写集成测试验证完整CRUD路由的权限控制
+- [x] 实现完整的测试套件 (AC: 8)
+  - [x] 编写集成测试验证完整CRUD路由的权限控制
 
 
 ## Dev Notes
 ## Dev Notes
 
 

+ 12 - 1
packages/shared-crud/tests/integration/data-permission.integration.test.ts

@@ -118,7 +118,7 @@ describe('共享CRUD数据权限控制集成测试', () => {
     });
     });
 
 
     // 创建模拟认证中间件
     // 创建模拟认证中间件
-    const mockAuthMiddleware = async (c: any, next: any) => {
+    mockAuthMiddleware = async (c: any, next: any) => {
       const authHeader = c.req.header('Authorization');
       const authHeader = c.req.header('Authorization');
       if (authHeader && authHeader.startsWith('Bearer ')) {
       if (authHeader && authHeader.startsWith('Bearer ')) {
         const token = authHeader.substring(7);
         const token = authHeader.substring(7);
@@ -518,6 +518,17 @@ describe('共享CRUD数据权限控制集成测试', () => {
       });
       });
 
 
       console.debug('禁用权限控制时的响应状态:', response.status);
       console.debug('禁用权限控制时的响应状态:', response.status);
+
+      if (response.status !== 200) {
+        try {
+          const errorData = await response.json();
+          console.debug('禁用权限控制时的错误信息:', errorData);
+        } catch (e) {
+          const text = await response.text();
+          console.debug('禁用权限控制时的响应文本:', text);
+        }
+      }
+
       expect(response.status).toBe(200);
       expect(response.status).toBe(200);
 
 
       if (response.status === 200) {
       if (response.status === 200) {

+ 3 - 1
packages/shared-crud/vitest.config.ts

@@ -10,5 +10,7 @@ export default defineConfig({
       reporter: ['text', 'json', 'html'],
       reporter: ['text', 'json', 'html'],
       exclude: ['node_modules/', 'tests/']
       exclude: ['node_modules/', 'tests/']
     }
     }
-  }
+  },
+  // 关闭并行测试以避免数据库连接冲突
+  fileParallelism: false
 });
 });