Read user profile display from profile table
This commit is contained in:
@@ -3,7 +3,10 @@
|
||||
|
||||
package mysql
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"database/sql"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNormalizeUserPhone(t *testing.T) {
|
||||
for input, want := range map[string]string{
|
||||
@@ -23,3 +26,34 @@ func TestNormalizeUserPhone(t *testing.T) {
|
||||
t.Fatal("invalid phone unexpectedly accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestProfilePublicFromFields(t *testing.T) {
|
||||
public := profilePublicFromFields(map[string]any{
|
||||
"fn": "旧昵称",
|
||||
"name": "旧昵称",
|
||||
"nickname": "旧昵称",
|
||||
"display_name": "旧昵称",
|
||||
"avatar_file_id": "old_avatar",
|
||||
"photo": "old_photo",
|
||||
"public_account": "usrAccount",
|
||||
}, sql.NullString{String: "新昵称", Valid: true}, sql.NullString{String: "file_avatar_1", Valid: true}).(map[string]any)
|
||||
|
||||
for _, key := range []string{"fn", "name", "nickname", "display_name"} {
|
||||
if public[key] != "新昵称" {
|
||||
t.Fatalf("nickname field %s not overlaid: %#v", key, public)
|
||||
}
|
||||
}
|
||||
if public["avatar_file_id"] != "file_avatar_1" || public["public_account"] != "usrAccount" {
|
||||
t.Fatalf("profile public not overlaid: %#v", public)
|
||||
}
|
||||
|
||||
public = profilePublicFromFields(public, sql.NullString{Valid: true}, sql.NullString{Valid: true}).(map[string]any)
|
||||
for _, key := range []string{"fn", "name", "nickname", "display_name", "avatar_file_id", "photo", "avatar"} {
|
||||
if _, ok := public[key]; ok {
|
||||
t.Fatalf("field %s should be hidden by empty profile value: %#v", key, public)
|
||||
}
|
||||
}
|
||||
if public["public_account"] != "usrAccount" {
|
||||
t.Fatalf("unrelated public field changed: %#v", public)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user