diff --git a/src/commands/edge_app.rs b/src/commands/edge_app.rs index 83ef990..f3527ce 100644 --- a/src/commands/edge_app.rs +++ b/src/commands/edge_app.rs @@ -406,14 +406,14 @@ impl EdgeAppCommand { revision: u32, channel: &String, ) -> Result<(), CommandError> { - let secrets = self.get_undefined_secrets(app_id)?; + let secrets = self.get_undefined_settings(app_id)?; if !secrets.is_empty() { - return Err(CommandError::UndefinedSecrets(serde_json::to_string( + return Err(CommandError::UndefinedSettings(serde_json::to_string( &secrets, )?)); } - debug!("All secrets are defined."); + debug!("All settings are defined."); let get_response = commands::get( &self.authentication, @@ -548,18 +548,18 @@ impl EdgeAppCommand { println!("Mock data for Edge App emulator was generated."); Ok(()) } - fn get_undefined_secrets(&self, app_id: &str) -> Result, CommandError> { + fn get_undefined_settings(&self, app_id: &str) -> Result, CommandError> { let installation_id = self.get_or_create_installation(app_id)?; - let undefined_secrets_response = commands::get( + let undefined_settings_response = commands::get( &self.authentication, &format!( - "v4/edge-apps/secrets/undefined?installation_id={}", + "v4/edge-apps/settings/undefined?installation_id={}", installation_id ), )?; - let titles = serde_json::from_value::>(undefined_secrets_response)?; + let titles = serde_json::from_value::>(undefined_settings_response)?; Ok(titles) } @@ -2005,9 +2005,9 @@ mod tests { }); // v4/edge-apps/settings?select=type,default_value,optional,title,help_text&app_id=eq.{}&order=title.asc - let undefined_secrets_mock = mock_server.mock(|when, then| { + let undefined_settings_mock = mock_server.mock(|when, then| { when.method(GET) - .path("/v4/edge-apps/secrets/undefined") + .path("/v4/edge-apps/settings/undefined") .header("Authorization", "Token token") .header( "user-agent", @@ -2049,7 +2049,7 @@ mod tests { get_version_mock.assert(); installation_mock.assert(); installation_mock_create.assert(); - undefined_secrets_mock.assert(); + undefined_settings_mock.assert(); promote_mock.assert(); assert!(&result.is_ok()); @@ -2270,7 +2270,7 @@ settings: } #[test] - fn test_promote_when_there_are_undefined_secrets_should_fail() { + fn test_promote_when_there_are_undefined_settings_should_fail() { let mock_server = MockServer::start(); let installation_mock = mock_server.mock(|when, then| { @@ -2310,9 +2310,9 @@ settings: }); // v4/edge-apps/settings?select=type,default_value,optional,title,help_text&app_id=eq.{}&order=title.asc - let undefined_secrets_mock = mock_server.mock(|when, then| { + let undefined_settings_mock = mock_server.mock(|when, then| { when.method(GET) - .path("/v4/edge-apps/secrets/undefined") + .path("/v4/edge-apps/settings/undefined") .header("Authorization", "Token token") .header( "user-agent", @@ -2332,10 +2332,10 @@ settings: installation_mock.assert(); installation_mock_create.assert(); - undefined_secrets_mock.assert(); + undefined_settings_mock.assert(); assert!(!&result.is_ok()); - assert!(result.unwrap_err().to_string().contains("Warning: these secrets are undefined: [\"undefined_secret\",\"another_undefined_secret\"].")); + assert!(result.unwrap_err().to_string().contains("Warning: these settings are required to be defined: [\"undefined_secret\",\"another_undefined_secret\"].")); } #[test] @@ -2394,9 +2394,9 @@ settings: }); // v4/edge-apps/settings?select=type,default_value,optional,title,help_text&app_id=eq.{}&order=title.asc - let undefined_secrets_mock = mock_server.mock(|when, then| { + let undefined_settings_mock = mock_server.mock(|when, then| { when.method(GET) - .path("/v4/edge-apps/secrets/undefined") + .path("/v4/edge-apps/settings/undefined") .header("Authorization", "Token token") .header( "user-agent", @@ -2416,7 +2416,7 @@ settings: get_version_mock.assert(); installation_mock.assert(); installation_mock_create.assert(); - undefined_secrets_mock.assert(); + undefined_settings_mock.assert(); assert!(!&result.is_ok()); assert!(result diff --git a/src/commands/edge_app_manifest.rs b/src/commands/edge_app_manifest.rs index e2dcbe4..47ffa55 100644 --- a/src/commands/edge_app_manifest.rs +++ b/src/commands/edge_app_manifest.rs @@ -601,7 +601,8 @@ settings: } #[test] - fn test_ensure_manifest_is_valid_when_required_string_field_has_no_default_value_should_fail() { + fn test_ensure_manifest_is_valid_when_required_string_field_has_no_default_value_should_succeed( + ) { let dir = tempdir().unwrap(); let file_name = "screenly.yml"; let content = r#"--- @@ -617,8 +618,7 @@ settings: write_to_tempfile(&dir, file_name, content); let file_path = dir.path().join(file_name); let result = EdgeAppManifest::ensure_manifest_is_valid(&file_path); - assert!(result.is_err()); - assert!(result.unwrap_err().to_string().contains("Setting \"username\" is of type \"string\" and is not optional, it must have a default value")); + assert!(result.is_ok()); } #[test] diff --git a/src/commands/edge_app_server.rs b/src/commands/edge_app_server.rs index 612f54e..60100e2 100644 --- a/src/commands/edge_app_server.rs +++ b/src/commands/edge_app_server.rs @@ -53,7 +53,6 @@ pub async fn run_server( .and(warp::path("screenly.js")) .and(warp::query::>()) .and_then({ - let dir_path = dir_path; move |params: HashMap| { let dir_path = dir_path.clone(); let secrets_clone = secrets_clone.clone(); diff --git a/src/commands/edge_app_settings.rs b/src/commands/edge_app_settings.rs index 1e98ca9..e67c35e 100644 --- a/src/commands/edge_app_settings.rs +++ b/src/commands/edge_app_settings.rs @@ -72,15 +72,6 @@ where setting.title ))); } - if setting.type_ == SettingType::String - && !setting.optional - && setting.default_value.is_none() - { - return Err(serde::de::Error::custom(format!( - "Setting \"{}\" is of type \"string\" and is not optional, it must have a default value", - setting.title - ))); - } } settings.sort_by_key(|s| s.title.clone()); diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 84579e1..dd5ae95 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -109,8 +109,8 @@ pub enum CommandError { InitializationError(String), #[error("Asset processing error: {0}")] AssetProcessingError(String), - #[error("Warning: these secrets are undefined: {0}.")] - UndefinedSecrets(String), + #[error("Warning: these settings are required to be defined: {0}.")] + UndefinedSettings(String), #[error("App id is required. Either in manifest or with --app-id.")] MissingAppId, #[error("App id cannot be empty. Provide it either in manifest or with --app-id.")]