(t *testing.T)
| 28 | ) |
| 29 | |
| 30 | func 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 | |
| 61 | func TestUpdateHook(t *testing.T) { |
| 62 | router, _, err := setupRouter(t) |
nothing calls this directly
no test coverage detected