feat(cli): Support for refreshing a specific series in Sonarr

This commit is contained in:
2024-11-22 19:13:57 -07:00
parent c3577a0724
commit eb06787bb2
3 changed files with 100 additions and 27 deletions
@@ -20,7 +20,7 @@ mod tests {
mod cli {
use super::*;
use clap::Parser;
use clap::{error::ErrorKind, Parser};
use pretty_assertions::assert_eq;
use rstest::rstest;
@@ -31,6 +31,38 @@ mod tests {
assert!(result.is_ok());
}
#[test]
fn test_refresh_series_requires_series_id() {
let result = Cli::command().try_get_matches_from(["managarr", "sonarr", "refresh", "series"]);
assert!(result.is_err());
assert_eq!(
result.unwrap_err().kind(),
ErrorKind::MissingRequiredArgument
);
}
#[test]
fn test_refresh_series_success() {
let expected_args = SonarrRefreshCommand::Series { series_id: 1 };
let result = Cli::try_parse_from([
"managarr",
"sonarr",
"refresh",
"series",
"--series-id",
"1",
]);
assert!(result.is_ok());
if let Some(Command::Sonarr(SonarrCommand::Refresh(refresh_command))) =
result.unwrap().command
{
assert_eq!(refresh_command, expected_args);
}
}
}
mod handler {
@@ -41,6 +73,7 @@ mod tests {
use serde_json::json;
use tokio::sync::Mutex;
use crate::{app::App, cli::sonarr::refresh_command_handler::SonarrRefreshCommandHandler};
use crate::{
cli::{sonarr::refresh_command_handler::SonarrRefreshCommand, CliCommandHandler},
network::sonarr_network::SonarrEvent,
@@ -57,8 +90,6 @@ mod tests {
#[case] refresh_command: SonarrRefreshCommand,
#[case] expected_sonarr_event: SonarrEvent,
) {
use crate::{app::App, cli::sonarr::refresh_command_handler::SonarrRefreshCommandHandler};
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
@@ -77,5 +108,31 @@ mod tests {
assert!(result.is_ok());
}
#[tokio::test]
async fn test_handle_refresh_series_command() {
let expected_series_id = 1;
let mut mock_network = MockNetworkTrait::new();
mock_network
.expect_handle_network_event()
.with(eq::<NetworkEvent>(
SonarrEvent::UpdateAndScanSeries(Some(expected_series_id)).into(),
))
.times(1)
.returning(|_| {
Ok(Serdeable::Sonarr(SonarrSerdeable::Value(
json!({"testResponse": "response"}),
)))
});
let app_arc = Arc::new(Mutex::new(App::default()));
let refresh_series_command = SonarrRefreshCommand::Series { series_id: 1 };
let result =
SonarrRefreshCommandHandler::with(&app_arc, refresh_series_command, &mut mock_network)
.handle()
.await;
assert!(result.is_ok());
}
}
}