feat: 实现门店套餐分配功能并统一测试基础设施
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:
2026-01-28 10:45:16 +08:00
parent 5fefe9d0cb
commit 23eb0307bb
73 changed files with 8716 additions and 4558 deletions

View File

@@ -2,6 +2,7 @@ package integration
import (
"bytes"
"context"
"encoding/json"
"fmt"
"net/http/httptest"
@@ -20,6 +21,7 @@ import (
postgresStore "github.com/break/junhong_cmp_fiber/internal/store/postgres"
"github.com/break/junhong_cmp_fiber/pkg/constants"
"github.com/break/junhong_cmp_fiber/pkg/errors"
pkgGorm "github.com/break/junhong_cmp_fiber/pkg/gorm"
"github.com/break/junhong_cmp_fiber/pkg/middleware"
"github.com/break/junhong_cmp_fiber/pkg/response"
"github.com/break/junhong_cmp_fiber/tests/testutils"
@@ -97,7 +99,8 @@ func TestPlatformAccountAPI_ListPlatformAccounts(t *testing.T) {
assert.GreaterOrEqual(t, len(items), 2)
var count int64
tx.Model(&model.Account{}).Where("user_type IN ?", []int{1, 2}).Count(&count)
ctx := pkgGorm.SkipDataPermission(context.Background())
tx.WithContext(ctx).Model(&model.Account{}).Where("user_type IN ?", []int{1, 2}).Count(&count)
assert.GreaterOrEqual(t, count, int64(2))
})
@@ -173,7 +176,8 @@ func TestPlatformAccountAPI_UpdatePassword(t *testing.T) {
assert.Equal(t, 0, result.Code)
var updated model.Account
tx.First(&updated, testAccount.ID)
ctx := pkgGorm.SkipDataPermission(context.Background())
tx.WithContext(ctx).First(&updated, testAccount.ID)
assert.NotEqual(t, "old_hashed_password", updated.Password)
})
@@ -246,7 +250,8 @@ func TestPlatformAccountAPI_UpdateStatus(t *testing.T) {
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
var updated model.Account
tx.First(&updated, testAccount.ID)
ctx := pkgGorm.SkipDataPermission(context.Background())
tx.WithContext(ctx).First(&updated, testAccount.ID)
assert.Equal(t, constants.StatusDisabled, updated.Status)
})
@@ -263,7 +268,8 @@ func TestPlatformAccountAPI_UpdateStatus(t *testing.T) {
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
var updated model.Account
tx.First(&updated, testAccount.ID)
ctx := pkgGorm.SkipDataPermission(context.Background())
tx.WithContext(ctx).First(&updated, testAccount.ID)
assert.Equal(t, constants.StatusEnabled, updated.Status)
})
}
@@ -353,7 +359,8 @@ func TestPlatformAccountAPI_AssignRoles(t *testing.T) {
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
var count int64
tx.Model(&model.AccountRole{}).Where("account_id = ? AND role_id = ?", platformUser.ID, testRole.ID).Count(&count)
ctx := pkgGorm.SkipDataPermission(context.Background())
tx.WithContext(ctx).Model(&model.AccountRole{}).Where("account_id = ? AND role_id = ?", platformUser.ID, testRole.ID).Count(&count)
assert.Equal(t, int64(1), count)
})
@@ -370,7 +377,8 @@ func TestPlatformAccountAPI_AssignRoles(t *testing.T) {
assert.Equal(t, fiber.StatusOK, resp.StatusCode)
var count int64
tx.Model(&model.AccountRole{}).Where("account_id = ?", platformUser.ID).Count(&count)
ctx := pkgGorm.SkipDataPermission(context.Background())
tx.WithContext(ctx).Model(&model.AccountRole{}).Where("account_id = ?", platformUser.ID).Count(&count)
assert.Equal(t, int64(0), count)
})
}