//! End-to-end check that a community page (snippets) follows the viewer's browser language: //! Turkish when `Accept-Language` asks for it, English otherwise. mod common; use std::process::Command; use std::time::Duration; use common::{BIN, describe, launch, pick_ports, write_config}; use reqwest::header::ACCEPT_LANGUAGE; const PW: &str = "alice-password-123"; /// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded. fn admin(config: &std::path::Path, args: &[&str]) { let out = Command::new(BIN) .arg("--config") .arg(config) .arg("admin") .args(args) .env("FORGE_PASSWORD", PW) .output() .expect("run admin command"); assert!( out.status.success(), "admin {args:?} failed:\n{}", describe(&out) ); } #[tokio::test] async fn snippets_page_follows_the_browser_language() { let root = tempfile::tempdir().expect("temp dir"); let dir = root.path().to_path_buf(); let ports = pick_ports(); let config = write_config(&dir, ports); admin(&config, &["create-user", "alice"]); let (_server, ports) = launch(&dir, ports).await; let client = reqwest::Client::builder() .timeout(Duration::from_secs(60)) .build() .expect("http client"); let base = format!("http://127.0.0.1:{}", ports.http); let turkish = client .get(format!("{base}/snippets")) .header(ACCEPT_LANGUAGE, "tr-TR,tr;q=0.9,en;q=0.8") .send() .await .expect("GET /snippets (tr)"); assert_eq!(turkish.status().as_u16(), 200); let body = turkish.text().await.expect("read body"); assert!(body.contains(""), "html lang is tr"); assert!(body.contains("