test: cover blocked profile visibility
This commit is contained in:
@@ -8767,6 +8767,69 @@ func TestServeIMUserProfile(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestServeIMUserProfileBlockedByMeReturnsMinimalProfile(t *testing.T) {
|
||||||
|
ctrl := gomock.NewController(t)
|
||||||
|
defer ctrl.Finish()
|
||||||
|
expectIMBearer(t, ctrl, "token-1", 7, 1)
|
||||||
|
oldUsers := store.Users
|
||||||
|
oldRelations := store.Relations
|
||||||
|
oldProfiles := store.Profiles
|
||||||
|
users := mock_store.NewMockUsersPersistenceInterface(ctrl)
|
||||||
|
peer := types.Uid(2)
|
||||||
|
users.EXPECT().Get(types.TenantID(7), peer).Return(&types.User{
|
||||||
|
ObjHeader: types.ObjHeader{Id: peer.String()},
|
||||||
|
TenantID: 7,
|
||||||
|
Public: map[string]any{
|
||||||
|
"display_name": "Alice",
|
||||||
|
"nickname": "Alice",
|
||||||
|
"avatar_file_id": "file-1",
|
||||||
|
"signature": "hello",
|
||||||
|
"gender": "female",
|
||||||
|
"region": "Shanghai",
|
||||||
|
"public_account": "alice001",
|
||||||
|
},
|
||||||
|
}, nil)
|
||||||
|
store.Users = users
|
||||||
|
store.Relations = &testRelationsStore{context: &types.RelationshipContext{
|
||||||
|
TenantID: 7,
|
||||||
|
UserID: 1,
|
||||||
|
PeerID: peer,
|
||||||
|
Topic: types.Uid(1).P2PName(peer),
|
||||||
|
Relationship: types.RelationshipBlockedByMe,
|
||||||
|
Remark: "老同事",
|
||||||
|
}}
|
||||||
|
store.Profiles = &testProfilesStore{}
|
||||||
|
defer func() {
|
||||||
|
store.Users = oldUsers
|
||||||
|
store.Relations = oldRelations
|
||||||
|
store.Profiles = oldProfiles
|
||||||
|
}()
|
||||||
|
|
||||||
|
req := httptest.NewRequest(http.MethodGet, "/v1/im/users/"+peer.UserId()+"/profile", nil)
|
||||||
|
req.Header.Set("Authorization", "Bearer token-1")
|
||||||
|
rec := httptest.NewRecorder()
|
||||||
|
|
||||||
|
serveIMUserResource(rec, req)
|
||||||
|
|
||||||
|
if rec.Code != http.StatusOK {
|
||||||
|
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.RelationshipBlockedByMe || data["display_name"] != "老同事" ||
|
||||||
|
data["avatar_file_id"] != "file-1" || data["topic"] == "" {
|
||||||
|
t.Fatalf("unexpected blocked profile response: %#v", data)
|
||||||
|
}
|
||||||
|
capabilities := data["capabilities"].(map[string]any)
|
||||||
|
if capabilities["can_send"] != false || capabilities["can_call"] != false || capabilities["can_add_friend"] != false {
|
||||||
|
t.Fatalf("blocked profile should disable actions: %#v", data)
|
||||||
|
}
|
||||||
|
for _, field := range []string{"signature", "gender", "region", "public_account"} {
|
||||||
|
if _, ok := data[field]; ok {
|
||||||
|
t.Fatalf("blocked profile should omit private field %q: %#v", field, data)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestServeIMUserQRCodes(t *testing.T) {
|
func TestServeIMUserQRCodes(t *testing.T) {
|
||||||
ctrl := gomock.NewController(t)
|
ctrl := gomock.NewController(t)
|
||||||
defer ctrl.Finish()
|
defer ctrl.Finish()
|
||||||
|
|||||||
Reference in New Issue
Block a user