Browse Source

📝 docs(story): add story for evaluating and migrating integration tests

- 创建Story 005.004: 评估和迁移集成测试
- 定义开发人员将集成测试迁移到packages/server目录的需求
- 列出分析依赖、迁移测试、更新工具类和验证测试的验收标准
- 分解任务为分析依赖、迁移测试、更新工具类和验证测试四个主要部分
- 提供技术栈信息、项目结构信息和测试策略等开发笔记
yourname 4 weeks ago
parent
commit
ad35ebf502
1 changed files with 117 additions and 0 deletions
  1. 117 0
      docs/stories/005.004.story.md

+ 117 - 0
docs/stories/005.004.story.md

@@ -0,0 +1,117 @@
+# Story 005.004: 评估和迁移集成测试
+
+## Status
+Draft
+
+## Story
+**As a** 开发人员,
+**I want** 评估和迁移适合的集成测试到packages/server目录,
+**so that** packages/server成为一个真正独立的、可测试的库包,集成测试与源代码在同一包内管理
+
+## Acceptance Criteria
+1. 分析集成测试对web环境的依赖
+2. 迁移适合的集成测试到packages/server
+3. 更新测试工具类的共享使用
+4. 验证集成测试正常运行
+
+## Tasks / Subtasks
+- [ ] 分析web/tests/integration/server中的集成测试依赖 (AC: 1)
+  - [ ] 检查auth.integration.test.ts的web环境依赖
+  - [ ] 检查users.integration.test.ts的web环境依赖
+  - [ ] 检查files.integration.test.ts的web环境依赖
+  - [ ] 检查minio.integration.test.ts的web环境依赖
+  - [ ] 检查backup.integration.test.ts的web环境依赖
+- [ ] 迁移适合的集成测试到packages/server/tests/integration (AC: 2)
+  - [ ] 创建packages/server/tests/integration目录结构
+  - [ ] 迁移auth.integration.test.ts(如果依赖可解决)
+  - [ ] 迁移users.integration.test.ts(如果依赖可解决)
+  - [ ] 迁移files.integration.test.ts(如果依赖可解决)
+  - [ ] 迁移minio.integration.test.ts(如果依赖可解决)
+  - [ ] 迁移backup.integration.test.ts(如果依赖可解决)
+- [ ] 更新测试工具类的共享使用 (AC: 3)
+  - [ ] 检查packages/server/tests/utils中现有的测试工具
+  - [ ] 更新集成测试以使用packages/server中的测试工具
+  - [ ] 确保测试工具类路径正确
+- [ ] 验证集成测试正常运行 (AC: 4)
+  - [ ] 运行所有迁移后的集成测试
+  - [ ] 检查测试覆盖率
+  - [ ] 确保没有测试失败
+
+## Dev Notes
+
+### 技术栈信息 [Source: architecture/tech-stack.md]
+- **测试框架**: Vitest 3.2.4
+- **运行时**: Node.js 20.18.3
+- **模块系统**: ES 模块
+- **数据库**: PostgreSQL 17 + TypeORM
+- **API框架**: Hono 4.8.5
+- **测试工具**: hono/testing (内置)
+
+### 项目结构信息 [Source: architecture/source-tree.md]
+- **当前集成测试位置**: web/tests/integration/server/
+  - auth.integration.test.ts - 认证API集成测试
+  - users.integration.test.ts - 用户API集成测试
+  - files.integration.test.ts - 文件API集成测试
+  - minio.integration.test.ts - MinIO服务集成测试
+  - backup.integration.test.ts - 备份工具集成测试
+- **目标集成测试位置**: packages/server/tests/integration/
+- **测试工具类位置**:
+  - web/tests/utils/server/integration-test-db.ts
+  - web/tests/utils/server/integration-test-utils.ts
+  - packages/server/tests/utils/integration-test-db.ts (已存在)
+  - packages/server/tests/utils/integration-test-utils.ts (已存在)
+
+### 测试策略信息 [Source: architecture/testing-strategy.md]
+- **集成测试位置**: tests/integration/**/*.test.{ts,tsx}
+- **集成测试框架**: Vitest + Testing Library + hono/testing
+- **集成测试覆盖率目标**: ≥ 60%
+- **测试执行频率**: 每次API变更
+- **测试数据管理**: 使用专用测试数据库,事务回滚
+
+### 先前故事洞察 [Source: docs/stories/005.003.story.md]
+- 工具类测试迁移成功,所有24个测试通过
+- 测试工具类已成功迁移到packages/server/tests/utils/
+- 导入路径需要更新为@/utils/路径
+- 保持测试功能对等,迁移前后测试覆盖相同功能
+
+### 集成测试依赖分析
+- **auth.integration.test.ts**: 依赖hono/testing, @d8d/server包,可能依赖web环境配置
+- **users.integration.test.ts**: 依赖hono/testing, @d8d/server包,用户管理API测试
+- **files.integration.test.ts**: 依赖hono/testing, @d8d/server包,文件上传API测试
+- **minio.integration.test.ts**: 依赖hono/testing, @d8d/server包,MinIO服务测试
+- **backup.integration.test.ts**: 依赖hono/testing, @d8d/server包,备份工具测试
+
+### 迁移注意事项
+- 检查每个集成测试是否依赖web特定环境(如SSR、前端路由等)
+- 如果测试依赖web环境,可能需要重构或保留在web目录
+- 更新导入路径为@d8d/server包内路径
+- 确保mock和依赖注入正确配置
+- 验证测试在packages/server环境中正常运行
+
+### Testing
+- **测试文件位置**: packages/server/tests/integration/
+- **测试框架**: Vitest + hono/testing
+- **测试模式**: 集成测试,使用真实数据库连接
+- **覆盖率要求**: 集成测试覆盖率 ≥ 60%
+- **测试标准**:
+  - 使用真实数据库连接进行集成测试
+  - 遵循Arrange-Act-Assert模式
+  - 包含API端点和业务逻辑集成测试
+  - 测试文件命名: [module].integration.test.ts
+
+## Change Log
+| Date | Version | Description | Author |
+|------|---------|-------------|--------|
+| 2025-11-09 | 1.0 | 初始故事创建 | Bob (Scrum Master) |
+
+## Dev Agent Record
+
+### Agent Model Used
+
+### Debug Log References
+
+### Completion Notes List
+
+### File List
+
+## QA Results