feat: directly add customer service friend
Deploy olons-server production / deploy (push) Successful in 3m26s
Deploy olons-server production / deploy (push) Successful in 3m26s
This commit is contained in:
@@ -42,15 +42,15 @@ func (r *repositoryStub) SaveMemberIMIdentity(_ context.Context, identity *store
|
||||
}
|
||||
|
||||
type imStub struct {
|
||||
friendRequests int
|
||||
loginAttempts int
|
||||
resetPasswords int
|
||||
loginError error
|
||||
profileError error
|
||||
friendError error
|
||||
conversation *imclient.Conversation
|
||||
conversationErr error
|
||||
ensureP2PCalls int
|
||||
directFriendAdds int
|
||||
loginAttempts int
|
||||
resetPasswords int
|
||||
loginError error
|
||||
profileError error
|
||||
friendError error
|
||||
conversation *imclient.Conversation
|
||||
conversationErr error
|
||||
ensureP2PCalls int
|
||||
}
|
||||
|
||||
func (i *imStub) Ready() bool { return true }
|
||||
@@ -83,12 +83,12 @@ func (i *imStub) UserProfile(context.Context, string, string) (*imclient.UserPro
|
||||
}
|
||||
return &imclient.UserProfile{UserID: "usr_agent", Relationship: "none"}, nil
|
||||
}
|
||||
func (i *imStub) CreateFriendRequest(context.Context, string, string, string) (*imclient.FriendRequest, error) {
|
||||
i.friendRequests++
|
||||
func (i *imStub) AddFriendDirect(context.Context, string, string) (*imclient.DirectFriendResult, error) {
|
||||
i.directFriendAdds++
|
||||
if i.friendError != nil {
|
||||
return nil, i.friendError
|
||||
}
|
||||
return &imclient.FriendRequest{RequestID: "frq_1", Status: "accepted"}, nil
|
||||
return &imclient.DirectFriendResult{Relationship: "friend", Topic: "p2p-topic"}, nil
|
||||
}
|
||||
func (i *imStub) EnsureP2P(context.Context, string, string, string) (*imclient.Conversation, error) {
|
||||
i.ensureP2PCalls++
|
||||
@@ -116,8 +116,8 @@ func TestOpenSessionAutoAcceptsAndReturnsTopic(t *testing.T) {
|
||||
if session.Topic != "p2p-topic" || session.CurrentUserID != "usr_member" || session.Agent.IMUserID != "usr_agent" {
|
||||
t.Fatalf("unexpected session: %+v", session)
|
||||
}
|
||||
if im.friendRequests != 1 {
|
||||
t.Fatalf("friend requests = %d, want 1", im.friendRequests)
|
||||
if im.directFriendAdds != 1 {
|
||||
t.Fatalf("direct friend adds = %d, want 1", im.directFriendAdds)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,25 +139,25 @@ func TestOpenSessionReturnsSameOriginEndpoints(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOpenSessionReturnsPendingWhenPrivateProfileHidesPendingRelationship(t *testing.T) {
|
||||
func TestOpenSessionDeniesWhenDirectFriendshipIsBlocked(t *testing.T) {
|
||||
repository := &repositoryStub{
|
||||
agent: &store.CustomerService{ID: 3, Name: "客服01", IMTenantCode: "allrich", IMUserID: "usr_agent", OnlineStatus: 1},
|
||||
identity: &store.MemberIMIdentity{TenantID: 0, MemberID: 9, IMTenantCode: "allrich", IMUserID: "usr_member", IMUsername: "member01"},
|
||||
}
|
||||
im := &imStub{
|
||||
profileError: &imclient.Error{Status: 403, Reason: "PERMISSION_DENIED"},
|
||||
friendError: &imclient.Error{Status: 409, Reason: "FRIEND_REQUEST_CONFLICT"},
|
||||
friendError: &imclient.Error{Status: 403, Reason: "PERMISSION_DENIED"},
|
||||
conversationErr: &imclient.Error{Status: 403, Reason: "PERMISSION_DENIED"},
|
||||
}
|
||||
service := New(repository, im, config.AuthConfig{FinanceMasterKey: strings.Repeat("k", 32)})
|
||||
repository.identity.IMPasswordCipher, _ = service.encryptCredential("password")
|
||||
|
||||
_, err := service.OpenSession(context.Background(), 0, 9, 3, SessionRequest{DeviceID: "web-1", Platform: "web"})
|
||||
if !errors.Is(err, ErrRelationPending) {
|
||||
t.Fatalf("error = %v, want ErrRelationPending", err)
|
||||
if !errors.Is(err, ErrRelationDenied) {
|
||||
t.Fatalf("error = %v, want ErrRelationDenied", err)
|
||||
}
|
||||
if im.ensureP2PCalls != 0 || im.friendRequests != 1 {
|
||||
t.Fatalf("ensure p2p calls=%d friend requests=%d, want 0 and 1", im.ensureP2PCalls, im.friendRequests)
|
||||
if im.ensureP2PCalls != 0 || im.directFriendAdds != 1 {
|
||||
t.Fatalf("ensure p2p calls=%d direct friend adds=%d, want 0 and 1", im.ensureP2PCalls, im.directFriendAdds)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user