Files
pages/internal/server/feeds_capture_preview_test.go
Anya Tokugawa 5321d613b4
Build and publish container images / images (push) Successful in 11m45s
Release container images / release (push) Successful in 21s
feat(feeds): add opt-in Gecko relay and folder shortcuts
Document engine redistribution requirements; exclude upstream engine assets and keep the viewer disabled by default.
2026-11-08 16:14:34 +09:00

55 lines
1.6 KiB
Go

package server
import (
"context"
"encoding/json"
"strings"
"testing"
)
func TestRSSLinkPreference(t *testing.T) {
s, token, domain, actor, _ := feedFixture(t)
p, err := s.store.TaskPreferences(context.Background(), domain, actor)
if err != nil || p.RSSLinkMode != "tab" {
t.Fatal(p.RSSLinkMode, err)
}
p.RSSLinkMode = "embedded"
if w := taskRequest(s, token, "PUT", "preferences", p, ""); w.Code != 200 {
t.Fatal(w.Code, w.Body)
}
p, err = s.store.TaskPreferences(context.Background(), domain, actor)
if err != nil || p.RSSLinkMode != "embedded" {
t.Fatal(p.RSSLinkMode, err)
}
p.RSSLinkMode = "gecko"
if w := taskRequest(s, token, "PUT", "preferences", p, ""); w.Code != 200 {
t.Fatal(w.Code, w.Body)
}
p.RSSLinkMode = "unsafe"
if w := taskRequest(s, token, "PUT", "preferences", p, ""); w.Code != 422 {
t.Fatal(w.Code, w.Body)
}
}
func TestFeedCapturePreview(t *testing.T) {
s, token, _, _, _ := feedFixture(t)
for _, tt := range []struct {
prefix string
status int
}{{"/notes/{YYYY}/{MM}/{DD}/{Subject}", 200}, {"/notes/{unknown}", 422}, {"/a/../b", 422}} {
w := feedRequestTest(s, token, "POST", "capture-preview", map[string]string{"prefix": tt.prefix, "title": "日本語 / test"})
if w.Code != tt.status {
t.Fatal(w.Code, w.Body)
}
if w.Code == 200 {
var data map[string]string
if e := json.Unmarshal(w.Body.Bytes(), &data); e != nil || strings.ContainsAny(data["prefix"], "{}") || !strings.HasSuffix(data["prefix"], "/日本語---test") {
t.Fatal(data, e)
}
}
}
if w := feedRequestTest(s, "", "POST", "capture-preview", map[string]string{"prefix": "/notes"}); w.Code != 401 {
t.Fatal(w.Code)
}
}