移除所有测试代码和测试要求
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m33s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 6m33s
**变更说明**: - 删除所有 *_test.go 文件(单元测试、集成测试、验收测试、流程测试) - 删除整个 tests/ 目录 - 更新 CLAUDE.md:用"测试禁令"章节替换所有测试要求 - 删除测试生成 Skill (openspec-generate-acceptance-tests) - 删除测试生成命令 (opsx:gen-tests) - 更新 tasks.md:删除所有测试相关任务 **新规范**: - ❌ 禁止编写任何形式的自动化测试 - ❌ 禁止创建 *_test.go 文件 - ❌ 禁止在任务中包含测试相关工作 - ✅ 仅当用户明确要求时才编写测试 **原因**: 业务系统的正确性通过人工验证和生产环境监控保证,测试代码维护成本高于价值。 Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,158 +0,0 @@
|
||||
package enterprise_card
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model"
|
||||
"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"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/middleware"
|
||||
"github.com/break/junhong_cmp_fiber/tests/testutils"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func TestAuthorizationService_BatchAuthorize_BoundCardRejected(t *testing.T) {
|
||||
tx := testutils.NewTestTransaction(t)
|
||||
rdb := testutils.GetTestRedis(t)
|
||||
testutils.CleanTestRedisKeys(t, rdb)
|
||||
|
||||
logger, _ := zap.NewDevelopment()
|
||||
|
||||
enterpriseStore := postgres.NewEnterpriseStore(tx, rdb)
|
||||
iotCardStore := postgres.NewIotCardStore(tx, rdb)
|
||||
authStore := postgres.NewEnterpriseCardAuthorizationStore(tx, rdb)
|
||||
|
||||
service := NewAuthorizationService(enterpriseStore, iotCardStore, authStore, logger)
|
||||
|
||||
shop := &model.Shop{
|
||||
BaseModel: model.BaseModel{Creator: 1, Updater: 1},
|
||||
ShopName: "测试店铺",
|
||||
ShopCode: "TEST_SHOP_001",
|
||||
Level: 1,
|
||||
Status: 1,
|
||||
}
|
||||
require.NoError(t, tx.Create(shop).Error)
|
||||
|
||||
enterprise := &model.Enterprise{
|
||||
BaseModel: model.BaseModel{Creator: 1, Updater: 1},
|
||||
EnterpriseName: "测试企业",
|
||||
EnterpriseCode: "TEST_ENT_001",
|
||||
OwnerShopID: &shop.ID,
|
||||
Status: 1,
|
||||
}
|
||||
require.NoError(t, tx.Create(enterprise).Error)
|
||||
|
||||
carrier := &model.Carrier{CarrierName: "测试运营商", CarrierType: "CMCC", Status: 1}
|
||||
require.NoError(t, tx.Create(carrier).Error)
|
||||
|
||||
unboundCard := &model.IotCard{
|
||||
ICCID: "UNBOUND_CARD_001",
|
||||
CarrierID: carrier.ID,
|
||||
Status: 2,
|
||||
ShopID: &shop.ID,
|
||||
}
|
||||
require.NoError(t, tx.Create(unboundCard).Error)
|
||||
|
||||
boundCard := &model.IotCard{
|
||||
ICCID: "BOUND_CARD_001",
|
||||
CarrierID: carrier.ID,
|
||||
Status: 2,
|
||||
ShopID: &shop.ID,
|
||||
}
|
||||
require.NoError(t, tx.Create(boundCard).Error)
|
||||
|
||||
device := &model.Device{
|
||||
DeviceNo: "TEST_DEVICE_001",
|
||||
DeviceName: "测试设备",
|
||||
Status: 2,
|
||||
ShopID: &shop.ID,
|
||||
}
|
||||
require.NoError(t, tx.Create(device).Error)
|
||||
|
||||
now := time.Now()
|
||||
binding := &model.DeviceSimBinding{
|
||||
DeviceID: device.ID,
|
||||
IotCardID: boundCard.ID,
|
||||
SlotPosition: 1,
|
||||
BindStatus: 1,
|
||||
BindTime: &now,
|
||||
}
|
||||
require.NoError(t, tx.Create(binding).Error)
|
||||
|
||||
ctx := middleware.SetUserContext(context.Background(), &middleware.UserContextInfo{
|
||||
UserID: 1,
|
||||
UserType: constants.UserTypePlatform,
|
||||
ShopID: shop.ID,
|
||||
})
|
||||
|
||||
t.Run("绑定设备的卡被拒绝授权", func(t *testing.T) {
|
||||
req := BatchAuthorizeRequest{
|
||||
EnterpriseID: enterprise.ID,
|
||||
CardIDs: []uint{boundCard.ID},
|
||||
AuthorizerID: 1,
|
||||
AuthorizerType: constants.UserTypePlatform,
|
||||
Remark: "测试授权",
|
||||
}
|
||||
|
||||
err := service.BatchAuthorize(ctx, req)
|
||||
|
||||
require.Error(t, err)
|
||||
appErr, ok := err.(*errors.AppError)
|
||||
require.True(t, ok, "应返回 AppError 类型")
|
||||
assert.Equal(t, errors.CodeCannotAuthorizeBoundCard, appErr.Code)
|
||||
assert.Contains(t, appErr.Message, "已绑定设备")
|
||||
})
|
||||
|
||||
t.Run("未绑定设备的卡可以授权", func(t *testing.T) {
|
||||
req := BatchAuthorizeRequest{
|
||||
EnterpriseID: enterprise.ID,
|
||||
CardIDs: []uint{unboundCard.ID},
|
||||
AuthorizerID: 1,
|
||||
AuthorizerType: constants.UserTypePlatform,
|
||||
Remark: "测试授权",
|
||||
}
|
||||
|
||||
err := service.BatchAuthorize(ctx, req)
|
||||
|
||||
require.NoError(t, err)
|
||||
|
||||
auths, err := authStore.ListByCards(ctx, []uint{unboundCard.ID}, false)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, auths, 1)
|
||||
assert.Equal(t, enterprise.ID, auths[0].EnterpriseID)
|
||||
})
|
||||
|
||||
t.Run("混合卡列表中有绑定卡时整体拒绝", func(t *testing.T) {
|
||||
unboundCard2 := &model.IotCard{
|
||||
ICCID: "UNBOUND_CARD_002",
|
||||
CarrierID: carrier.ID,
|
||||
Status: 2,
|
||||
ShopID: &shop.ID,
|
||||
}
|
||||
require.NoError(t, tx.Create(unboundCard2).Error)
|
||||
|
||||
req := BatchAuthorizeRequest{
|
||||
EnterpriseID: enterprise.ID,
|
||||
CardIDs: []uint{unboundCard2.ID, boundCard.ID},
|
||||
AuthorizerID: 1,
|
||||
AuthorizerType: constants.UserTypePlatform,
|
||||
Remark: "测试授权",
|
||||
}
|
||||
|
||||
err := service.BatchAuthorize(ctx, req)
|
||||
|
||||
require.Error(t, err)
|
||||
appErr, ok := err.(*errors.AppError)
|
||||
require.True(t, ok, "应返回 AppError 类型")
|
||||
assert.Equal(t, errors.CodeCannotAuthorizeBoundCard, appErr.Code)
|
||||
|
||||
auths, err := authStore.ListByCards(ctx, []uint{unboundCard2.ID}, false)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, auths, 0, "混合列表中的未绑定卡也不应被授权")
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user