Add HTTP /v1 MVC, TCP send path, groups with server-side member-avatar collage, object-storage upload, and friends/favorites around the architecture-v3 layout. Co-authored-by: Cursor <cursoragent@cursor.com>
75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
package logic
|
|
|
|
import (
|
|
"errors"
|
|
"strings"
|
|
"testing"
|
|
|
|
"spark-server/internal/module/user/entity"
|
|
"spark-server/internal/pkg/errs"
|
|
)
|
|
|
|
func TestUpdateSparkID(t *testing.T) {
|
|
svc, _, _ := testService(t)
|
|
ctx := t.Context()
|
|
u, err := svc.AuthenticateEmail(ctx, "test04@spark.com", "1", &entity.LoginDevice{DeviceID: 1, DeviceType: entity.DeviceIOS})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
got, err := svc.UpdateSparkID(ctx, u.ID, "alice_ok")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if got.SparkID != "alice_ok" {
|
|
t.Fatalf("%+v", got)
|
|
}
|
|
p := PublicProfile(got)
|
|
if p.UID != u.ID || p.SparkID != "alice_ok" || p.CreateTime == 0 || p.UpdateTime == 0 {
|
|
t.Fatalf("profile %+v", p)
|
|
}
|
|
other, err := svc.AuthenticateEmail(ctx, "test05@spark.com", "1", &entity.LoginDevice{DeviceID: 1, DeviceType: entity.DeviceIOS})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
_, err = svc.UpdateSparkID(ctx, other.ID, "alice_ok")
|
|
if !errors.Is(err, errs.ErrDuplicate) {
|
|
t.Fatalf("dup %v", err)
|
|
}
|
|
_, err = svc.UpdateSparkID(ctx, u.ID, "1bad")
|
|
app, ok := errs.AsAppError(err)
|
|
if !ok || app.Code != errs.ErrInvalidArgument.Code || !strings.Contains(app.Msg, "字母开头") {
|
|
t.Fatalf("invalid %v", err)
|
|
}
|
|
}
|
|
|
|
func TestUpdateProfileFields(t *testing.T) {
|
|
svc, _, _ := testService(t)
|
|
ctx := t.Context()
|
|
u, err := svc.AuthenticateEmail(ctx, "test06@spark.com", "1", &entity.LoginDevice{DeviceID: 1, DeviceType: entity.DeviceWeb})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
nick := "Ada"
|
|
avatar := "oss://avatar/ada"
|
|
gender := entity.GenderFemale
|
|
day := "1994-05-01"
|
|
got, err := svc.UpdateProfile(ctx, u.ID, UpdateProfileInput{
|
|
Nickname: &nick, Avatar: &avatar, Gender: &gender, Birthday: &day,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
p := PublicProfile(got)
|
|
if p.Nickname != "Ada" || p.Avatar != "oss://avatar/ada" || p.Gender != entity.GenderFemale || p.Birthday != "1994-05-01" {
|
|
t.Fatalf("profile %+v", p)
|
|
}
|
|
empty := ""
|
|
got, err = svc.UpdateProfile(ctx, u.ID, UpdateProfileInput{Birthday: &empty})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !got.Birthday.IsZero() {
|
|
t.Fatalf("birthday %v", got.Birthday)
|
|
}
|
|
}
|