完成客服工作台闭环
This commit is contained in:
@@ -39,3 +39,31 @@ func TestBroadcastToSessionRestrictsRecipients(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestBroadcastToVisitorRestrictsSession(t *testing.T) {
|
||||
hub := NewHub()
|
||||
go hub.Run()
|
||||
|
||||
sessionID := uint(21)
|
||||
otherSessionID := uint(22)
|
||||
visitor := &Client{TenantID: 1, Kind: "visitor", SessionID: &sessionID, Send: make(chan []byte, 1)}
|
||||
otherVisitor := &Client{TenantID: 1, Kind: "visitor", SessionID: &otherSessionID, Send: make(chan []byte, 1)}
|
||||
agent := &Client{TenantID: 1, Kind: "agent", UserID: 1, Role: "agent", Send: make(chan []byte, 1)}
|
||||
for _, client := range []*Client{visitor, otherVisitor, agent} {
|
||||
hub.register <- client
|
||||
}
|
||||
|
||||
hub.BroadcastToVisitor(1, sessionID, []byte(`{"type":"typing"}`))
|
||||
select {
|
||||
case <-visitor.Send:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("目标访客未收到输入状态")
|
||||
}
|
||||
for _, client := range []*Client{otherVisitor, agent} {
|
||||
select {
|
||||
case <-client.Send:
|
||||
t.Fatalf("无关客户端收到访客状态:%+v", client)
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user