test /v1/feeds POST
This commit is contained in:
61
src/cmd/server/handler/feeds_test.go
Normal file
61
src/cmd/server/handler/feeds_test.go
Normal file
@@ -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)
|
||||
}
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user