diff options
Diffstat (limited to 'server/tests')
| -rw-r--r-- | server/tests/common/mod.rs | 155 | ||||
| -rw-r--r-- | server/tests/integration_test.rs | 98 |
2 files changed, 253 insertions, 0 deletions
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<Path>, args: &[&str]) -> Result<(), anyhow::Er run(&mut cmd, "git command").await } +const STRINGS_GRD: &str = r#"<?xml version="1.0" encoding="UTF-8"?> +<grit current_release="1" latest_public_release="0"> + <outputs> + <output filename="values/strings.xml" type="android" lang="en" /> + <output filename="values-en-rGB/strings.xml" type="android" lang="en-GB" /> + <output filename="values-sv/strings.xml" type="android" lang="sv" /> + </outputs> + <translations> + <file path="translations/strings_en_gb.xlf" lang="en-GB" /> + <file path="translations/strings_sv.xlf" lang="sv" /> + </translations> + <release allow_pseudo="false" seq="1"> + <messages fallback_to_english="true"> + <part file="extra.grdp" /> + <message desc="Description" name="MAIN_STRING"> + Main test string + </message> + </messages> + </release> +</grit>"#; +const EXTRA_GRDP: &str = r#"<?xml version="1.0" encoding="utf-8"?> +<grit-part> + <message desc="Some description" name="EXTRA_STRING"> + Extra string, gray + </message> +</grit-part>"#; +const STRINGS_EN_GB_XLF: &str = r#"<?xml version="1.0" encoding="UTF-8"?> +<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> +<file datatype="xml" source-language="en-US" original="strings.grd" target-language="en-gb"> +<body> +<trans-unit id="759906012366268261"> + <source>Main test string</source> + <target>Main test string</target> + <note>MAIN_STRING + Description + </note> +</trans-unit> +<trans-unit id="3195503415604121324"> + <source>Extra string, gray</source> + <target>Extra string, grey</target> + <note>EXTRA_STRING + Some description + </note> +</trans-unit> +</body> +</file> +</xliff>"#; +const STRINGS_SV_XLF: &str = r#"<?xml version="1.0" encoding="UTF-8"?> +<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2"> +<file datatype="xml" source-language="en-US" original="strings.grd" target-language="sv"> +<body> +<trans-unit id="759906012366268261"> + <source>Main test string</source> + <target>Primära teststrängen</target> + <note>MAIN_STRING + Description + </note> +</trans-unit> +<trans-unit id="3195503415604121324"> + <source>Extra string, gray</source> + <target>Extra sträng, grå</target> + <note>EXTRA_STRING + Some description + </note> +</trans-unit> +</body> +</file> +</xliff>"#; + 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<api_model::TranslationReview, anyhow::Error> { + 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::<api_model::TranslationReview>().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<api_model::LocalizationStrings, anyhow::Error> { + let result = client + .get(format!( + "{}/api/v1/translation/{translation_reviewid}/strings", + ctx.url() + )) + .send() + .await?; + if result.status().is_success() { + let strings = result.json::<api_model::LocalizationStrings>().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)); + } +} |
