feat(cli): Support for downloading an episode release in Sonarr

This commit is contained in:
2024-11-22 20:04:57 -07:00
parent 5ed3372ae2
commit 1b5979c36c
2 changed files with 147 additions and 0 deletions
@@ -213,6 +213,84 @@ mod tests {
assert!(result.is_ok());
}
#[test]
fn test_download_episode_requires_episode_id() {
let result = Cli::command().try_get_matches_from([
"managarr",
"sonarr",
"download",
"episode",
"--indexer-id",
"1",
"--guid",
"1",
]);
assert!(result.is_err());
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_download_episode_requires_guid() {
let result = Cli::command().try_get_matches_from([
"managarr",
"sonarr",
"download",
"episode",
"--indexer-id",
"1",
"--episode-id",
"1",
]);
assert!(result.is_err());
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_download_episode_requires_indexer_id() {
let result = Cli::command().try_get_matches_from([
"managarr",
"sonarr",
"download",
"episode",
"--guid",
"1",
"--episode-id",
"1",
]);
assert!(result.is_err());
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_download_episode_requirements_satisfied() {
let result = Cli::command().try_get_matches_from([
"managarr",
"sonarr",
"download",
"episode",
"--guid",
"1",
"--episode-id",
"1",
"--indexer-id",
"1",
]);
assert!(result.is_ok());
}
}
mod handler {
@@ -306,5 +384,40 @@ mod tests {
assert!(result.is_ok());
}
#[tokio::test]
async fn test_download_episode_release_command() {
let expected_release_download_body = SonarrReleaseDownloadBody {
guid: "guid".to_owned(),
indexer_id: 1,
episode_id: Some(1),
..SonarrReleaseDownloadBody::default()
};
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
SonarrEvent::DownloadRelease(expected_release_download_body).into(),
))
.times(1)
.returning(|_| {
Ok(Serdeable::Sonarr(SonarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::default()));
let download_release_command = SonarrDownloadCommand::Episode {
guid: "guid".to_owned(),
indexer_id: 1,
episode_id: 1,
};
let result =
SonarrDownloadCommandHandler::with(&app_arc, download_release_command, &mut mock_network)
.handle()
.await;
assert!(result.is_ok());
}
}
}