feat: 接入商务用户资料和全局统计偏好
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package business
|
||||
|
||||
import (
|
||||
"context"
|
||||
"kra/internal/biz/system"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type preferenceRepoFake struct {
|
||||
value *UserPreference
|
||||
userID uint
|
||||
calls int
|
||||
}
|
||||
|
||||
func (r *preferenceRepoFake) Find(_ context.Context, id uint) (*UserPreference, error) {
|
||||
r.calls++
|
||||
r.userID = id
|
||||
return r.value, nil
|
||||
}
|
||||
func (r *preferenceRepoFake) Save(_ context.Context, id uint, pref UserPreference) error {
|
||||
r.calls++
|
||||
r.userID, r.value = id, &pref
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestPreferenceDefaultsAndCurrentIdentity(t *testing.T) {
|
||||
r := &preferenceRepoFake{}
|
||||
uc := NewUserPreferenceUsecase(r)
|
||||
if _, err := uc.Current(context.Background()); err != ErrUnauthenticated || r.calls != 0 {
|
||||
t.Fatalf("匿名请求访问了偏好: %v", err)
|
||||
}
|
||||
ctx := system.NewActorContext(context.Background(), system.Actor{UserID: 7})
|
||||
pref, err := uc.Current(ctx)
|
||||
if err != nil || !pref.IncludeSubPromote || !pref.IDCardDedup {
|
||||
t.Fatalf("缺省开关应均为开启: %+v %v", pref, err)
|
||||
}
|
||||
if err = uc.UpdateCurrent(ctx, UserPreference{}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r.userID != 7 || r.value.IncludeSubPromote || r.value.IDCardDedup {
|
||||
t.Fatalf("未保存当前用户的关闭值: %+v", r)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user