feat(cli): Support for searching for new series to add to Sonarr

This commit is contained in:
2024-11-24 14:58:30 -07:00
parent da3bb795b7
commit 45542cd3a9
3 changed files with 69 additions and 2 deletions
+2 -2
View File
@@ -129,7 +129,7 @@ mod tests {
assert!(result.is_ok());
}
#[rstest]
#[test]
fn test_search_new_movie_requires_query() {
let result = Cli::command().try_get_matches_from(["managarr", "radarr", "search-new-movie"]);
@@ -153,7 +153,7 @@ mod tests {
assert!(result.is_ok());
}
#[rstest]
#[test]
fn test_start_task_requires_task_name() {
let result = Cli::command().try_get_matches_from(["managarr", "radarr", "start-task"]);
+16
View File
@@ -85,6 +85,15 @@ pub enum SonarrCommand {
)]
history_item_id: i64,
},
#[command(about = "Search for a new series to add to Sonarr")]
SearchNewSeries {
#[arg(
long,
help = "The title of the series you want to search for",
required = true
)]
query: String,
},
#[command(about = "Start the specified Sonarr task")]
StartTask {
#[arg(
@@ -195,6 +204,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, SonarrCommand> for SonarrCliHandler<'a, '
.await?;
"Sonarr history item marked as 'failed'".to_owned()
}
SonarrCommand::SearchNewSeries { query } => {
let resp = self
.network
.handle_network_event(SonarrEvent::SearchNewSeries(Some(query)).into())
.await?;
serde_json::to_string_pretty(&resp)?
}
SonarrCommand::StartTask { task_name } => {
let resp = self
.network
+51
View File
@@ -57,6 +57,30 @@ mod tests {
assert!(result.is_ok());
}
#[test]
fn test_search_new_series_requires_query() {
let result = Cli::command().try_get_matches_from(["managarr", "sonarr", "search-new-series"]);
assert!(result.is_err());
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_search_new_series_requirements_satisfied() {
let result = Cli::command().try_get_matches_from([
"managarr",
"sonarr",
"search-new-series",
"--query",
"halo",
]);
assert!(result.is_ok());
}
#[test]
fn test_start_task_requires_task_name() {
let result = Cli::command().try_get_matches_from(["managarr", "sonarr", "start-task"]);
@@ -434,6 +458,33 @@ mod tests {
assert!(result.is_ok());
}
#[tokio::test]
async fn test_search_new_series_command() {
let expected_search_query = "halo".to_owned();
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
SonarrEvent::SearchNewSeries(Some(expected_search_query)).into(),
))
.times(1)
.returning(|_| {
Ok(Serdeable::Sonarr(SonarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::default()));
let search_new_series_command = SonarrCommand::SearchNewSeries {
query: "halo".to_owned(),
};
let result = SonarrCliHandler::with(&app_arc, search_new_series_command, &mut mock_network)
.handle()
.await;
assert!(result.is_ok());
}
#[tokio::test]
async fn test_start_task_command() {
let expected_task_name = SonarrTaskName::ApplicationUpdateCheck;