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) } } }