feat: 实现门店套餐分配功能并统一测试基础设施
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m30s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m30s
新增功能: - 门店套餐分配管理(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>
This commit is contained in:
51
openspec/changes/unify-test-infrastructure/tasks.md
Normal file
51
openspec/changes/unify-test-infrastructure/tasks.md
Normal file
@@ -0,0 +1,51 @@
|
||||
# 测试基础设施统一 - 任务清单
|
||||
|
||||
## 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)
|
||||
Reference in New Issue
Block a user