(t *testing.T)
| 280 | } |
| 281 | |
| 282 | func TestHandler_DrainUnreadOnConnect(t *testing.T) { |
| 283 | hub := NewHub() |
| 284 | defer hub.Close() |
| 285 | |
| 286 | now := time.Now() |
| 287 | store := &mockStore{ |
| 288 | user: newTestUser(), |
| 289 | agent: newTestAgent("user_1"), |
| 290 | messages: []identity.Message{ |
| 291 | { |
| 292 | ID: "msg_1", |
| 293 | AgentID: "agent_test", |
| 294 | Sender: "alice@example.com", |
| 295 | Recipient: "bot@agents.e2a.dev", |
| 296 | Subject: "Hello", |
| 297 | ConversationID: "conv_1", |
| 298 | CreatedAt: now, |
| 299 | }, |
| 300 | { |
| 301 | ID: "msg_2", |
| 302 | AgentID: "agent_test", |
| 303 | Sender: "bob@example.com", |
| 304 | Recipient: "bot@agents.e2a.dev", |
| 305 | Subject: "Hi there", |
| 306 | CreatedAt: now, |
| 307 | }, |
| 308 | }, |
| 309 | } |
| 310 | handler := NewHandler(hub, store) |
| 311 | srv := startServer(t, handler) |
| 312 | |
| 313 | conn, _ := dialWS(t, srv, "bot@agents.e2a.dev", "valid_key") |
| 314 | if conn == nil { |
| 315 | t.Fatal("expected successful WS connection") |
| 316 | } |
| 317 | defer conn.Close(websocket.StatusNormalClosure, "") |
| 318 | |
| 319 | // Read two drained notifications |
| 320 | for i := 0; i < 2; i++ { |
| 321 | ctx, cancel := context.WithTimeout(context.Background(), 2*time.Second) |
| 322 | _, data, err := conn.Read(ctx) |
| 323 | cancel() |
| 324 | if err != nil { |
| 325 | t.Fatalf("read notification %d: %v", i+1, err) |
| 326 | } |
| 327 | |
| 328 | var notif struct { |
| 329 | MessageID string `json:"message_id"` |
| 330 | ConversationID string `json:"conversation_id,omitempty"` |
| 331 | From string `json:"from"` |
| 332 | Recipient string `json:"recipient"` |
| 333 | Subject string `json:"subject"` |
| 334 | } |
| 335 | if err := json.Unmarshal(data, ¬if); err != nil { |
| 336 | t.Fatalf("unmarshal notification %d: %v", i+1, err) |
| 337 | } |
| 338 | |
| 339 | if i == 0 { |
nothing calls this directly
no test coverage detected