MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / TestHandler_SendAfterConnect

Function TestHandler_SendAfterConnect

internal/ws/handler_test.go:405–438  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

403}
404
405func TestHandler_SendAfterConnect(t *testing.T) {
406 hub := NewHub()
407 defer hub.Close()
408 store := &mockStore{
409 user: newTestUser(),
410 agent: newTestAgent("user_1"),
411 }
412 handler := NewHandler(hub, store)
413 srv := startServer(t, handler)
414
415 conn, _ := dialWS(t, srv, "bot@agents.e2a.dev", "valid_key")
416 if conn == nil {
417 t.Fatal("expected successful WS connection")
418 }
419 defer conn.Close(websocket.StatusNormalClosure, "")
420
421 waitConnected(t, hub, "agent_test")
422
423 // Send a message through the hub after connection
424 msg := `{"message_id":"msg_live","from":"charlie@example.com","subject":"Live"}`
425 if !hub.Send("agent_test", []byte(msg)) {
426 t.Fatal("expected send to succeed")
427 }
428
429 ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second)
430 defer cancel()
431 _, data, err := conn.Read(ctx)
432 if err != nil {
433 t.Fatalf("read: %v", err)
434 }
435 if string(data) != msg {
436 t.Fatalf("got %q, want %q", data, msg)
437 }
438}
439
440func TestBuildNotification(t *testing.T) {
441 now := time.Date(2026, 3, 27, 10, 0, 0, 0, time.UTC)

Callers

nothing calls this directly

Calls 9

CloseMethod · 0.95
SendMethod · 0.95
NewHubFunction · 0.85
newTestUserFunction · 0.85
newTestAgentFunction · 0.85
NewHandlerFunction · 0.85
startServerFunction · 0.85
dialWSFunction · 0.85
waitConnectedFunction · 0.85

Tested by

no test coverage detected