feat: add im group mention flows
This commit is contained in:
@@ -761,6 +761,73 @@ func TestHandleBroadcastDataRejectsUserSystemType(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleBroadcastDataRejectsMentionAllByMember(t *testing.T) {
|
||||
numUsers := 2
|
||||
helper := TopicTestHelper{}
|
||||
helper.setUp(t, numUsers, types.TopicCatGrp, "grp-test", true)
|
||||
defer helper.tearDown()
|
||||
pud := helper.topic.perUser[helper.uids[0]]
|
||||
pud.modeWant = types.ModeCPublic
|
||||
pud.modeGiven = types.ModeCPublic
|
||||
helper.topic.perUser[helper.uids[0]] = pud
|
||||
|
||||
from := helper.uids[0].UserId()
|
||||
msg := &ClientComMessage{
|
||||
Id: "mention-all-1",
|
||||
AsUser: from,
|
||||
Pub: &MsgClientPub{
|
||||
Topic: "grp-test",
|
||||
Head: map[string]any{"mention_all": true},
|
||||
Content: "hello all",
|
||||
},
|
||||
sess: helper.sessions[0],
|
||||
}
|
||||
|
||||
helper.topic.handleClientMsg(msg)
|
||||
helper.finish()
|
||||
|
||||
verifyResponseCodes(helper.results[0], []int{http.StatusForbidden}, t)
|
||||
if helper.topic.lastID != 0 {
|
||||
t.Fatalf("Topic.lastID: expected 0, got %d", helper.topic.lastID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHandleBroadcastDataFiltersInvalidMentions(t *testing.T) {
|
||||
numUsers := 2
|
||||
helper := TopicTestHelper{}
|
||||
helper.setUp(t, numUsers, types.TopicCatGrp, "grp-test", true)
|
||||
defer helper.tearDown()
|
||||
helper.mm.EXPECT().Save(types.TenantID(1), gomock.Any(), gomock.Any(), gomock.Any()).
|
||||
DoAndReturn(func(_ types.TenantID, msg *types.Message, _ []string, _ bool) (*types.MessageSaveResult, error) {
|
||||
mentions, ok := msg.Head["mentions"].([]map[string]any)
|
||||
if !ok || len(mentions) != 1 || mentions[0]["user_id"] != helper.uids[1].UserId() {
|
||||
t.Fatalf("unexpected normalized mentions: %#v", msg.Head["mentions"])
|
||||
}
|
||||
return &types.MessageSaveResult{SeqId: 1, MarkedReadBySender: true}, nil
|
||||
})
|
||||
|
||||
from := helper.uids[0].UserId()
|
||||
msg := &ClientComMessage{
|
||||
Id: "mention-1",
|
||||
AsUser: from,
|
||||
Pub: &MsgClientPub{
|
||||
Topic: "grp-test",
|
||||
Head: map[string]any{"mentions": []any{
|
||||
map[string]any{"user_id": helper.uids[1].UserId(), "offset": 0, "length": 2},
|
||||
map[string]any{"user_id": types.Uid(99).UserId(), "offset": 3, "length": 2},
|
||||
}},
|
||||
Content: "hi",
|
||||
NoEcho: true,
|
||||
},
|
||||
sess: helper.sessions[0],
|
||||
}
|
||||
|
||||
helper.topic.handleClientMsg(msg)
|
||||
helper.finish()
|
||||
|
||||
verifyResponseCodes(helper.results[0], []int{http.StatusAccepted}, t)
|
||||
}
|
||||
|
||||
func TestHandleBroadcastDataInactiveTopic(t *testing.T) {
|
||||
numUsers := 2
|
||||
helper := TopicTestHelper{}
|
||||
|
||||
Reference in New Issue
Block a user