From 754ceac95c63b5821a0559a8a80c03c2b291f00d Mon Sep 17 00:00:00 2001 From: Bel LaPointe <153096461+breel-render@users.noreply.github.com> Date: Mon, 28 Apr 2025 22:05:31 -0600 Subject: [PATCH] test /v1/feeds POST --- src/cmd/server/handler/feeds.go | 16 ++++++++ src/cmd/server/handler/feeds_test.go | 61 ++++++++++++++++++++++++++++ src/cmd/server/handler/handler.go | 2 + 3 files changed, 79 insertions(+) create mode 100644 src/cmd/server/handler/feeds.go create mode 100644 src/cmd/server/handler/feeds_test.go diff --git a/src/cmd/server/handler/feeds.go b/src/cmd/server/handler/feeds.go new file mode 100644 index 0000000..53164c4 --- /dev/null +++ b/src/cmd/server/handler/feeds.go @@ -0,0 +1,16 @@ +package handler + +import ( + "io" + "net/http" +) + +func (h Handler) feeds(w http.ResponseWriter, r *http.Request) error { + switch r.Method { + case http.MethodPost: + return io.EOF + default: + http.NotFound(w, r) + } + return nil +} diff --git a/src/cmd/server/handler/feeds_test.go b/src/cmd/server/handler/feeds_test.go new file mode 100644 index 0000000..bb0792b --- /dev/null +++ b/src/cmd/server/handler/feeds_test.go @@ -0,0 +1,61 @@ +package handler_test + +import ( + "context" + "net/http" + "net/http/httptest" + "show-rss/src/cmd/server/handler" + "show-rss/src/db" + "show-rss/src/feeds" + "strings" + "testing" +) + +func TestFeeds(t *testing.T) { + ctx := db.Test(t, context.Background()) + h := handler.New(ctx) + + t.Run("happy", func(t *testing.T) { + w := httptest.NewRecorder() + r := httptest.NewRequest(http.MethodPost, "/v1/feeds", strings.NewReader(`{ + "url": "url", + "cron": "cron", + "pattern": "pattern", + "webhookMethod": "wmethod", + "webhookURL": "wurl", + "webhookBody": "wbody" + }`)) + h.ServeHTTP(w, r) + if w.Code != http.StatusOK { + t.Errorf("(%d) %s", w.Code, w.Body.Bytes()) + } + found := false + if err := feeds.ForEach(ctx, func(f feeds.Feed) error { + t.Logf("%+v", f) + if f.Version.URL != "url" { + t.Errorf("bad url") + } + if f.Version.Cron != "cron" { + t.Errorf("bad cron") + } + if f.Version.Pattern != "pattern" { + t.Errorf("bad pattern") + } + if f.Version.WebhookMethod != "wmethod" { + t.Errorf("bad wmethod") + } + if f.Version.WebhookURL != "wurl" { + t.Errorf("bad wurl") + } + if f.Version.WebhookBody != "wbody" { + t.Errorf("bad wbody") + } + found = true + return nil + }); err != nil { + t.Error(err) + } else if !found { + t.Error(found) + } + }) +} diff --git a/src/cmd/server/handler/handler.go b/src/cmd/server/handler/handler.go index 1d5ffd0..121b16a 100644 --- a/src/cmd/server/handler/handler.go +++ b/src/cmd/server/handler/handler.go @@ -23,6 +23,8 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { func (h Handler) serveHTTP(w http.ResponseWriter, r *http.Request) error { if strings.HasPrefix(r.URL.Path, "/v1/vpntor") { return h.vpntor(r.Context(), r.Body) + } else if strings.HasPrefix(r.URL.Path, "/v1/feeds") { + return h.feeds(w, r) } else if strings.HasPrefix(r.URL.Path, "/experimental/ui") { return h.ui(w, r) } else {