Merge branch 'dev' of https://git.118im.com/im_team/im_server into dev
This commit is contained in:
+44
-1
@@ -283,6 +283,8 @@ type testGroupBusinessStore struct {
|
||||
updatedSettings types.GroupSettingsPatch
|
||||
updatedMembers []types.GroupMemberPatch
|
||||
updatedRoleMode types.AccessMode
|
||||
leftTopic string
|
||||
leftUID types.Uid
|
||||
updateSettingsErr error
|
||||
updateMemberErr error
|
||||
}
|
||||
@@ -546,7 +548,9 @@ func (s *testGroupBusinessStore) InviteMember(_ types.TenantID, topic string, in
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (s *testGroupBusinessStore) Leave(_ types.TenantID, _ string, _ types.Uid, _ time.Time) error {
|
||||
func (s *testGroupBusinessStore) Leave(_ types.TenantID, topic string, uid types.Uid, _ time.Time) error {
|
||||
s.leftTopic = topic
|
||||
s.leftUID = uid
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -3127,6 +3131,45 @@ func TestServeIMGroupMemberReturnsSingleSnapshot(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeIMGroupMemberDeleteRemovesMember(t *testing.T) {
|
||||
ctrl := gomock.NewController(t)
|
||||
defer ctrl.Finish()
|
||||
expectIMBearer(t, ctrl, "token-1", 7, 42)
|
||||
oldSubs := store.Subs
|
||||
oldGroupBusiness := store.GroupBusiness
|
||||
subs := mock_store.NewMockSubsPersistenceInterface(ctrl)
|
||||
store.Subs = subs
|
||||
target := types.Uid(101)
|
||||
groupStore := &testGroupBusinessStore{member: &types.GroupMember{
|
||||
ID: 101, Topic: "grpMention", UserID: target, Role: types.GroupMemberRoleMember,
|
||||
MemberStatus: types.GroupMemberStatusActive, Version: 3,
|
||||
}}
|
||||
store.GroupBusiness = groupStore
|
||||
t.Cleanup(func() {
|
||||
store.Subs = oldSubs
|
||||
store.GroupBusiness = oldGroupBusiness
|
||||
})
|
||||
|
||||
ownerSub := &types.Subscription{TenantID: 7, User: types.Uid(42).String(), Topic: "grpMention", ModeWant: types.ModeCFull, ModeGiven: types.ModeCFull}
|
||||
subs.EXPECT().Get(types.TenantID(7), "grpMention", types.Uid(42), false).Return(ownerSub, nil)
|
||||
|
||||
req := httptest.NewRequest(http.MethodDelete, "/v1/im/groups/grpMention/members/"+target.UserId(), nil)
|
||||
req.Header.Set("Authorization", "Bearer token-1")
|
||||
rec := httptest.NewRecorder()
|
||||
serveIMGroupResource(rec, req)
|
||||
|
||||
if rec.Code != http.StatusOK {
|
||||
t.Fatalf("status: got %d, want %d; body=%s", rec.Code, http.StatusOK, rec.Body.String())
|
||||
}
|
||||
if groupStore.leftTopic != "grpMention" || groupStore.leftUID != target {
|
||||
t.Fatalf("member was not removed: topic=%q uid=%s", groupStore.leftTopic, groupStore.leftUID.UserId())
|
||||
}
|
||||
data := decodeIMHTTPResponse(t, rec).Data.(map[string]any)
|
||||
if data["topic"] != "grpMention" || data["user_id"] != target.UserId() || data["status"] != "left" {
|
||||
t.Fatalf("unexpected delete response: %#v", data)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGroupMemberPayloadUserIDFormats(t *testing.T) {
|
||||
raw := types.Uid(101)
|
||||
fromRaw := groupMemberPayload(types.Subscription{
|
||||
|
||||
Reference in New Issue
Block a user