feat: links settings and outbound rules in resolve
- migration 202610280003: settings links_new_tab (default on),
nofollow_domains and sponsored_domains; robots llms_enabled and
llms_intro (used by the llms.txt commit)
- SEO settings Links tab: the new-tab switch and the two domain lists,
one domain per line, lowercased, refused with settings.domain_invalid
naming the line; writable through seo_update_settings
- the resolve answer of an ok page carries outbound {new_tab,
nofollow_domains, sponsored_domains}; no existing key changes
This commit is contained in:
@@ -330,3 +330,57 @@ func TestRouteReport(t *testing.T) {
|
||||
t.Fatalf("missing=only after the page is reported again = %s", again)
|
||||
}
|
||||
}
|
||||
|
||||
// outboundOf reads the resolve answer's outbound rules.
|
||||
func outboundOf(t *testing.T, got map[string]any) map[string]any {
|
||||
t.Helper()
|
||||
out, ok := got["outbound"].(map[string]any)
|
||||
if !ok {
|
||||
t.Fatalf("resolve answer without outbound: %v", got)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// TestSettingsLinks covers the Links tab (UI-SPEC C20, D-83, P33-16): the
|
||||
// new-tab switch on by default, the domain lists with their line-numbered
|
||||
// refusal, the MCP-writable keys and outbound in the resolve answer.
|
||||
func TestSettingsLinks(t *testing.T) {
|
||||
env := bootEnv(t)
|
||||
token := env.admin(t, true)
|
||||
findField(t, env.formSchema(t, token, "golem15/seo/settings"), "nofollow_domains")
|
||||
env.createPage(t, token, map[string]any{"title": "About", "slug": "about", "published": true})
|
||||
|
||||
out := outboundOf(t, env.resolve(t, "/pages/about"))
|
||||
if out["new_tab"] != true || len(out["nofollow_domains"].([]any)) != 0 || len(out["sponsored_domains"].([]any)) != 0 {
|
||||
t.Fatalf("default outbound = %v, want new_tab true and no domains", out)
|
||||
}
|
||||
if got := env.resolve(t, "/pages/missing"); got["outbound"] != nil {
|
||||
t.Fatalf("a not_found answer carries outbound: %v", got)
|
||||
}
|
||||
|
||||
rec := env.call(t, http.MethodPut, adminAPI("/golem15/seo/settings/1"), token, map[string]any{"nofollow_domains": "example.com\nhttps://x.pl/a"})
|
||||
if rec.Code != http.StatusUnprocessableEntity || !strings.Contains(rec.Body.String(), `Line 2: “https://x.pl/a” is not a domain.`) {
|
||||
t.Fatalf("admin save of a bad domain = %d %s, want 422 naming line 2", rec.Code, rec.Body.String())
|
||||
}
|
||||
env.expect(t, http.StatusOK, http.MethodPut, adminAPI("/golem15/seo/settings/1"), token, map[string]any{"nofollow_domains": "Example.com\n\n shop.example.org "})
|
||||
var stored string
|
||||
if err := env.db.Raw(`SELECT nofollow_domains FROM golem15_seo_settings WHERE id = 1`).Scan(&stored).Error; err != nil || stored != "example.com\nshop.example.org" {
|
||||
t.Fatalf("stored nofollow_domains = %q err=%v", stored, err)
|
||||
}
|
||||
|
||||
api := "/_seo/api/v1/settings"
|
||||
rec = env.call(t, http.MethodPut, api, token, map[string]any{"sponsored_domains": "partner.pl\nnot a domain"})
|
||||
if rec.Code != http.StatusUnprocessableEntity || !strings.Contains(rec.Body.String(), "sponsored_domains") || !strings.Contains(rec.Body.String(), "Line 2") {
|
||||
t.Fatalf("API save of a bad domain = %d %s", rec.Code, rec.Body.String())
|
||||
}
|
||||
env.expect(t, http.StatusOK, http.MethodPut, api, token, map[string]any{"sponsored_domains": "partner.pl", "links_new_tab": false})
|
||||
show := env.expect(t, http.StatusOK, http.MethodGet, api, token, nil).Body.String()
|
||||
if !jsonContains(show, `"links_new_tab":false`) || !jsonContains(show, `"sponsored_domains":"partner.pl"`) {
|
||||
t.Fatalf("settings = %s", show)
|
||||
}
|
||||
out = outboundOf(t, env.resolve(t, "/pages/about"))
|
||||
raw, _ := json.Marshal(out)
|
||||
if string(raw) != `{"new_tab":false,"nofollow_domains":["example.com","shop.example.org"],"sponsored_domains":["partner.pl"]}` {
|
||||
t.Fatalf("outbound = %s", raw)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user