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

Function TestHandleAgentActivity_WithMessages

internal/auth/auth_test.go:114–151  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

112}
113
114func TestHandleAgentActivity_WithMessages(t *testing.T) {
115 ua, store, token := setupUserAuth(t)
116 ctx := context.Background()
117
118 user, _ := store.GetUserSession(ctx, token)
119 store.ClaimOrCreateDomain(ctx, "active.example.com", user.ID)
120 agent, _ := store.CreateAgent(ctx, "agent@active.example.com", "active.example.com", "", "https://example.com/webhook", "", user.ID)
121
122 // Create some activity ("" id lets the store generate one).
123 store.CreateInboundMessage(ctx, "", agent.ID, "alice@gmail.com", "bot@active.example.com", "", "Hello", "", "", nil, nil, nil, false, "", nil, nil, nil, identity.InboundScreening{})
124 store.CreateOutboundMessage(ctx, agent.ID, []string{"alice@gmail.com"}, nil, nil, "Re: Hello", "reply", "smtp", "", "", nil)
125 store.CreateInboundMessage(ctx, "", agent.ID, "bob@gmail.com", "bot@active.example.com", "", "Hi", "", "", nil, nil, nil, false, "", nil, nil, nil, identity.InboundScreening{})
126
127 req := authedRequest("GET", "/api/dashboard/agents/agent%40active.example.com/activity", token)
128 w := httptest.NewRecorder()
129 ua.HandleAgentActivity(w, req)
130
131 if w.Code != http.StatusOK {
132 t.Fatalf("status = %d, want 200", w.Code)
133 }
134
135 var activity []identity.Message
136 json.NewDecoder(w.Body).Decode(&activity)
137 if len(activity) != 3 {
138 t.Fatalf("expected 3 activities, got %d", len(activity))
139 }
140
141 // Most recent first
142 if activity[0].Direction != "inbound" || activity[0].Subject != "Hi" {
143 t.Errorf("first entry: direction=%q subject=%q", activity[0].Direction, activity[0].Subject)
144 }
145 if activity[1].Direction != "outbound" || activity[1].Method != "smtp" {
146 t.Errorf("second entry: direction=%q method=%q", activity[1].Direction, activity[1].Method)
147 }
148 if activity[2].Direction != "inbound" || activity[2].Subject != "Hello" {
149 t.Errorf("third entry: direction=%q subject=%q", activity[2].Direction, activity[2].Subject)
150 }
151}
152
153// --- API key endpoints (Item #3) ---
154

Callers

nothing calls this directly

Calls 8

setupUserAuthFunction · 0.85
authedRequestFunction · 0.85
GetUserSessionMethod · 0.80
ClaimOrCreateDomainMethod · 0.80
CreateAgentMethod · 0.80
CreateOutboundMessageMethod · 0.80
HandleAgentActivityMethod · 0.80
CreateInboundMessageMethod · 0.65

Tested by

no test coverage detected