Phase 8 part 2: who links to you, from Bing
With a Bing Webmaster key, Supermarket reads once a week (or on Read now) how many links Bing knows to each page of the site, and for the 25 most linked pages, the pages that link and their anchor text, into the backlinks table. SEO → Links lists the linking sites, new ones first, with the pages they link to and their link text; without a key it says how to get one. A refused key keeps the last read, with the error. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -171,3 +171,35 @@ func TestWhatToWriteNext(t *testing.T) {
|
||||
t.Error("New pages wasn't filled in")
|
||||
}
|
||||
}
|
||||
|
||||
func TestLinksFromBing(t *testing.T) {
|
||||
b := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var d any
|
||||
switch r.URL.Path {
|
||||
case "/GetLinkCounts":
|
||||
d = map[string]any{"TotalPages": 1, "Links": []map[string]any{{"Url": "https://acme.example/freescout", "Count": 2}}}
|
||||
case "/GetUrlLinks":
|
||||
d = map[string]any{"TotalPages": 1, "Details": []map[string]any{{"Url": "https://selfhosted.blog/hosts/", "AnchorText": "Acme hosting"}}}
|
||||
}
|
||||
json.NewEncoder(w).Encode(map[string]any{"d": d})
|
||||
}))
|
||||
defer b.Close()
|
||||
bingBase = b.URL
|
||||
defer func() { bingBase = "" }()
|
||||
s, h := newTestServer(t, nil)
|
||||
profile.Save(s.DB, &profile.Profile{Name: "Acme", Websites: []profile.Website{{URL: "https://acme.example/", SearchConsoleProperty: "sc-domain:acme.example"}}})
|
||||
|
||||
if body := do(h, http.MethodGet, "/seo/links", nil, nil).Body.String(); !strings.Contains(body, "Save a Bing Webmaster API key") {
|
||||
t.Errorf("without a key: %s", body)
|
||||
}
|
||||
postForm(h, "/settings/search", url.Values{secrets.BingAPIKey: {"k"}})
|
||||
if rec := postForm(h, "/seo/links/bing?site=0", nil); rec.Code != http.StatusSeeOther || !strings.Contains(rec.Header().Get("Location"), "msg=bing-read") {
|
||||
t.Fatalf("read: %d %s", rec.Code, rec.Header().Get("Location"))
|
||||
}
|
||||
body := do(h, http.MethodGet, "/seo/links", nil, nil).Body.String()
|
||||
for _, want := range []string{"selfhosted.blog", "“Acme hosting”", "/freescout/", "2 links to 1 page"} {
|
||||
if !strings.Contains(body, want) {
|
||||
t.Errorf("links page lacks %q", want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user