新增测试代码规范、修复响应体断言缺失与魔法数字
- AGENTS.md 新增测试代码专项规范:常量、fixture、触发器、HTTP断言、层边界说明 - TestUpdateAllocationExpiryBaseHTTP 补全 PATCH 响应体字段断言 - 四个集成测试文件以 testIDMask 局部常量替换 0x7fffffff 魔法数字 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
package task
|
||||
|
||||
// testIDMask 用于将纳秒时间戳截断为合法的 uint 主键范围,仅限测试用。
|
||||
const testIDMask = testIDMask
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strconv"
|
||||
@@ -34,7 +37,7 @@ func TestAutoPurchasePersistsTermsSnapshotsAndRealnameDecision(t *testing.T) {
|
||||
tx := testutil.NewPostgresTransaction(t)
|
||||
card := createAutoPurchaseCard(t, tx, testCase.realnameStatus)
|
||||
pkg := createAutoPurchasePackage(t, tx, constants.PackageTypeFormal, testCase.defaultBase, 31)
|
||||
shopID := uint(time.Now().UnixNano() & 0x7fffffff)
|
||||
shopID := uint(time.Now().UnixNano() & testIDMask)
|
||||
if testCase.override != nil {
|
||||
allocation := &model.ShopPackageAllocation{ShopID: shopID, PackageID: pkg.ID, CostPrice: 1, RetailPrice: 2, Status: constants.StatusEnabled, ShelfStatus: 1, ExpiryBaseOverride: testCase.override}
|
||||
if err := tx.Create(allocation).Error; err != nil {
|
||||
@@ -186,7 +189,7 @@ func createAutoPurchasePackage(t *testing.T, tx *gorm.DB, packageType, expiryBas
|
||||
}
|
||||
|
||||
func newAutoPurchaseOrder(cardID uint, sellerShopID *uint) *model.Order {
|
||||
orderID := uint(time.Now().UnixNano() & 0x7fffffff)
|
||||
orderID := uint(time.Now().UnixNano() & testIDMask)
|
||||
return &model.Order{Model: gorm.Model{ID: orderID}, OrderNo: "UR55-AUTO-" + strconv.FormatUint(uint64(orderID), 10), OrderType: model.OrderTypeSingleCard, IotCardID: &cardID, SellerShopID: sellerShopID, TotalAmount: 100, Generation: 1}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user