feat: Bulk added CLI support for tracks and album functionalities in Lidarr
This commit is contained in:
@@ -28,6 +28,11 @@ pub enum LidarrDeleteCommand {
|
||||
#[arg(long, help = "Add a list exclusion for this album")]
|
||||
add_list_exclusion: bool,
|
||||
},
|
||||
#[command(about = "Delete the specified track file from disk")]
|
||||
TrackFile {
|
||||
#[arg(long, help = "The ID of the track file to delete", required = true)]
|
||||
track_file_id: i64,
|
||||
},
|
||||
#[command(about = "Delete an artist from your Lidarr library")]
|
||||
Artist {
|
||||
#[arg(long, help = "The ID of the artist to delete", required = true)]
|
||||
@@ -102,6 +107,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, LidarrDeleteCommand> for LidarrDeleteComm
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
LidarrDeleteCommand::TrackFile { track_file_id } => {
|
||||
let resp = self
|
||||
.network
|
||||
.handle_network_event(LidarrEvent::DeleteTrackFile(track_file_id).into())
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
LidarrDeleteCommand::Artist {
|
||||
artist_id,
|
||||
delete_files_from_disk,
|
||||
|
||||
@@ -86,6 +86,40 @@ mod tests {
|
||||
assert_eq!(delete_command, expected_args);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_delete_track_file_requires_arguments() {
|
||||
let result =
|
||||
Cli::command().try_get_matches_from(["managarr", "lidarr", "delete", "track-file"]);
|
||||
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_delete_track_file_success() {
|
||||
let expected_args = LidarrDeleteCommand::TrackFile { track_file_id: 1 };
|
||||
|
||||
let result = Cli::try_parse_from([
|
||||
"managarr",
|
||||
"lidarr",
|
||||
"delete",
|
||||
"track-file",
|
||||
"--track-file-id",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert_ok!(&result);
|
||||
|
||||
let Some(Command::Lidarr(LidarrCommand::Delete(delete_command))) = result.unwrap().command
|
||||
else {
|
||||
panic!("Unexpected command type");
|
||||
};
|
||||
assert_eq!(delete_command, expected_args);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_delete_artist_requires_arguments() {
|
||||
let result = Cli::command().try_get_matches_from(["managarr", "lidarr", "delete", "artist"]);
|
||||
@@ -327,6 +361,32 @@ mod tests {
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_delete_track_file_command() {
|
||||
let expected_track_file_id = 1;
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
mock_network
|
||||
.expect_handle_network_event()
|
||||
.with(eq::<NetworkEvent>(
|
||||
LidarrEvent::DeleteTrackFile(expected_track_file_id).into(),
|
||||
))
|
||||
.times(1)
|
||||
.returning(|_| {
|
||||
Ok(Serdeable::Lidarr(LidarrSerdeable::Value(
|
||||
json!({"testResponse": "response"}),
|
||||
)))
|
||||
});
|
||||
let app_arc = Arc::new(Mutex::new(App::test_default()));
|
||||
let delete_track_file_command = LidarrDeleteCommand::TrackFile { track_file_id: 1 };
|
||||
|
||||
let result =
|
||||
LidarrDeleteCommandHandler::with(&app_arc, delete_track_file_command, &mut mock_network)
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_delete_artist_command() {
|
||||
let expected_delete_artist_params = DeleteParams {
|
||||
|
||||
@@ -27,6 +27,23 @@ pub enum LidarrListCommand {
|
||||
)]
|
||||
artist_id: i64,
|
||||
},
|
||||
#[command(
|
||||
about = "Fetch all history events for the given album corresponding to the artist with the given ID."
|
||||
)]
|
||||
AlbumHistory {
|
||||
#[arg(
|
||||
long,
|
||||
help = "The Lidarr artist ID of the artist whose history you wish to fetch and list",
|
||||
required = true
|
||||
)]
|
||||
artist_id: i64,
|
||||
#[arg(
|
||||
long,
|
||||
help = "The Lidarr album ID to fetch history events for",
|
||||
required = true
|
||||
)]
|
||||
album_id: i64,
|
||||
},
|
||||
#[command(about = "Fetch all history events for the artist with the given ID")]
|
||||
ArtistHistory {
|
||||
#[arg(
|
||||
@@ -72,6 +89,32 @@ pub enum LidarrListCommand {
|
||||
Tags,
|
||||
#[command(about = "List all Lidarr tasks")]
|
||||
Tasks,
|
||||
#[command(
|
||||
about = "List the tracks for the album that corresponds to the artist with the given ID"
|
||||
)]
|
||||
Tracks {
|
||||
#[arg(
|
||||
long,
|
||||
help = "The Lidarr artist ID of the artist whose tracks you wish to fetch",
|
||||
required = true
|
||||
)]
|
||||
artist_id: i64,
|
||||
#[arg(
|
||||
long,
|
||||
help = "The Lidarr album ID whose tracks you wish to fetch",
|
||||
required = true
|
||||
)]
|
||||
album_id: i64,
|
||||
},
|
||||
#[command(about = "List the track files for the album with the given ID")]
|
||||
TrackFiles {
|
||||
#[arg(
|
||||
long,
|
||||
help = "The Lidarr ID of the album whose track files you wish to fetch",
|
||||
required = true
|
||||
)]
|
||||
album_id: i64,
|
||||
},
|
||||
#[command(about = "List all Lidarr updates")]
|
||||
Updates,
|
||||
}
|
||||
@@ -110,6 +153,16 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, LidarrListCommand> for LidarrListCommandH
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
LidarrListCommand::AlbumHistory {
|
||||
artist_id,
|
||||
album_id,
|
||||
} => {
|
||||
let resp = self
|
||||
.network
|
||||
.handle_network_event(LidarrEvent::GetAlbumHistory(artist_id, album_id).into())
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
LidarrListCommand::ArtistHistory { artist_id } => {
|
||||
let resp = self
|
||||
.network
|
||||
@@ -204,6 +257,23 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, LidarrListCommand> for LidarrListCommandH
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
LidarrListCommand::Tracks {
|
||||
artist_id,
|
||||
album_id,
|
||||
} => {
|
||||
let resp = self
|
||||
.network
|
||||
.handle_network_event(LidarrEvent::GetTracks(artist_id, album_id).into())
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
LidarrListCommand::TrackFiles { album_id } => {
|
||||
let resp = self
|
||||
.network
|
||||
.handle_network_event(LidarrEvent::GetTrackFiles(album_id).into())
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
LidarrListCommand::Updates => {
|
||||
let resp = self
|
||||
.network
|
||||
|
||||
@@ -69,6 +69,58 @@ mod tests {
|
||||
assert_eq!(album_command, expected_args);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_album_history_requires_artist_id() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"lidarr",
|
||||
"list",
|
||||
"album-history",
|
||||
"--album-id",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_album_history_requires_album_id() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"lidarr",
|
||||
"list",
|
||||
"album-history",
|
||||
"--artist-id",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_album_history_requirements_satisfied() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"lidarr",
|
||||
"list",
|
||||
"album-history",
|
||||
"--artist-id",
|
||||
"1",
|
||||
"--album-id",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_artist_history_requires_artist_id() {
|
||||
let result =
|
||||
@@ -172,6 +224,101 @@ mod tests {
|
||||
};
|
||||
assert_eq!(logs_command, expected_args);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_tracks_requires_artist_id() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"lidarr",
|
||||
"list",
|
||||
"tracks",
|
||||
"--album-id",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_tracks_requires_album_id() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"lidarr",
|
||||
"list",
|
||||
"tracks",
|
||||
"--artist-id",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_tracks_success() {
|
||||
let expected_args = LidarrListCommand::Tracks {
|
||||
artist_id: 1,
|
||||
album_id: 1,
|
||||
};
|
||||
let result = Cli::try_parse_from([
|
||||
"managarr",
|
||||
"lidarr",
|
||||
"list",
|
||||
"tracks",
|
||||
"--artist-id",
|
||||
"1",
|
||||
"--album-id",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert_ok!(&result);
|
||||
|
||||
let Some(Command::Lidarr(LidarrCommand::List(tracks_command))) = result.unwrap().command
|
||||
else {
|
||||
panic!("Unexpected command type");
|
||||
};
|
||||
assert_eq!(tracks_command, expected_args);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_track_files_requires_album_id() {
|
||||
let result =
|
||||
Cli::command().try_get_matches_from(["managarr", "lidarr", "list", "track-files"]);
|
||||
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_list_track_files_success() {
|
||||
let expected_args = LidarrListCommand::TrackFiles { album_id: 1 };
|
||||
let result = Cli::try_parse_from([
|
||||
"managarr",
|
||||
"lidarr",
|
||||
"list",
|
||||
"track-files",
|
||||
"--album-id",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert_ok!(&result);
|
||||
|
||||
let Some(Command::Lidarr(LidarrCommand::List(track_files_command))) = result.unwrap().command
|
||||
else {
|
||||
panic!("Unexpected command type");
|
||||
};
|
||||
assert_eq!(track_files_command, expected_args);
|
||||
}
|
||||
}
|
||||
|
||||
mod handler {
|
||||
@@ -248,6 +395,36 @@ mod tests {
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_list_album_history_command() {
|
||||
let expected_artist_id = 1;
|
||||
let expected_album_id = 1;
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
mock_network
|
||||
.expect_handle_network_event()
|
||||
.with(eq::<NetworkEvent>(
|
||||
LidarrEvent::GetAlbumHistory(expected_artist_id, expected_album_id).into(),
|
||||
))
|
||||
.times(1)
|
||||
.returning(|_| {
|
||||
Ok(Serdeable::Lidarr(LidarrSerdeable::Value(
|
||||
json!({"testResponse": "response"}),
|
||||
)))
|
||||
});
|
||||
let app_arc = Arc::new(Mutex::new(App::test_default()));
|
||||
let list_album_history_command = LidarrListCommand::AlbumHistory {
|
||||
artist_id: 1,
|
||||
album_id: 1,
|
||||
};
|
||||
|
||||
let result =
|
||||
LidarrListCommandHandler::with(&app_arc, list_album_history_command, &mut mock_network)
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_list_artist_history_command() {
|
||||
let expected_artist_id = 1;
|
||||
@@ -353,5 +530,60 @@ mod tests {
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_list_tracks_command() {
|
||||
let expected_artist_id = 1;
|
||||
let expected_album_id = 1;
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
mock_network
|
||||
.expect_handle_network_event()
|
||||
.with(eq::<NetworkEvent>(
|
||||
LidarrEvent::GetTracks(expected_artist_id, expected_album_id).into(),
|
||||
))
|
||||
.times(1)
|
||||
.returning(|_| {
|
||||
Ok(Serdeable::Lidarr(LidarrSerdeable::Value(
|
||||
json!({"testResponse": "response"}),
|
||||
)))
|
||||
});
|
||||
let app_arc = Arc::new(Mutex::new(App::test_default()));
|
||||
let list_tracks_command = LidarrListCommand::Tracks {
|
||||
artist_id: 1,
|
||||
album_id: 1,
|
||||
};
|
||||
|
||||
let result = LidarrListCommandHandler::with(&app_arc, list_tracks_command, &mut mock_network)
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_list_track_files_command() {
|
||||
let expected_album_id = 1;
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
mock_network
|
||||
.expect_handle_network_event()
|
||||
.with(eq::<NetworkEvent>(
|
||||
LidarrEvent::GetTrackFiles(expected_album_id).into(),
|
||||
))
|
||||
.times(1)
|
||||
.returning(|_| {
|
||||
Ok(Serdeable::Lidarr(LidarrSerdeable::Value(
|
||||
json!({"testResponse": "response"}),
|
||||
)))
|
||||
});
|
||||
let app_arc = Arc::new(Mutex::new(App::test_default()));
|
||||
let list_track_files_command = LidarrListCommand::TrackFiles { album_id: 1 };
|
||||
|
||||
let result =
|
||||
LidarrListCommandHandler::with(&app_arc, list_track_files_command, &mut mock_network)
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,19 @@ mod manual_search_command_handler_tests;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
|
||||
pub enum LidarrManualSearchCommand {
|
||||
#[command(
|
||||
about = "Trigger a manual search of releases for the given album corresponding to the artist with the given ID"
|
||||
)]
|
||||
Album {
|
||||
#[arg(
|
||||
long,
|
||||
help = "The Lidarr ID of the artist whose releases you wish to fetch and list",
|
||||
required = true
|
||||
)]
|
||||
artist_id: i64,
|
||||
#[arg(long, help = "The Lidarr album ID to search for", required = true)]
|
||||
album_id: i64,
|
||||
},
|
||||
#[command(
|
||||
about = "Trigger a manual search of discography releases for the given artist corresponding to the artist with the given ID."
|
||||
)]
|
||||
@@ -59,6 +72,27 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, LidarrManualSearchCommand>
|
||||
|
||||
async fn handle(self) -> Result<String> {
|
||||
let result = match self.command {
|
||||
LidarrManualSearchCommand::Album {
|
||||
artist_id,
|
||||
album_id,
|
||||
} => {
|
||||
println!("Searching for album releases. This may take a minute...");
|
||||
match self
|
||||
.network
|
||||
.handle_network_event(LidarrEvent::GetAlbumReleases(artist_id, album_id).into())
|
||||
.await
|
||||
{
|
||||
Ok(Serdeable::Lidarr(LidarrSerdeable::Releases(releases_vec))) => {
|
||||
let albums_vec: Vec<LidarrRelease> = releases_vec
|
||||
.into_iter()
|
||||
.filter(|release| !release.discography)
|
||||
.collect();
|
||||
serde_json::to_string_pretty(&albums_vec)?
|
||||
}
|
||||
Err(e) => return Err(e),
|
||||
_ => serde_json::to_string_pretty(&json!({"message": "Failed to parse response"}))?,
|
||||
}
|
||||
}
|
||||
LidarrManualSearchCommand::Discography { artist_id } => {
|
||||
println!("Searching for artist discography releases. This may take a minute...");
|
||||
match self
|
||||
|
||||
@@ -23,6 +23,58 @@ mod tests {
|
||||
use clap::error::ErrorKind;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test_manual_album_search_requires_artist_id() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"lidarr",
|
||||
"manual-search",
|
||||
"album",
|
||||
"--album-id",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_manual_album_search_requires_album_id() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"lidarr",
|
||||
"manual-search",
|
||||
"album",
|
||||
"--artist-id",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_manual_album_search_requirements_satisfied() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"lidarr",
|
||||
"manual-search",
|
||||
"album",
|
||||
"--artist-id",
|
||||
"1",
|
||||
"--album-id",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_manual_discography_search_requires_artist_id() {
|
||||
let result =
|
||||
@@ -65,6 +117,39 @@ mod tests {
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_manual_album_search_command() {
|
||||
let expected_artist_id = 1;
|
||||
let expected_album_id = 1;
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
mock_network
|
||||
.expect_handle_network_event()
|
||||
.with(eq::<NetworkEvent>(
|
||||
LidarrEvent::GetAlbumReleases(expected_artist_id, expected_album_id).into(),
|
||||
))
|
||||
.times(1)
|
||||
.returning(|_| {
|
||||
Ok(Serdeable::Lidarr(LidarrSerdeable::Value(
|
||||
json!({"testResponse": "response"}),
|
||||
)))
|
||||
});
|
||||
let app_arc = Arc::new(Mutex::new(App::test_default()));
|
||||
let manual_album_search_command = LidarrManualSearchCommand::Album {
|
||||
artist_id: 1,
|
||||
album_id: 1,
|
||||
};
|
||||
|
||||
let result = LidarrManualSearchCommandHandler::with(
|
||||
&app_arc,
|
||||
manual_album_search_command,
|
||||
&mut mock_network,
|
||||
)
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_manual_discography_search_command() {
|
||||
let expected_artist_id = 1;
|
||||
|
||||
@@ -18,6 +18,15 @@ mod trigger_automatic_search_command_handler_tests;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Subcommand)]
|
||||
pub enum LidarrTriggerAutomaticSearchCommand {
|
||||
#[command(about = "Trigger an automatic search for the album with the specified ID")]
|
||||
Album {
|
||||
#[arg(
|
||||
long,
|
||||
help = "The Lidarr ID of the album you want to trigger an automatic search for",
|
||||
required = true
|
||||
)]
|
||||
album_id: i64,
|
||||
},
|
||||
#[command(about = "Trigger an automatic search for the artist with the specified ID")]
|
||||
Artist {
|
||||
#[arg(
|
||||
@@ -58,6 +67,13 @@ impl<'a, 'b> CliCommandHandler<'a, 'b, LidarrTriggerAutomaticSearchCommand>
|
||||
|
||||
async fn handle(self) -> Result<String> {
|
||||
let result = match self.command {
|
||||
LidarrTriggerAutomaticSearchCommand::Album { album_id } => {
|
||||
let resp = self
|
||||
.network
|
||||
.handle_network_event(LidarrEvent::TriggerAutomaticAlbumSearch(album_id).into())
|
||||
.await?;
|
||||
serde_json::to_string_pretty(&resp)?
|
||||
}
|
||||
LidarrTriggerAutomaticSearchCommand::Artist { artist_id } => {
|
||||
let resp = self
|
||||
.network
|
||||
|
||||
@@ -28,6 +28,36 @@ mod tests {
|
||||
use clap::error::ErrorKind;
|
||||
use pretty_assertions::assert_eq;
|
||||
|
||||
#[test]
|
||||
fn test_trigger_automatic_album_search_requires_album_id() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"lidarr",
|
||||
"trigger-automatic-search",
|
||||
"album",
|
||||
]);
|
||||
|
||||
assert_err!(&result);
|
||||
assert_eq!(
|
||||
result.unwrap_err().kind(),
|
||||
ErrorKind::MissingRequiredArgument
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trigger_automatic_album_search_with_album_id() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
"managarr",
|
||||
"lidarr",
|
||||
"trigger-automatic-search",
|
||||
"album",
|
||||
"--album-id",
|
||||
"1",
|
||||
]);
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_trigger_automatic_artist_search_requires_artist_id() {
|
||||
let result = Cli::command().try_get_matches_from([
|
||||
@@ -75,6 +105,35 @@ mod tests {
|
||||
network::{MockNetworkTrait, NetworkEvent, lidarr_network::LidarrEvent},
|
||||
};
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_trigger_automatic_album_search_command() {
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
mock_network
|
||||
.expect_handle_network_event()
|
||||
.with(eq::<NetworkEvent>(
|
||||
LidarrEvent::TriggerAutomaticAlbumSearch(1).into(),
|
||||
))
|
||||
.times(1)
|
||||
.returning(|_| {
|
||||
Ok(Serdeable::Lidarr(LidarrSerdeable::Value(
|
||||
json!({"testResponse": "response"}),
|
||||
)))
|
||||
});
|
||||
let app_arc = Arc::new(Mutex::new(App::test_default()));
|
||||
let trigger_automatic_search_command =
|
||||
LidarrTriggerAutomaticSearchCommand::Album { album_id: 1 };
|
||||
|
||||
let result = LidarrTriggerAutomaticSearchCommandHandler::with(
|
||||
&app_arc,
|
||||
trigger_automatic_search_command,
|
||||
&mut mock_network,
|
||||
)
|
||||
.handle()
|
||||
.await;
|
||||
|
||||
assert_ok!(&result);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_handle_trigger_automatic_artist_search_command() {
|
||||
let mut mock_network = MockNetworkTrait::new();
|
||||
|
||||
Reference in New Issue
Block a user