forge
ExploreLog in

Tahinli/forge

public
0 watching
★ 0
2.3 KiB
1//! End-to-end check that a community page (snippets) follows the viewer's browser language:
2//! Turkish when `Accept-Language` asks for it, English otherwise.
3
4mod common;
5
6use std::process::Command;
7use std::time::Duration;
8
9use common::{BIN, describe, launch, pick_ports, write_config};
10use reqwest::header::ACCEPT_LANGUAGE;
11
12const PW: &str = "alice-password-123";
13
14/// Runs an admin subcommand with the password in FORGE_PASSWORD and asserts it succeeded.
15fn 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]
32async 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}