test /v1/feeds POST
parent
4c9e6fbe35
commit
754ceac95c
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -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)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
@ -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 {
|
func (h Handler) serveHTTP(w http.ResponseWriter, r *http.Request) error {
|
||||||
if strings.HasPrefix(r.URL.Path, "/v1/vpntor") {
|
if strings.HasPrefix(r.URL.Path, "/v1/vpntor") {
|
||||||
return h.vpntor(r.Context(), r.Body)
|
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") {
|
} else if strings.HasPrefix(r.URL.Path, "/experimental/ui") {
|
||||||
return h.ui(w, r)
|
return h.ui(w, r)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue