30 lines
876 B
Go
30 lines
876 B
Go
package server
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
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)
|
|
}
|
|
}
|