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 +++++++++++++++++++++++++++++++++++++++ server/tests/integration_test.rs | 98 +++++++++++++++++++++++++ 2 files changed, 253 insertions(+) (limited to 'server/tests') 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)) + } +} diff --git a/server/tests/integration_test.rs b/server/tests/integration_test.rs index 200657e..6becf61 100644 --- a/server/tests/integration_test.rs +++ b/server/tests/integration_test.rs @@ -1,9 +1,12 @@ +use pretty_assertions::assert_eq; use std::path::PathBuf; use std::thread::sleep; use std::time::Duration; use test_context::test_context; use tokio::fs; +use eyeballs_api::api_model; + mod common; const TESTKEY1: &str = "-----BEGIN OPENSSH PRIVATE KEY----- @@ -128,3 +131,98 @@ async fn test_sanity(ctx: &mut common::DockerComposeContext) { sleep(Duration::from_millis(500)); } } + +#[test_context(common::DockerComposeContext)] +#[tokio::test] +async fn test_translation_review_create(ctx: &mut common::DockerComposeContext) { + let mut client1 = common::create_client().expect("client1"); + common::login(ctx, &mut client1, "user01", "password1") + .await + .expect("user01 login"); + + common::user_key_add(ctx, &mut client1, "ssh-rsa", TESTKEY1_PUB) + .await + .expect("user01 key add"); + ctx.setup_ssh_key("client1", TESTKEY1) + .await + .expect("user01 ssh_config setup"); + + let remote_git = String::from(ctx.remote_git()); + let remote_git_key = PathBuf::from(ctx.remote_git_key()); + common::create_project(ctx, &mut client1, "fake", &remote_git, &remote_git_key) + .await + .expect("create fake project"); + + let review = common::create_translation_review(ctx, &mut client1, "fake") + .await + .expect("create translation review"); + + for _ in 0..5 { + let strings = common::list_translation_strings(ctx, &mut client1, review.id) + .await + .expect("list strings"); + if strings.strings.len() > 0 { + assert_eq!( + strings.strings, + vec![ + api_model::LocalizationString { + id: "EXTRA_STRING".to_string(), + file: "extra.grdp".to_string(), + description: "Some description".to_string(), + meaning: "".to_string(), + source: "Extra string, gray".to_string(), + placeholders: vec![], + placeholder_offset: vec![], + translations: vec![ + api_model::TranslationString { + language: "en-gb".to_string(), + translation: "Extra string, grey".to_string(), + placeholder_offset: vec![], + state: api_model::TranslationState::Unchanged, + comment: "".to_string(), + reviewer: None, + }, + api_model::TranslationString { + language: "sv".to_string(), + translation: "Extra sträng, grå".to_string(), + placeholder_offset: vec![], + state: api_model::TranslationState::Unchanged, + comment: "".to_string(), + reviewer: None, + } + ], + }, + api_model::LocalizationString { + id: "MAIN_STRING".to_string(), + file: "strings.grd".to_string(), + description: "Description".to_string(), + meaning: "".to_string(), + source: "Main test string".to_string(), + placeholders: vec![], + placeholder_offset: vec![], + translations: vec![ + api_model::TranslationString { + language: "en-gb".to_string(), + translation: "Main test string".to_string(), + placeholder_offset: vec![], + state: api_model::TranslationState::Unchanged, + comment: "".to_string(), + reviewer: None, + }, + api_model::TranslationString { + language: "sv".to_string(), + translation: "Primära teststrängen".to_string(), + placeholder_offset: vec![], + state: api_model::TranslationState::Unchanged, + comment: "".to_string(), + reviewer: None, + } + ], + }, + ] + ); + break; + } + sleep(Duration::from_millis(500)); + } +} -- cgit v1.2.3-70-g09d2