feat: add conversation system action messages
This commit is contained in:
+39
-35
@@ -789,44 +789,48 @@ func TestHandleBroadcastDataDuplicateClientMessage(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestHandleBroadcastDataRejectsUserSystemType(t *testing.T) {
|
||||
numUsers := 2
|
||||
helper := TopicTestHelper{}
|
||||
helper.setUp(t, numUsers, types.TopicCatP2P, "p2p-test", true)
|
||||
defer helper.tearDown()
|
||||
for _, msgType := range []string{"system_event", "system_notice", "system_action"} {
|
||||
t.Run(msgType, func(t *testing.T) {
|
||||
numUsers := 2
|
||||
helper := TopicTestHelper{}
|
||||
helper.setUp(t, numUsers, types.TopicCatP2P, "p2p-test", true)
|
||||
defer helper.tearDown()
|
||||
|
||||
from := helper.uids[0].UserId()
|
||||
msg := &ClientComMessage{
|
||||
Id: "sys-1",
|
||||
AsUser: from,
|
||||
Pub: &MsgClientPub{
|
||||
Topic: "p2p",
|
||||
Head: map[string]any{"x-im-schema": float64(1), "x-im-type": "system_event"},
|
||||
Content: "test",
|
||||
},
|
||||
sess: helper.sessions[0],
|
||||
}
|
||||
from := helper.uids[0].UserId()
|
||||
msg := &ClientComMessage{
|
||||
Id: "sys-1",
|
||||
AsUser: from,
|
||||
Pub: &MsgClientPub{
|
||||
Topic: "p2p",
|
||||
Head: map[string]any{"x-im-schema": float64(1), "x-im-type": msgType},
|
||||
Content: "test",
|
||||
},
|
||||
sess: helper.sessions[0],
|
||||
}
|
||||
|
||||
helper.topic.handleClientMsg(msg)
|
||||
helper.finish()
|
||||
helper.topic.handleClientMsg(msg)
|
||||
helper.finish()
|
||||
|
||||
if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
|
||||
t.Fatal(errorMsgs[0].Ctrl.Text)
|
||||
}
|
||||
if helper.topic.lastID != 0 {
|
||||
t.Errorf("Topic.lastID: expected forbidden publish to keep 0, found %d", helper.topic.lastID)
|
||||
}
|
||||
if len(helper.results[0].messages) != 1 {
|
||||
t.Fatalf("User 1 is expected to receive one ctrl message vs %d received.", len(helper.results[0].messages))
|
||||
}
|
||||
resp := helper.results[0].messages[0].(*ServerComMessage)
|
||||
if resp.Ctrl == nil || resp.Ctrl.Code != 403 {
|
||||
t.Fatalf("User 1 expected 403 ctrl, received %#v", resp)
|
||||
}
|
||||
if len(helper.results[1].messages) != 0 {
|
||||
t.Errorf("User 2 is not expected to receive any messages, %d received.", len(helper.results[1].messages))
|
||||
}
|
||||
if len(helper.hubMessages) != 0 {
|
||||
t.Errorf("Hubhelper.route did not expect any messages, however %d received.", len(helper.hubMessages))
|
||||
if errorMsgs, hasError := helper.hubMessages["__ERROR__"]; hasError {
|
||||
t.Fatal(errorMsgs[0].Ctrl.Text)
|
||||
}
|
||||
if helper.topic.lastID != 0 {
|
||||
t.Errorf("Topic.lastID: expected forbidden publish to keep 0, found %d", helper.topic.lastID)
|
||||
}
|
||||
if len(helper.results[0].messages) != 1 {
|
||||
t.Fatalf("User 1 is expected to receive one ctrl message vs %d received.", len(helper.results[0].messages))
|
||||
}
|
||||
resp := helper.results[0].messages[0].(*ServerComMessage)
|
||||
if resp.Ctrl == nil || resp.Ctrl.Code != 403 {
|
||||
t.Fatalf("User 1 expected 403 ctrl, received %#v", resp)
|
||||
}
|
||||
if len(helper.results[1].messages) != 0 {
|
||||
t.Errorf("User 2 is not expected to receive any messages, %d received.", len(helper.results[1].messages))
|
||||
}
|
||||
if len(helper.hubMessages) != 0 {
|
||||
t.Errorf("Hubhelper.route did not expect any messages, however %d received.", len(helper.hubMessages))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user