| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
use crate::harness::TestHarness; |
| 14 |
use serde_json::Value; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
#[tokio::test] |
| 20 |
async fn every_indexed_doc_slug_is_served() { |
| 21 |
let mut h = TestHarness::new().await; |
| 22 |
|
| 23 |
let resp = h.client.get("/docs/search.json").await; |
| 24 |
assert_eq!(resp.status, 200, "search index should be served"); |
| 25 |
let index: Vec<Value> = resp.json(); |
| 26 |
assert!( |
| 27 |
!index.is_empty(), |
| 28 |
"the search index is empty, which means the harness loaded no docs and \ |
| 29 |
this test is proving nothing" |
| 30 |
); |
| 31 |
|
| 32 |
for entry in &index { |
| 33 |
let slug = entry["slug"].as_str().expect("each entry carries a slug"); |
| 34 |
let page = h.client.get(&format!("/docs/{slug}")).await; |
| 35 |
assert_eq!( |
| 36 |
page.status, 200, |
| 37 |
"/docs/{slug} is in the search index but is not served" |
| 38 |
); |
| 39 |
} |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
#[tokio::test] |
| 46 |
async fn the_sitemap_carries_every_doc_url() { |
| 47 |
let mut h = TestHarness::new().await; |
| 48 |
|
| 49 |
let resp = h.client.get("/docs/search.json").await; |
| 50 |
let index: Vec<Value> = resp.json(); |
| 51 |
let slugs: Vec<String> = index |
| 52 |
.iter() |
| 53 |
.map(|e| e["slug"].as_str().expect("slug").to_string()) |
| 54 |
.collect(); |
| 55 |
assert!( |
| 56 |
!slugs.is_empty(), |
| 57 |
"no docs loaded, nothing is being asserted" |
| 58 |
); |
| 59 |
|
| 60 |
let resp = h.client.get("/sitemap.xml").await; |
| 61 |
assert_eq!(resp.status, 200, "sitemap should be served"); |
| 62 |
let xml = resp.text; |
| 63 |
|
| 64 |
assert!( |
| 65 |
xml.contains("/docs</loc>") || xml.contains("/docs<"), |
| 66 |
"the docs index itself belongs in the sitemap" |
| 67 |
); |
| 68 |
for slug in &slugs { |
| 69 |
assert!( |
| 70 |
xml.contains(&format!("/docs/{slug}</loc>")), |
| 71 |
"/docs/{slug} is published but missing from the sitemap" |
| 72 |
); |
| 73 |
} |
| 74 |
} |
| 75 |
|