//! The published documentation tree, end to end. //! //! These two assertions were written when the docs half of the sitemap and the //! search index were fixed, then dropped: the harness built its `DocLoader` //! with `sections: vec![]`, so under test the site had no doc pages and neither //! test could pass. The harness now loads the real tree through the same //! `site_docs::build_doc_loader` production uses, so they hold again. //! //! Both are corpus-wide rather than example-based on purpose. A test naming one //! slug pins that slug; these fail when any page stops being reachable, which is //! the failure that actually happens when a doc is added or a section renamed. use crate::harness::TestHarness; use serde_json::Value; /// Every page in the search index must be reachable. The index is what the /// client-side filter searches, so a slug present here but not served is a /// result that 404s when clicked. #[tokio::test] async fn every_indexed_doc_slug_is_served() { let mut h = TestHarness::new().await; let resp = h.client.get("/docs/search.json").await; assert_eq!(resp.status, 200, "search index should be served"); let index: Vec = resp.json(); assert!( !index.is_empty(), "the search index is empty, which means the harness loaded no docs and \ this test is proving nothing" ); for entry in &index { let slug = entry["slug"].as_str().expect("each entry carries a slug"); let page = h.client.get(&format!("/docs/{slug}")).await; assert_eq!( page.status, 200, "/docs/{slug} is in the search index but is not served" ); } } /// The sitemap is how a crawler finds the docs at all. It carries one URL per /// indexed page, and a doc missing from it is a doc that is published but /// undiscoverable. #[tokio::test] async fn the_sitemap_carries_every_doc_url() { let mut h = TestHarness::new().await; let resp = h.client.get("/docs/search.json").await; let index: Vec = resp.json(); let slugs: Vec = index .iter() .map(|e| e["slug"].as_str().expect("slug").to_string()) .collect(); assert!( !slugs.is_empty(), "no docs loaded, nothing is being asserted" ); let resp = h.client.get("/sitemap.xml").await; assert_eq!(resp.status, 200, "sitemap should be served"); let xml = resp.text; assert!( xml.contains("/docs") || xml.contains("/docs<"), "the docs index itself belongs in the sitemap" ); for slug in &slugs { assert!( xml.contains(&format!("/docs/{slug}")), "/docs/{slug} is published but missing from the sitemap" ); } }