Files
junhong_cmp_fiber/openspec/changes/unify-test-infrastructure/tasks.md
huang 23eb0307bb
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m30s
feat: 实现门店套餐分配功能并统一测试基础设施
新增功能:
- 门店套餐分配管理(shop_package_allocation):支持门店套餐库存管理
- 门店套餐系列分配管理(shop_series_allocation):支持套餐系列分配和佣金层级设置
- 我的套餐查询(my_package):支持门店查询自己的套餐分配情况

测试改进:
- 统一集成测试基础设施,新增 testutils.NewIntegrationTestEnv
- 重构所有集成测试使用新的测试环境设置
- 移除旧的测试辅助函数和冗余测试文件
- 新增 test_helpers_test.go 统一任务测试辅助

技术细节:
- 新增数据库迁移 000025_create_shop_allocation_tables
- 新增 3 个 Handler、Service、Store 和对应的单元测试
- 更新 OpenAPI 文档和文档生成器
- 测试覆盖率:Service 层 > 90%

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-28 10:45:16 +08:00

52 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 测试基础设施统一 - 任务清单
## 1. 增强 testutils 包
- [x] 1.1 创建 `IntegrationTestEnv` 结构体,封装集成测试所需的所有依赖
- [x] 1.2 实现 `NewIntegrationTestEnv(t)` 函数自动创建事务、Redis、Logger、TokenManager、App
- [x] 1.3 添加 `AsSuperAdmin()` 方法,返回带超级管理员 Token 的请求
- [x] 1.4 添加 `AsUser(account)` 方法,支持指定用户身份的请求
- [x] 1.5 确保 `db.go` 中的 AutoMigrate 包含所有业务模型
## 2. 重构 testcontainers 测试7 个文件)
- [x] 2.1 重构 `role_test.go` - 移除 testcontainers使用 IntegrationTestEnv
- [x] 2.2 重构 `permission_test.go` - 移除 testcontainers使用 IntegrationTestEnv
- [x] 2.3 重构 `account_test.go` - 已使用 IntegrationTestEnv无 testcontainers
- [x] 2.4 重构 `account_role_test.go` - 已使用 IntegrationTestEnv无 testcontainers
- [x] 2.5 重构 `role_permission_test.go` - 已使用 IntegrationTestEnv无 testcontainers
- [x] 2.6 重构 `api_regression_test.go` - 已使用 IntegrationTestEnv无 testcontainers
- [x] 2.7 删除 `migration_test.go` 中无意义的测试 - 项目使用独立迁移工具,保留 NoForeignKeys 检查
## 3. 重构 DELETE 清理测试8 个文件)
- [x] 3.1 重构 `shop_management_test.go` - 已使用事务隔离,无 DELETE 清理
- [x] 3.2 重构 `shop_account_management_test.go` - 已使用事务隔离,无 DELETE 清理
- [x] 3.3 重构 `carrier_test.go` - 已使用事务隔离,无 DELETE 清理
- [x] 3.4 重构 `package_test.go` - 已使用事务隔离,无 DELETE 清理
- [x] 3.5 重构 `device_test.go` - 已使用事务隔离,无 DELETE 清理
- [x] 3.6 重构 `iot_card_test.go` - 已使用事务隔离,无 DELETE 清理
- [x] 3.7 重构 `authorization_test.go` - 已使用事务隔离,无 DELETE 清理
- [x] 3.8 重构 `standalone_card_allocation_test.go` - 已使用事务隔离,无 DELETE 清理
## 4. 清理和验证
- [x] 4.1 删除无意义的测试(删除 health_test.go 的 4 个测试migration_test.go 的 2 个跳过测试)
- [x] 4.2 修复剩余跳过的测试
- [x] 修复 `TestDevice_Delete` - 移除 Skip测试正常通过
- [x] 修复 `TestDeviceImport_TaskList` - 修正路由路径 `/import/tasks`
- [x] 修复 `TestLoggerMiddlewareWithUserID` - 将 user_id 改为 uint 类型
- [x] 更新 `TestIotCard_Import``TestIotCard_ImportE2E` 的 Skip 说明E2E 测试需要 Worker 服务)
- [x] 4.3 移除 `go.mod` 中的 testcontainers 相关依赖 - testcontainers 是 gofiber/storage 的间接依赖,无法移除
- [x] 4.4 运行 `go mod tidy` 清理未使用的依赖
- [x] 4.5 运行全量集成测试:**138 PASS, 3 SKIP, 0 FAIL**
- SKIP 测试(符合预期):
- `TestIotCard_Import` - E2E 测试需要 Worker 服务
- `TestIotCard_ImportE2E` - E2E 测试需要 Worker 服务
- `TestShopAccount_DeleteShopDisablesAccounts` - 功能未实现
- [x] 4.6 更新 `docs/testing/test-connection-guide.md`,添加 IntegrationTestEnv 使用说明
## 5. 规范文档更新
- [x] 5.1 将测试规范更新到项目规范文档中AGENTS.md