feat: 添加独立其他设置菜单及有效端参数保存
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package business
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"kra/internal/biz/business"
|
||||
"kra/internal/service/dto"
|
||||
)
|
||||
|
||||
type settingsUsecaseFake struct{ calls int }
|
||||
|
||||
func (f *settingsUsecaseFake) Get(context.Context) (*business.OtherSettings, error) {
|
||||
value := business.DefaultOtherSettings()
|
||||
return &value, nil
|
||||
}
|
||||
func (f *settingsUsecaseFake) Save(_ context.Context, value business.OtherSettings) (*business.OtherSettings, error) {
|
||||
f.calls++
|
||||
return &value, nil
|
||||
}
|
||||
|
||||
func TestOtherSettingsServiceRequiresBothValidFields(t *testing.T) {
|
||||
f := &settingsUsecaseFake{}
|
||||
s := &OtherSettingsService{uc: f}
|
||||
zero, days, negative := int64(0), int64(30), int64(-1)
|
||||
for _, req := range []*dto.OtherSettingsRequest{nil, {}, {Amount: &zero}, {Days: &days}, {Amount: &negative, Days: &days}, {Amount: &zero, Days: &zero}} {
|
||||
if _, err := s.Save(context.Background(), req); err != business.ErrOtherSettingsInput {
|
||||
t.Fatalf("边界校验错误: %v", err)
|
||||
}
|
||||
}
|
||||
if f.calls != 0 {
|
||||
t.Fatal("无效输入不得进入用例")
|
||||
}
|
||||
res, err := s.Save(context.Background(), &dto.OtherSettingsRequest{Amount: &zero, Days: &days})
|
||||
if err != nil || res.Amount != 0 || res.Days != 30 || res.Defaults.Amount != 3000 || f.calls != 1 {
|
||||
t.Fatalf("DTO 转换或零值错误: %+v %v", res, err)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user