53 lines
1.4 KiB
Go
53 lines
1.4 KiB
Go
package api
|
|
|
|
// #256: renamed page routes; old URLs redirect.
|
|
import (
|
|
"palette/internal/store"
|
|
"palette/internal/web"
|
|
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
)
|
|
|
|
func TestRenamedPageRoutes(t *testing.T) {
|
|
globalLimiter = newLimiter() // fresh rate-limit buckets
|
|
st, err := store.OpenStore(":memory:")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
ui, err := web.New()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
cfg := Config{MaxTextBytes: 5 * 1024 * 1024}
|
|
ss := NewTestSettingsStore(t, cfg)
|
|
globalSettingsFn = ss.get
|
|
t.Cleanup(func() { globalSettingsFn = nil })
|
|
a := &apiServer{store: st, cfg: cfg, ui: ui, settings: ss, adminKey: "test-admin-key"}
|
|
h := a.routes()
|
|
|
|
// new routes render pages
|
|
for _, path := range []string{"/public", "/saved"} {
|
|
req := httptest.NewRequest("GET", path, nil)
|
|
rec := httptest.NewRecorder()
|
|
h.ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusOK {
|
|
t.Fatalf("GET %s: %d, want 200", path, rec.Code)
|
|
}
|
|
}
|
|
|
|
// old routes redirect
|
|
for _, tc := range [][2]string{{"/history", "/public"}, {"/mine", "/saved"}, {"/", "/public"}} {
|
|
req := httptest.NewRequest("GET", tc[0], nil)
|
|
rec := httptest.NewRecorder()
|
|
h.ServeHTTP(rec, req)
|
|
if rec.Code != http.StatusMovedPermanently && rec.Code != http.StatusFound {
|
|
t.Fatalf("GET %s: %d, want redirect", tc[0], rec.Code)
|
|
}
|
|
if loc := rec.Header().Get("Location"); loc != tc[1] {
|
|
t.Fatalf("GET %s redirects to %s, want %s", tc[0], loc, tc[1])
|
|
}
|
|
}
|
|
}
|