| 1 | |
| 2 | |
| 3 | |
| 4 | mod common; |
| 5 | |
| 6 | use std::process::Command; |
| 7 | use std::time::Duration; |
| 8 | |
| 9 | use common::{BIN, describe, launch, pick_ports, write_config}; |
| 10 | use reqwest::header::ACCEPT_LANGUAGE; |
| 11 | |
| 12 | const PW: &str = "alice-password-123"; |
| 13 | |
| 14 | |
| 15 | fn admin(config: &std::path::Path, args: &[&str]) { |
| 16 | let out = Command::new(BIN) |
| 17 | .arg("--config") |
| 18 | .arg(config) |
| 19 | .arg("admin") |
| 20 | .args(args) |
| 21 | .env("FORGE_PASSWORD", PW) |
| 22 | .output() |
| 23 | .expect("run admin command"); |
| 24 | assert!( |
| 25 | out.status.success(), |
| 26 | "admin {args:?} failed:\n{}", |
| 27 | describe(&out) |
| 28 | ); |
| 29 | } |
| 30 | |
| 31 | #[tokio::test] |
| 32 | async fn snippets_page_follows_the_browser_language() { |
| 33 | let root = tempfile::tempdir().expect("temp dir"); |
| 34 | let dir = root.path().to_path_buf(); |
| 35 | let ports = pick_ports(); |
| 36 | let config = write_config(&dir, ports); |
| 37 | admin(&config, &["create-user", "alice"]); |
| 38 | let (_server, ports) = launch(&dir, ports).await; |
| 39 | |
| 40 | let client = reqwest::Client::builder() |
| 41 | .timeout(Duration::from_secs(60)) |
| 42 | .build() |
| 43 | .expect("http client"); |
| 44 | let base = format!("http://127.0.0.1:{}", ports.http); |
| 45 | |
| 46 | let turkish = client |
| 47 | .get(format!("{base}/snippets")) |
| 48 | .header(ACCEPT_LANGUAGE, "tr-TR,tr;q=0.9,en;q=0.8") |
| 49 | .send() |
| 50 | .await |
| 51 | .expect("GET /snippets (tr)"); |
| 52 | assert_eq!(turkish.status().as_u16(), 200); |
| 53 | let body = turkish.text().await.expect("read body"); |
| 54 | assert!(body.contains("<html lang=\"tr\""), "html lang is tr"); |
| 55 | assert!(body.contains("<h1>Parçacıklar</h1>"), "Turkish heading"); |
| 56 | assert!( |
| 57 | body.contains("Gösterilecek parçacık yok."), |
| 58 | "Turkish empty state" |
| 59 | ); |
| 60 | assert!(!body.contains("No snippets to show."), "no English left"); |
| 61 | |
| 62 | let english = client |
| 63 | .get(format!("{base}/snippets")) |
| 64 | .header(ACCEPT_LANGUAGE, "en-US,en;q=0.9") |
| 65 | .send() |
| 66 | .await |
| 67 | .expect("GET /snippets (en)"); |
| 68 | let body = english.text().await.expect("read body"); |
| 69 | assert!(body.contains("<h1>Snippets</h1>"), "English heading"); |
| 70 | assert!(body.contains("No snippets to show."), "English empty state"); |
| 71 | } |