diff --git a/crates/arr-api/src/subtitle_settings.rs b/crates/arr-api/src/subtitle_settings.rs index dc9e9e4..bb15fc3 100644 --- a/crates/arr-api/src/subtitle_settings.rs +++ b/crates/arr-api/src/subtitle_settings.rs @@ -302,13 +302,24 @@ mod tests { assert_eq!(refetched, updated); } + /// Whether a known engine is selectable depends on which `translate-*` + /// features this binary was built with, so the test asks the build rather + /// than assuming. With no feature on, every engine is uncompiled and must + /// be refused; with all of them on there is nothing to refuse, and the + /// complementary truth — a compiled engine is accepted — is what holds. #[tokio::test] async fn an_uncompiled_engine_is_a_422_naming_the_field() { + let compiled = arr_subs::compiled_engines(); + let Some(uncompiled) = arr_subs::ENGINES + .iter() + .find(|engine| !compiled.contains(*engine)) + else { + return a_compiled_engine_is_accepted().await; + }; + let (_dir, base) = application().await; let mut payload = valid_input(); - // No `translate-*` feature is enabled by default (arr-subs's - // Cargo.toml), so every named engine is rejected as uncompiled. - payload["translation_engine"] = serde_json::json!("deepl"); + payload["translation_engine"] = serde_json::json!(uncompiled); let response = reqwest::Client::new() .put(format!("{base}/api/settings/subtitles")) .json(&payload) @@ -326,6 +337,27 @@ mod tests { ); } + /// The other side of the feature gate: an engine this binary *did* + /// compile in is selectable. Called directly when no engine is uncompiled. + async fn a_compiled_engine_is_accepted() { + let compiled = arr_subs::compiled_engines(); + let Some(engine) = compiled.first() else { + return; + }; + + let (_dir, base) = application().await; + let mut payload = valid_input(); + payload["translation_engine"] = serde_json::json!(engine); + let response = reqwest::Client::new() + .put(format!("{base}/api/settings/subtitles")) + .json(&payload) + .send() + .await + .expect("put settings"); + + assert_eq!(response.status(), StatusCode::OK, "{engine} is compiled in"); + } + #[tokio::test] async fn an_unknown_engine_name_is_a_422() { let (_dir, base) = application().await;