feat: add chapter eight call records

This commit is contained in:
richjohnrambo
2026-08-13 16:14:57 +08:00
parent 92d0066a02
commit dfcccbb761
9 changed files with 711 additions and 20 deletions
+39 -4
View File
@@ -351,7 +351,7 @@ func TestHandleBroadcastCall(t *testing.T) {
Pub: &MsgClientPub{
Topic: "p2p",
Head: map[string]any{"webrtc": "started"},
Content: "test",
Content: map[string]any{"callId": "call-1", "callType": "audio"},
NoEcho: true,
},
sess: helper.sessions[0],
@@ -383,11 +383,15 @@ func TestHandleBroadcastCall(t *testing.T) {
if r.Data.Topic != from {
t.Errorf("Response[0] topic: expected '%s', got '%s'", from, r.Data.Topic)
}
if r.Data.Content.(string) != "test" {
t.Errorf("Response[0] content: expected 'test', got '%s'", r.Data.Content.(string))
content := r.Data.Content.(map[string]any)
if content["callId"] != "call-1" || content["callType"] != "audio" || content["video"] != false {
t.Errorf("Response[0] content: unexpected call payload: %#v", content)
}
if r.Data.Head == nil || r.Data.Head["webrtc"].(string) != "started" {
t.Errorf("Response[0] head: expected {'webrtc': 'started'}', got '%s'", r.Data.Content.(string))
t.Errorf("Response[0] head: expected {'webrtc': 'started'}', got %#v", r.Data.Head)
}
if r.Data.Head["x-im-type"] != "call" || r.Data.Head["mime"] != "application/json" {
t.Errorf("Response[0] head: expected normalized call head, got %#v", r.Data.Head)
}
if r.Data.From != from {
t.Errorf("Response[0] from: expected '%s', got '%s'", from, r.Data.From)
@@ -445,6 +449,37 @@ func TestHandleBroadcastCall(t *testing.T) {
}
}
func TestHandleBroadcastCallRequiresStructuredInvite(t *testing.T) {
numUsers := 2
helper := TopicTestHelper{}
helper.setUp(t, numUsers, types.TopicCatP2P, "p2p-test" /*attach=*/, true)
globals.iceServers = []iceServer{{Username: "dummy"}}
defer func() {
globals.iceServers = nil
helper.tearDown()
}()
from := helper.uids[0].UserId()
msg := &ClientComMessage{
AsUser: from,
Original: from,
Pub: &MsgClientPub{
Topic: "p2p",
Head: map[string]any{"webrtc": "started"},
Content: "test",
NoEcho: true,
},
sess: helper.sessions[0],
}
helper.topic.handleClientMsg(msg)
helper.finish()
verifyResponseCodes(helper.results[0], []int{http.StatusBadRequest}, t)
if len(helper.results[1].messages) != 0 {
t.Fatalf("peer: expected 0 messages, got %d", len(helper.results[1].messages))
}
}
func TestHandleBroadcastDataGroup(t *testing.T) {
topicName := "grp-test"
numUsers := 4