feat: expose account fields in user profiles
This commit is contained in:
+56
-3
@@ -3821,6 +3821,11 @@ func TestServeIMMeProfile(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
expectIMBearer(t, ctrl, "token-1", 7, 42)
|
||||
oldUsers := store.Users
|
||||
users := mock_store.NewMockUsersPersistenceInterface(ctrl)
|
||||
users.EXPECT().Get(types.TenantID(7), types.Uid(42)).Return(&types.User{Phone: "+8613800138000", Username: "gcharles7"}, nil)
|
||||
store.Users = users
|
||||
defer func() { store.Users = oldUsers }()
|
||||
oldProfiles := store.Profiles
|
||||
profiles := &testProfilesStore{}
|
||||
store.Profiles = profiles
|
||||
@@ -3835,11 +3840,57 @@ func TestServeIMMeProfile(t *testing.T) {
|
||||
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
data := decodeIMHTTPResponse(t, rec).Data.(map[string]any)
|
||||
if data["nickname"] != "新昵称" || data["email"] != "me@example.com" || data["version"].(float64) != 2 {
|
||||
if data["nickname"] != "新昵称" || data["email"] != "me@example.com" || data["version"].(float64) != 2 ||
|
||||
data["phone_mask"] != "138****8000" || data["username"] != "gcharles7" {
|
||||
t.Fatalf("unexpected profile: %#v", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeIMMeProfileGetPhoneMask(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
expectIMBearer(t, ctrl, "token-1", 7, 42)
|
||||
oldUsers := store.Users
|
||||
users := mock_store.NewMockUsersPersistenceInterface(ctrl)
|
||||
users.EXPECT().Get(types.TenantID(7), types.Uid(42)).Return(&types.User{Phone: "+8613600003333", Username: "gcharles7"}, nil)
|
||||
store.Users = users
|
||||
defer func() { store.Users = oldUsers }()
|
||||
oldProfiles := store.Profiles
|
||||
store.Profiles = &testProfilesStore{}
|
||||
defer func() { store.Profiles = oldProfiles }()
|
||||
|
||||
req := httptest.NewRequest(http.MethodGet, "/v1/im/me/profile", nil)
|
||||
req.Header.Set("Authorization", "Bearer token-1")
|
||||
rec := httptest.NewRecorder()
|
||||
serveIMMeProfile(rec, req)
|
||||
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status=%d body=%s", rec.Code, rec.Body.String())
|
||||
}
|
||||
data := decodeIMHTTPResponse(t, rec).Data.(map[string]any)
|
||||
if data["phone_mask"] != "136****3333" || data["username"] != "gcharles7" {
|
||||
t.Fatalf("unexpected account fields: %#v body=%s", data, rec.Body.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestMaskIMProfilePhone(t *testing.T) {
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
phone string
|
||||
want string
|
||||
}{
|
||||
{name: "empty", phone: "", want: ""},
|
||||
{name: "mainland e164", phone: "+8613600003333", want: "136****3333"},
|
||||
{name: "mainland local", phone: "13600003333", want: "136****3333"},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
if got := maskIMProfilePhone(tc.phone); got != tc.want {
|
||||
t.Fatalf("maskIMProfilePhone(%q)=%q, want %q", tc.phone, got, tc.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeIMMePrivacy(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
@@ -8907,6 +8958,7 @@ func TestServeIMUserProfile(t *testing.T) {
|
||||
users.EXPECT().Get(types.TenantID(7), peer).Return(&types.User{
|
||||
ObjHeader: types.ObjHeader{Id: peer.String()},
|
||||
TenantID: 7,
|
||||
Username: "alice7",
|
||||
Public: map[string]any{"display_name": "Alice", "nickname": "Alice", "avatar_file_id": "file-1", "signature": "hello"},
|
||||
}, nil)
|
||||
store.Users = users
|
||||
@@ -8936,7 +8988,7 @@ func TestServeIMUserProfile(t *testing.T) {
|
||||
t.Fatalf("status: got %d, want %d; body=%s", rec.Code, http.StatusOK, rec.Body.String())
|
||||
}
|
||||
data := decodeIMHTTPResponse(t, rec).Data.(map[string]any)
|
||||
if data["relationship"] != types.RelationshipFriend || data["signature"] != "hello" || data["topic"] == "" {
|
||||
if data["relationship"] != types.RelationshipFriend || data["signature"] != "hello" || data["topic"] == "" || data["username"] != "alice7" {
|
||||
t.Fatalf("unexpected profile response: %#v", data)
|
||||
}
|
||||
if data["display_name"] != "老同事" || data["remark"] != "老同事" {
|
||||
@@ -8959,6 +9011,7 @@ func TestServeIMUserProfileBlockedByMeReturnsMinimalProfile(t *testing.T) {
|
||||
users.EXPECT().Get(types.TenantID(7), peer).Return(&types.User{
|
||||
ObjHeader: types.ObjHeader{Id: peer.String()},
|
||||
TenantID: 7,
|
||||
Username: "alice7",
|
||||
Public: map[string]any{
|
||||
"display_name": "Alice",
|
||||
"nickname": "Alice",
|
||||
@@ -8996,7 +9049,7 @@ func TestServeIMUserProfileBlockedByMeReturnsMinimalProfile(t *testing.T) {
|
||||
}
|
||||
data := decodeIMHTTPResponse(t, rec).Data.(map[string]any)
|
||||
if data["relationship"] != types.RelationshipBlockedByMe || data["display_name"] != "老同事" ||
|
||||
data["avatar_file_id"] != "file-1" || data["topic"] == "" {
|
||||
data["avatar_file_id"] != "file-1" || data["topic"] == "" || data["username"] != "alice7" {
|
||||
t.Fatalf("unexpected blocked profile response: %#v", data)
|
||||
}
|
||||
capabilities := data["capabilities"].(map[string]any)
|
||||
|
||||
Reference in New Issue
Block a user