MCPcopy Create free account
hub / github.com/compozy/agh / TestHookEventsHandlerReturnsPayloads

Function TestHookEventsHandlerReturnsPayloads

internal/api/httpapi/hooks_test.go:347–387  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

345}
346
347func TestHookEventsHandlerReturnsPayloads(t *testing.T) {
348 t.Parallel()
349
350 homePaths := newTestHomePaths(t)
351 observer := stubObserver{
352 QueryHookEventsFn: func(_ context.Context, filter hookspkg.EventFilter) ([]hookspkg.EventDescriptor, error) {
353 if filter.Family != hookspkg.HookEventFamilyTool {
354 t.Fatalf("filter.Family = %q, want %q", filter.Family, hookspkg.HookEventFamilyTool)
355 }
356 if !filter.SyncOnly {
357 t.Fatal("filter.SyncOnly = false, want true")
358 }
359 return []hookspkg.EventDescriptor{
360 {
361 Event: hookspkg.HookToolPreCall,
362 Family: hookspkg.HookEventFamilyTool,
363 SyncEligible: true,
364 PayloadSchema: "ToolPreCallPayload",
365 PatchSchema: "ToolCallPatch",
366 },
367 }, nil
368 },
369 }
370
371 engine := newTestRouter(t, newTestHandlers(t, stubSessionManager{}, observer, homePaths))
372 recorder := performRequest(t, engine, http.MethodGet, "/api/hooks/events?family=tool&sync_only=true", nil)
373 if recorder.Code != http.StatusOK {
374 t.Fatalf("status = %d, want %d; body=%s", recorder.Code, http.StatusOK, recorder.Body.String())
375 }
376
377 var response struct {
378 Events []contract.HookEventPayload `json:"events"`
379 }
380 decodeJSONResponse(t, recorder, &response)
381 if got, want := len(response.Events), 1; got != want {
382 t.Fatalf("len(events) = %d, want %d", got, want)
383 }
384 if response.Events[0].Event != hookspkg.HookToolPreCall.String() || !response.Events[0].SyncEligible {
385 t.Fatalf("events[0] = %#v", response.Events[0])
386 }
387}
388
389func TestHookEventsHandlerRejectsInvalidFamily(t *testing.T) {
390 t.Parallel()

Callers

nothing calls this directly

Calls 6

newTestHomePathsFunction · 0.70
newTestRouterFunction · 0.70
newTestHandlersFunction · 0.70
performRequestFunction · 0.70
decodeJSONResponseFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected