Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates: required string can lack default_value. Updated undefined ap… #129

Merged
merged 2 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/commands/edge_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<Vec<String>, CommandError> {
fn get_undefined_settings(&self, app_id: &str) -> Result<Vec<String>, 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::<Vec<String>>(undefined_secrets_response)?;
let titles = serde_json::from_value::<Vec<String>>(undefined_settings_response)?;

Ok(titles)
}
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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| {
Expand Down Expand Up @@ -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",
Expand All @@ -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]
Expand Down Expand Up @@ -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",
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions src/commands/edge_app_manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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#"---
Expand All @@ -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]
Expand Down
1 change: 0 additions & 1 deletion src/commands/edge_app_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ pub async fn run_server(
.and(warp::path("screenly.js"))
.and(warp::query::<HashMap<String, String>>())
.and_then({
let dir_path = dir_path;
move |params: HashMap<String, String>| {
let dir_path = dir_path.clone();
let secrets_clone = secrets_clone.clone();
Expand Down
9 changes: 0 additions & 9 deletions src/commands/edge_app_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.")]
Expand Down
Loading