All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 4m35s
新增功能: - 店铺佣金查询:店铺佣金统计、店铺佣金记录列表、店铺提现记录 - 佣金提现审批:提现申请列表、审批通过、审批拒绝 - 提现配置管理:配置列表、新增配置、获取当前生效配置 - 企业管理:企业列表、创建、更新、删除、获取详情 - 企业卡授权:授权列表、批量授权、批量取消授权、统计 - 客户账号管理:账号列表、创建、更新状态、重置密码 - 我的佣金:佣金统计、佣金记录、提现申请、提现记录 数据库变更: - 扩展 tb_commission_withdrawal_request 新增提现单号等字段 - 扩展 tb_account 新增 is_primary 字段 - 扩展 tb_commission_record 新增 shop_id、balance_after - 扩展 tb_commission_withdrawal_setting 新增每日提现次数限制 - 扩展 tb_iot_card、tb_device 新增 shop_id 冗余字段 - 新建 tb_enterprise_card_authorization 企业卡授权表 - 新建 tb_asset_allocation_record 资产分配记录表 - 数据迁移:owner_type 枚举值 agent 统一为 shop 测试: - 新增 7 个单元测试文件覆盖各服务 - 修复集成测试 Redis 依赖问题
190 lines
5.7 KiB
Go
190 lines
5.7 KiB
Go
package unit
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/break/junhong_cmp_fiber/internal/model"
|
|
"github.com/break/junhong_cmp_fiber/internal/service/commission_withdrawal_setting"
|
|
"github.com/break/junhong_cmp_fiber/internal/store/postgres"
|
|
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
|
"github.com/break/junhong_cmp_fiber/tests/testutils"
|
|
)
|
|
|
|
func createWithdrawalSettingTestContext(userID uint) context.Context {
|
|
ctx := context.Background()
|
|
ctx = context.WithValue(ctx, constants.ContextKeyUserID, userID)
|
|
ctx = context.WithValue(ctx, constants.ContextKeyUserType, constants.UserTypePlatform)
|
|
return ctx
|
|
}
|
|
|
|
func TestCommissionWithdrawalSettingService_Create(t *testing.T) {
|
|
db, redisClient := testutils.SetupTestDB(t)
|
|
defer testutils.TeardownTestDB(t, db, redisClient)
|
|
|
|
accountStore := postgres.NewAccountStore(db, redisClient)
|
|
settingStore := postgres.NewCommissionWithdrawalSettingStore(db, redisClient)
|
|
|
|
service := commission_withdrawal_setting.New(db, accountStore, settingStore)
|
|
|
|
t.Run("新增提现配置", func(t *testing.T) {
|
|
ctx := createWithdrawalSettingTestContext(1)
|
|
|
|
req := &model.CreateWithdrawalSettingReq{
|
|
DailyWithdrawalLimit: 5,
|
|
MinWithdrawalAmount: 10000,
|
|
FeeRate: 100,
|
|
}
|
|
|
|
result, err := service.Create(ctx, req)
|
|
require.NoError(t, err)
|
|
assert.NotNil(t, result)
|
|
assert.Equal(t, 5, result.DailyWithdrawalLimit)
|
|
assert.Equal(t, int64(10000), result.MinWithdrawalAmount)
|
|
assert.Equal(t, int64(100), result.FeeRate)
|
|
assert.True(t, result.IsActive)
|
|
})
|
|
|
|
t.Run("未授权用户创建配置应失败", func(t *testing.T) {
|
|
ctx := context.Background()
|
|
|
|
req := &model.CreateWithdrawalSettingReq{
|
|
DailyWithdrawalLimit: 5,
|
|
MinWithdrawalAmount: 10000,
|
|
FeeRate: 100,
|
|
}
|
|
|
|
_, err := service.Create(ctx, req)
|
|
assert.Error(t, err)
|
|
})
|
|
}
|
|
|
|
func TestCommissionWithdrawalSettingService_ConfigSwitch(t *testing.T) {
|
|
db, redisClient := testutils.SetupTestDB(t)
|
|
defer testutils.TeardownTestDB(t, db, redisClient)
|
|
|
|
accountStore := postgres.NewAccountStore(db, redisClient)
|
|
settingStore := postgres.NewCommissionWithdrawalSettingStore(db, redisClient)
|
|
|
|
service := commission_withdrawal_setting.New(db, accountStore, settingStore)
|
|
|
|
t.Run("配置切换-旧配置自动失效", func(t *testing.T) {
|
|
ctx := createWithdrawalSettingTestContext(1)
|
|
|
|
req1 := &model.CreateWithdrawalSettingReq{
|
|
DailyWithdrawalLimit: 3,
|
|
MinWithdrawalAmount: 5000,
|
|
FeeRate: 50,
|
|
}
|
|
result1, err := service.Create(ctx, req1)
|
|
require.NoError(t, err)
|
|
assert.True(t, result1.IsActive)
|
|
|
|
req2 := &model.CreateWithdrawalSettingReq{
|
|
DailyWithdrawalLimit: 10,
|
|
MinWithdrawalAmount: 20000,
|
|
FeeRate: 200,
|
|
}
|
|
result2, err := service.Create(ctx, req2)
|
|
require.NoError(t, err)
|
|
assert.True(t, result2.IsActive)
|
|
|
|
current, err := service.GetCurrent(ctx)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, result2.ID, current.ID)
|
|
assert.Equal(t, 10, current.DailyWithdrawalLimit)
|
|
assert.Equal(t, int64(20000), current.MinWithdrawalAmount)
|
|
assert.Equal(t, int64(200), current.FeeRate)
|
|
assert.True(t, current.IsActive)
|
|
})
|
|
}
|
|
|
|
func TestCommissionWithdrawalSettingService_List(t *testing.T) {
|
|
db, redisClient := testutils.SetupTestDB(t)
|
|
defer testutils.TeardownTestDB(t, db, redisClient)
|
|
|
|
accountStore := postgres.NewAccountStore(db, redisClient)
|
|
settingStore := postgres.NewCommissionWithdrawalSettingStore(db, redisClient)
|
|
|
|
service := commission_withdrawal_setting.New(db, accountStore, settingStore)
|
|
|
|
t.Run("查询配置列表-空结果", func(t *testing.T) {
|
|
ctx := createWithdrawalSettingTestContext(1)
|
|
|
|
req := &model.WithdrawalSettingListReq{
|
|
Page: 1,
|
|
PageSize: 20,
|
|
}
|
|
|
|
result, err := service.List(ctx, req)
|
|
require.NoError(t, err)
|
|
assert.NotNil(t, result)
|
|
assert.GreaterOrEqual(t, result.Total, int64(0))
|
|
})
|
|
|
|
t.Run("查询配置列表-有数据", func(t *testing.T) {
|
|
ctx := createWithdrawalSettingTestContext(1)
|
|
|
|
for i := 0; i < 3; i++ {
|
|
req := &model.CreateWithdrawalSettingReq{
|
|
DailyWithdrawalLimit: i + 1,
|
|
MinWithdrawalAmount: int64((i + 1) * 1000),
|
|
FeeRate: int64((i + 1) * 10),
|
|
}
|
|
_, err := service.Create(ctx, req)
|
|
require.NoError(t, err)
|
|
}
|
|
|
|
listReq := &model.WithdrawalSettingListReq{
|
|
Page: 1,
|
|
PageSize: 20,
|
|
}
|
|
|
|
result, err := service.List(ctx, listReq)
|
|
require.NoError(t, err)
|
|
assert.NotNil(t, result)
|
|
assert.GreaterOrEqual(t, result.Total, int64(3))
|
|
assert.NotEmpty(t, result.Items)
|
|
})
|
|
}
|
|
|
|
func TestCommissionWithdrawalSettingService_GetCurrent(t *testing.T) {
|
|
db, redisClient := testutils.SetupTestDB(t)
|
|
defer testutils.TeardownTestDB(t, db, redisClient)
|
|
|
|
accountStore := postgres.NewAccountStore(db, redisClient)
|
|
settingStore := postgres.NewCommissionWithdrawalSettingStore(db, redisClient)
|
|
|
|
service := commission_withdrawal_setting.New(db, accountStore, settingStore)
|
|
|
|
t.Run("获取当前配置-无配置时应返回错误", func(t *testing.T) {
|
|
ctx := createWithdrawalSettingTestContext(1)
|
|
|
|
_, err := service.GetCurrent(ctx)
|
|
assert.Error(t, err)
|
|
})
|
|
|
|
t.Run("获取当前配置-有配置时正常返回", func(t *testing.T) {
|
|
ctx := createWithdrawalSettingTestContext(1)
|
|
|
|
req := &model.CreateWithdrawalSettingReq{
|
|
DailyWithdrawalLimit: 5,
|
|
MinWithdrawalAmount: 10000,
|
|
FeeRate: 100,
|
|
}
|
|
_, err := service.Create(ctx, req)
|
|
require.NoError(t, err)
|
|
|
|
current, err := service.GetCurrent(ctx)
|
|
require.NoError(t, err)
|
|
assert.NotNil(t, current)
|
|
assert.Equal(t, 5, current.DailyWithdrawalLimit)
|
|
assert.Equal(t, int64(10000), current.MinWithdrawalAmount)
|
|
assert.Equal(t, int64(100), current.FeeRate)
|
|
assert.True(t, current.IsActive)
|
|
})
|
|
}
|