From 2b54f5c51ff9a26d4077037631ed39d62ed2b3fb Mon Sep 17 00:00:00 2001 From: Joel Klinghed Date: Thu, 12 Jun 2025 09:11:18 +0200 Subject: Initial support for translation reviews --- server/tests/common/mod.rs | 155 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 155 insertions(+) (limited to 'server/tests/common/mod.rs') diff --git a/server/tests/common/mod.rs b/server/tests/common/mod.rs index 5a7e30d..0a9556a 100644 --- a/server/tests/common/mod.rs +++ b/server/tests/common/mod.rs @@ -91,6 +91,75 @@ async fn git_cmd(base: impl AsRef, args: &[&str]) -> Result<(), anyhow::Er run(&mut cmd, "git command").await } +const STRINGS_GRD: &str = r#" + + + + + + + + + + + + + + + Main test string + + + +"#; +const EXTRA_GRDP: &str = r#" + + + Extra string, gray + +"#; +const STRINGS_EN_GB_XLF: &str = r#" + + + + + Main test string + Main test string + MAIN_STRING + Description + + + + Extra string, gray + Extra string, grey + EXTRA_STRING + Some description + + + + +"#; +const STRINGS_SV_XLF: &str = r#" + + + + + Main test string + Primära teststrängen + MAIN_STRING + Description + + + + Extra string, gray + Extra sträng, grå + EXTRA_STRING + Some description + + + + +"#; + impl DockerComposeContext { pub fn url(&self) -> &str { self.url.as_str() @@ -235,6 +304,47 @@ impl AsyncTestContext for DockerComposeContext { .await .expect("git push"); + fs::write(mod_path.join("fake/strings.grd"), STRINGS_GRD) + .await + .expect("Write strings.grd"); + fs::write(mod_path.join("fake/extra.grdp"), EXTRA_GRDP) + .await + .expect("Write extra.grdp"); + fs::create_dir(mod_path.join("fake/translations")) + .await + .expect("mkdir translations"); + fs::write( + mod_path.join("fake/translations/strings_en_gb.xlf"), + STRINGS_EN_GB_XLF, + ) + .await + .expect("Write strings_en_gb.xlf"); + fs::write( + mod_path.join("fake/translations/strings_sv.xlf"), + STRINGS_SV_XLF, + ) + .await + .expect("Write strings_sv"); + + git_cmd( + &mod_path, + &[ + "add", + "strings.grd", + "extra.grdp", + "translations/strings_en_gb.xlf", + "translations/strings_sv.xlf", + ], + ) + .await + .expect("git add"); + git_cmd(&mod_path, &["commit", "-m", "Add strings"]) + .await + .expect("git commit"); + git_cmd(&mod_path, &["push", "origin", "HEAD:main"]) + .await + .expect("git push"); + ctx } @@ -351,3 +461,48 @@ pub async fn list_reviews( Err(anyhow::Error::msg(content)) } } + +pub async fn create_translation_review( + ctx: &mut DockerComposeContext, + client: &mut Client, + projectid: &str, +) -> Result { + let data = api_model::TranslationReviewData { + title: "Test".to_string(), + description: "Some test".to_string(), + base: None, + }; + let result = client + .post(format!("{}/api/v1/translation/{projectid}/new", ctx.url())) + .json(&data) + .send() + .await?; + if result.status().is_success() { + let review = result.json::().await?; + Ok(review) + } else { + let content = result.text().await?; + Err(anyhow::Error::msg(content)) + } +} + +pub async fn list_translation_strings( + ctx: &mut DockerComposeContext, + client: &mut Client, + translation_reviewid: u64, +) -> Result { + let result = client + .get(format!( + "{}/api/v1/translation/{translation_reviewid}/strings", + ctx.url() + )) + .send() + .await?; + if result.status().is_success() { + let strings = result.json::().await?; + Ok(strings) + } else { + let content = result.text().await?; + Err(anyhow::Error::msg(content)) + } +} -- cgit v1.2.3-70-g09d2