fix: set_url_seo and record imports refuse a locale the record does not have (WR-18)
A locale given with a URL write overrode the matched one unchecked, so "xx" created an entry nothing ever reads while the answer reported success. SetURLSEO (API, MCP, batch set_seo, records import) now requires one of the record's locales and refuses others with api.locale_unknown.
This commit is contained in:
11
mcp_test.go
11
mcp_test.go
@@ -257,6 +257,17 @@ func TestManagementAPI(t *testing.T) {
|
||||
}
|
||||
env.mcpExpect(t, http.StatusOK, http.MethodPut, "/_seo/api/v1/seo", agent, map[string]any{"url": "/pages/a", "values": map[string]any{"og_image": "https://cdn.example/a.png"}})
|
||||
|
||||
// A locale the record does not describe is refused (WR-18); one it
|
||||
// does is written.
|
||||
for _, bad := range []string{"xx", "EN "} {
|
||||
if rec := env.mcp(t, http.MethodPut, "/_seo/api/v1/seo", agent, map[string]any{"url": "/pages/a", "locale": bad, "values": map[string]any{"title": "Lost"}}); rec.Code != http.StatusUnprocessableEntity || !strings.Contains(rec.Body.String(), `"locale"`) {
|
||||
t.Fatalf("set_url_seo locale %q = %d %s, want 422 on locale", bad, rec.Code, rec.Body.String())
|
||||
}
|
||||
}
|
||||
if got := env.mcpExpect(t, http.StatusOK, http.MethodPut, "/_seo/api/v1/seo", agent, map[string]any{"url": "/pages/a", "locale": "pl", "values": map[string]any{"title": "Po polsku"}}); got["locale"] != "pl" {
|
||||
t.Fatalf("set_url_seo locale pl = %v", got)
|
||||
}
|
||||
|
||||
// URL rules.
|
||||
rule := env.mcpExpect(t, http.StatusCreated, http.MethodPost, "/_seo/api/v1/rules", agent, map[string]any{"url": "/blog?tag=*", "match": "pattern", "robots": "noindex"})
|
||||
data, _ := rule["data"].(map[string]any)
|
||||
|
||||
Reference in New Issue
Block a user