Files
sm-seo-plugin/crawler_test.go
Jakub Zych c2b61bf8e9 feat: crawler finds a page with two H1 headings and stores the issue (tracer)
- golem15_seo_crawls, crawl pages, links, issues and ignores (P33-37)
- classes/crawl: fetchguard client on the site host and its www twin,
  sitemap index and robots.txt seeds, two workers with a delay, limits
- h1_missing and h1_multiple with the P33-38 fix route
- POST /_seo/api/v1/crawls queues the golem15.seo.crawl job; GET /issues
  answers the stored issues with id, severity, source, fix, found_at,
  ignored and crawl_id
2026-11-04 15:05:45 +01:00

49 lines
1.9 KiB
Go

package seo_test
import (
"testing"
"git.golem15.com/golem15/summercms/modules/pact"
)
// TestCrawlerTracer is the end-to-end path (D-14): an administrator
// starts a crawl through the API, the crawl job fetches the site with the
// crawler's User-Agent, and GET /issues lists the page with two H1
// headings as an error with how to fix it: code for H1 headings of the
// template, the record type's headings tool for an H1 inside the record's
// own content.
func TestCrawlerTracer(t *testing.T) {
env := bootCrawlEnv(t)
token := env.admin(t, true)
setCrawlRecords(t, map[string][]crawlRecord{
crawlPostType: {{id: "1", path: "/c/two-h1", title: "Post title", headings: []pact.ContentHeading{{Level: 1, Text: "Inside the body"}}}},
})
site := newFakeSite()
site.sitemap("/", "/p/two-h1", "/c/two-h1")
site.plant(
doc{path: "/", title: "Home", links: []string{"/p/two-h1", "/c/two-h1"}},
doc{path: "/p/two-h1", title: "Template page", h1: []string{"Template page", "Another H1"}},
doc{path: "/c/two-h1", title: "Post title", h1: []string{"Post title", "Inside the body"}},
)
env.crawlOnce(t, token, siteCtx(t, site))
list := env.issues(t, token, "")
tpl := findIssue(t, list, "h1_multiple", "/p/two-h1")
if tpl.Severity != "error" || tpl.Fix != "code" || tpl.Tool != "" || tpl.Source != "crawl" || tpl.Details["what"] == nil || tpl.Details["count"] != float64(2) {
t.Fatalf("template h1_multiple = %+v", tpl)
}
content := findIssue(t, list, "h1_multiple", "/c/two-h1")
if content.Fix != "tool" || content.Tool != "acme_fix_headings" || content.CrawlID == nil || content.ID == 0 {
t.Fatalf("content h1_multiple = %+v", content)
}
if !site.requested("/sitemap-pages-1.xml") || !site.requested("/c/two-h1") {
t.Fatalf("crawler requests = %v", site.requests)
}
for _, ua := range site.agents {
if ua != "SummerCMS-SEO-Crawler/1 (+https://www.example.test)" {
t.Fatalf("User-Agent = %q", ua)
}
}
}