Capture accumulated application, UI, CLI, regression tests and design documentation changes, including task project mapping and default CalDAV list naming. Keep deployment data, backups, local credentials and build artifacts out of Git. Move the Compose enrollment token to an ignored local environment file.
67 lines
2.2 KiB
Go
67 lines
2.2 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http/httptest"
|
|
"strings"
|
|
"testing"
|
|
)
|
|
|
|
func TestPeriodicalDateRoutes(t *testing.T) {
|
|
s, token, _, _ := periodicalFixture(t)
|
|
for _, kind := range []string{"diary", "blog"} {
|
|
base := "/v/" + kind
|
|
for _, tc := range []struct {
|
|
suffix string
|
|
code int
|
|
location string
|
|
}{
|
|
{"/2026/09", 200, ""}, {"/2026/09/18?category=Work&own", 200, ""},
|
|
{"?month=2026-09", 302, base + "/2026/09"},
|
|
{"?date=2026-09-18&month=2026-09&category=Work&mine=1", 302, base + "/2026/09/18?category=Work&own"},
|
|
{"?date=2024-02-29", 302, base + "/2024/02/29"},
|
|
{"/2026/09?own=1", 302, base + "/2026/09?own"},
|
|
{"/2026/09?mine=1&offset=20", 302, base + "/2026/09?offset=20&own"},
|
|
{"/2026/09/18?month=2026-10", 400, ""},
|
|
{"/2026/02/29", 400, ""}, {"/0000/01", 400, ""},
|
|
{"/2026/9", 400, ""}, {"/2026", 400, ""}, {"/2026/09/18/extra", 400, ""},
|
|
{"?month=2026-09&month=2026-10", 400, ""},
|
|
} {
|
|
w := periodicalRequest(s, token, "GET", base+tc.suffix, "")
|
|
if w.Code != tc.code || w.Header().Get("Location") != tc.location {
|
|
t.Errorf("%s: %d %s", base+tc.suffix, w.Code, w.Header().Get("Location"))
|
|
}
|
|
}
|
|
w := periodicalRequest(s, "", "GET", base+"/2026/09", "")
|
|
if w.Code == 200 {
|
|
t.Fatal("anonymous index")
|
|
}
|
|
w = periodicalRequest(s, token, "POST", base+"/2026/09", `{}`)
|
|
if w.Code < 400 {
|
|
t.Fatal("POST viewer allowed")
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestPeriodicalCanonicalLinks(t *testing.T) {
|
|
s, token, _, _ := periodicalFixture(t)
|
|
w := periodicalRequest(s, token, "POST", "/_/api/v1/extension/content.diary/settings", `{"enabled":true}`)
|
|
if w.Code != 200 {
|
|
t.Fatal(w.Body.String())
|
|
}
|
|
w = periodicalRequest(s, token, "GET", "/v/diary/2026/09?category=Work&own", "")
|
|
body := w.Body.String()
|
|
for _, want := range []string{`/v/diary/2026/09/18?category=Work&own`, `/v/diary/2026/08?category=Work&own`, `name="own"`} {
|
|
if !strings.Contains(body, want) {
|
|
t.Errorf("missing %s", want)
|
|
}
|
|
}
|
|
if strings.Contains(body, "mine=1") || strings.Contains(body, "?month=") {
|
|
t.Fatal("legacy navigation generated")
|
|
}
|
|
r := httptest.NewRequest("GET", "/v/blog/2024/02/29", nil)
|
|
month, day, err := periodicalSelection(r, "blog")
|
|
if err != nil || month != "2024-02" || day != "2024-02-29" {
|
|
t.Fatal(month, day, err)
|
|
}
|
|
}
|