CUB-206: WSClient integration tests with mock WebSocket server #43
@@ -172,7 +172,7 @@ func agentItemToCard(item agentListItem) models.AgentCardData {
|
||||
}
|
||||
channel := item.Channel
|
||||
if channel == "" {
|
||||
channel = "discord"
|
||||
channel = "unknown"
|
||||
}
|
||||
name := item.Name
|
||||
if name == "" {
|
||||
|
||||
105
go-backend/internal/gateway/wsclient_test.go
Normal file
105
go-backend/internal/gateway/wsclient_test.go
Normal file
@@ -0,0 +1,105 @@
|
||||
package gateway
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"code.cubecraftcreations.com/CubeCraft-Creations/Control-Center/go-backend/internal/models"
|
||||
)
|
||||
|
||||
func TestMapSessionStatus(t *testing.T) {
|
||||
tests := []struct {
|
||||
input string
|
||||
expected models.AgentStatus
|
||||
}{
|
||||
{"running", models.AgentStatusActive},
|
||||
{"streaming", models.AgentStatusActive},
|
||||
{"done", models.AgentStatusIdle},
|
||||
{"error", models.AgentStatusError},
|
||||
{"", models.AgentStatusIdle},
|
||||
{"garbage", models.AgentStatusIdle},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
result := mapSessionStatus(tt.input)
|
||||
if result != tt.expected {
|
||||
t.Errorf("mapSessionStatus(%q) = %q, want %q", tt.input, result, tt.expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestAgentItemToCard(t *testing.T) {
|
||||
t.Run("full fields", func(t *testing.T) {
|
||||
item := agentListItem{
|
||||
ID: "dex",
|
||||
Name: "Dex",
|
||||
Role: "backend",
|
||||
Channel: "telegram",
|
||||
}
|
||||
card := agentItemToCard(item)
|
||||
if card.ID != "dex" {
|
||||
t.Errorf("ID = %q, want %q", card.ID, "dex")
|
||||
}
|
||||
if card.DisplayName != "Dex" {
|
||||
t.Errorf("DisplayName = %q, want %q", card.DisplayName, "Dex")
|
||||
}
|
||||
if card.Role != "backend" {
|
||||
t.Errorf("Role = %q, want %q", card.Role, "backend")
|
||||
}
|
||||
if card.Channel != "telegram" {
|
||||
t.Errorf("Channel = %q, want %q", card.Channel, "telegram")
|
||||
}
|
||||
if card.Status != models.AgentStatusIdle {
|
||||
t.Errorf("Status = %q, want %q", card.Status, models.AgentStatusIdle)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("empty fields use defaults", func(t *testing.T) {
|
||||
item := agentListItem{
|
||||
ID: "otto",
|
||||
}
|
||||
card := agentItemToCard(item)
|
||||
if card.ID != "otto" {
|
||||
t.Errorf("ID = %q, want %q", card.ID, "otto")
|
||||
}
|
||||
if card.DisplayName != "otto" {
|
||||
t.Errorf("DisplayName = %q, want %q (should fallback to ID)", card.DisplayName, "otto")
|
||||
}
|
||||
if card.Role != "agent" {
|
||||
t.Errorf("Role = %q, want %q (default)", card.Role, "agent")
|
||||
}
|
||||
if card.Channel != "unknown" {
|
||||
t.Errorf("Channel = %q, want %q (per Grimm requirement)", card.Channel, "unknown")
|
||||
}
|
||||
if card.Status != models.AgentStatusIdle {
|
||||
t.Errorf("Status = %q, want %q", card.Status, models.AgentStatusIdle)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("empty name falls back to ID", func(t *testing.T) {
|
||||
item := agentListItem{
|
||||
ID: "hex",
|
||||
Name: "",
|
||||
Role: "database",
|
||||
}
|
||||
card := agentItemToCard(item)
|
||||
if card.DisplayName != "hex" {
|
||||
t.Errorf("DisplayName = %q, want %q (ID fallback)", card.DisplayName, "hex")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func TestStrPtr(t *testing.T) {
|
||||
s := "hello"
|
||||
p := strPtr(s)
|
||||
if p == nil {
|
||||
t.Fatal("strPtr returned nil")
|
||||
}
|
||||
if *p != s {
|
||||
t.Errorf("strPtr(%q) = %q, want %q", s, *p, s)
|
||||
}
|
||||
|
||||
empty := ""
|
||||
ep := strPtr(empty)
|
||||
if *ep != empty {
|
||||
t.Errorf("strPtr(empty) = %q, want %q", *ep, empty)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user