MCPcopy Create free account
hub / github.com/devaccuracy/ledgerforge / TestRegisterHook

Function TestRegisterHook

api/hooks_test.go:30–59  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

28)
29
30func TestRegisterHook(t *testing.T) {
31 router, _, err := setupRouter(t)
32 if err != nil {
33 t.Fatalf("Failed to setup router: %v", err)
34 }
35
36 t.Run("Invalid JSON", func(t *testing.T) {
37 req := httptest.NewRequest("POST", "/hooks", bytes.NewReader([]byte("invalid json")))
38 req.Header.Set("Content-Type", "application/json")
39 resp := httptest.NewRecorder()
40 router.ServeHTTP(resp, req)
41 assert.Equal(t, http.StatusBadRequest, resp.Code)
42 })
43
44 t.Run("Valid hook registration", func(t *testing.T) {
45 hook := hooks.Hook{
46 Name: "Test Hook",
47 URL: "https://example.com/webhook",
48 Type: hooks.PreTransaction,
49 Active: true,
50 Timeout: 30,
51 }
52 payloadBytes, _ := request.ToJsonReq(&hook)
53 req := httptest.NewRequest("POST", "/hooks", payloadBytes)
54 req.Header.Set("Content-Type", "application/json")
55 resp := httptest.NewRecorder()
56 router.ServeHTTP(resp, req)
57 assert.Equal(t, http.StatusCreated, resp.Code)
58 })
59}
60
61func TestUpdateHook(t *testing.T) {
62 router, _, err := setupRouter(t)

Callers

nothing calls this directly

Calls 3

ToJsonReqFunction · 0.92
setupRouterFunction · 0.85
SetMethod · 0.65

Tested by

no test coverage detected