fix: 换货原因长度上限放宽到 500 字
从微信复制的多行换货说明常超过 100 字,创建换货单时报参数验证失败。 请求校验与模型字段长度同步改为 500;生产库已手动执行 ALTER,迁移文件随 Iteration/8-11 编号补充。 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
34
internal/model/dto/exchange_dto_test.go
Normal file
34
internal/model/dto/exchange_dto_test.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package dto
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/go-playground/validator/v10"
|
||||
)
|
||||
|
||||
// 换货原因按字符计数,上限 500:从微信复制的多行说明(含换行)不超过 500 字都应通过校验。
|
||||
func TestCreateExchangeRequest_ExchangeReasonLength(t *testing.T) {
|
||||
validate := validator.New()
|
||||
multiLine := "862639070766110(门店:862639070766110机头,862639070743218后盖)\n\n" +
|
||||
"862639070743218(厂家:862639070766110后盖,862639070743218机头)\n\n这两台后盖机头窜了。"
|
||||
cases := []struct {
|
||||
name string
|
||||
reason string
|
||||
wantErr bool
|
||||
}{
|
||||
{name: "多行说明124字", reason: multiLine, wantErr: false},
|
||||
{name: "500个中文字", reason: strings.Repeat("换", 500), wantErr: false},
|
||||
{name: "501个中文字", reason: strings.Repeat("换", 501), wantErr: true},
|
||||
{name: "空", reason: "", wantErr: true},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
req := CreateExchangeRequest{OldAssetType: "device", OldIdentifier: "862639070743218", ExchangeReason: tc.reason}
|
||||
err := validate.Struct(req)
|
||||
if (err != nil) != tc.wantErr {
|
||||
t.Fatalf("wantErr=%v, err=%v", tc.wantErr, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user